SchemaSet和继承的类


public class SchemaSet
{
 // @Field
 private Object elementData[];
 private int elementCount;
 private int capacityIncrement;

 public CErrors mErrors;   // 错误信息

 // @Constructor
 public SchemaSet(int initialCapacity, int capacityIncrement)
 {
  if (initialCapacity < 0)
  {
   // @@错误处理
   CError tError = new CError();
   tError.moduleName = "SchemaSet";
   tError.functionName = "SchemaSet";
   tError.errorMessage = "Illegal Capacity: " + initialCapacity;
   this.mErrors .addOneError(tError);
  }
  this.elementData = new Object[initialCapacity];
  this.capacityIncrement = capacityIncrement;
  this.elementCount = 0;

  mErrors = new CErrors();
 }

 public SchemaSet(int initialCapacity)
 {
  this(initialCapacity,0);
 }

 public SchemaSet()
 {
  this(10);
 }

 // @Method
 public boolean add(Schema aSchema)
 {
  if (aSchema == null) return false;
  ensureCapacityHelper(elementCount + 1);
  elementData[elementCount] = aSchema;
  elementCount++;
  return true;
 }

 public boolean add(SchemaSet aSet)
 {
  if (aSet == null) return false;
  int n = aSet.size();
  ensureCapacityHelper(elementCount + n);
  for (int i = 0; i < n; i++)
  {
   elementData[elementCount + i] = aSet.getObj(i + 1);
  }
  elementCount += n;
  return true;
 }

 public boolean remove(Schema aSchema)
 {
  if (aSchema == null) return false;
  for (int i = 0; i < elementCount; i++)
  {
   if (aSchema.equals(elementData[i]))
   {
    int j = elementCount - i - 1;
    if (j > 0)
    {
     System.arraycopy(elementData, i + 1, elementData, i, j);
    }
    elementCount--;
    elementData[elementCount] = null;
    return true;
   } // end of if
  } // end of for
  return false;
 }

 public boolean removeRange(int begin, int end)
 {
  if (begin <= 0 || end > elementCount || begin > end)
  {
   return false;
  }
  int n = elementCount - end;
  if (n > 0)
  {
   System.arraycopy(elementData, end, elementData, begin - 1, elementCount - end);
  }
  int m = end - begin + 1;
  for (int i = 1; i <= m; i++)
  {
   int j = elementCount - i;
   elementData[j] = null;
  }
  elementCount -= m;
  return true;
 }

 public void clear()
 {
  for (int i = 0; i < elementCount; i++)
  {
   elementData[i] = null;
  }
  elementCount = 0;
 }

 public Object getObj(int index)
 {
  if (index > elementCount)
  {
   // @@错误处理
   CError tError = new CError();
   tError.moduleName = "SchemaSet";
   tError.functionName = "get";
   tError.errorMessage = "Index out of bounds!";
   this.mErrors .addOneError(tError);
  }
  return elementData[index - 1];
 }

 public boolean set(int index, Schema aSchema)
 {
  if (index > elementCount)
  {
   // @@错误处理
   CError tError = new CError();
   tError.moduleName = "SchemaSet";
   tError.functionName = "set";
   tError.errorMessage = "Index out of bounds!";
   this.mErrors .addOneError(tError);

   return false;
  }
  elementData[index - 1] = aSchema;
  return true;
 }

 public boolean set(SchemaSet aSet)
 {
  this.clear();
   return this.add(aSet);
 }

 public int size()
 {
  return elementCount;
 }

 private void ensureCapacityHelper(int minCapacity)
 {
  int oldCapacity = elementData.length;
  if (minCapacity > oldCapacity)
  {
   Object oldData[] = elementData;
   int newCapacity = (capacityIncrement > 0) ? (oldCapacity + capacityIncrement) : (oldCapacity * 2);
   if (newCapacity < minCapacity)
   {
    newCapacity = minCapacity;
   }
   elementData = new Object[newCapacity];
   System.arraycopy(oldData, 0, elementData, 0, elementCount);
  }
 }
}

/*
 * 
 */
package com.vschema;

import com.schema.LAAscriptionSchema;
import com.utility.SchemaSet;
import com.utility.SysConst;

public class LAAscriptionSet extends SchemaSet
{
    // @Method
    public boolean add(LAAscriptionSchema aSchema)
    {
        return super.add(aSchema);
    }

    public boolean add(LAAscriptionSet aSet)
    {
        return super.add(aSet);
    }

    public boolean remove(LAAscriptionSchema aSchema)
    {
        return super.remove(aSchema);
    }

    public LAAscriptionSchema get(int index)
    {
        LAAscriptionSchema tSchema = (LAAscriptionSchema)super.getObj(index);
        return tSchema;
    }

    public boolean set(int index, LAAscriptionSchema aSchema)
    {
        return super.set(index, aSchema);
    }

    public boolean set(LAAscriptionSet aSet)
    {
        return super.set(aSet);
    }

    /**
     * 数据打包,按 XML 格式打包,顺序参见<A href ={@docRoot}/dataStructure/tb.html#PrpLAAscription描述/A>表字段
     * @param: 无
     * @return: 返回打包后字符串
     **/
    public String encode()
    {
        String strReturn = "";
        int n = this.size();
        for (int i = 1; i <= n; i++)
        {
            LAAscriptionSchema aSchema = (LAAscriptionSchema)this.get(i);
            strReturn += aSchema.encode();
            if (i != n)
            {
                strReturn += SysConst.RECORDSPLITER;
            }
        }

        return strReturn;
    }

    /**
     * 数据解包
     * @param: 打包后字符串
     * @return: boolean
     **/
    public boolean decode(String str)
    {
        int nBeginPos = 0;
        int nEndPos = str.indexOf('^');
        this.clear();

        while (nEndPos != -1)
        {
            LAAscriptionSchema aSchema = new LAAscriptionSchema();
            if (aSchema.decode(str.substring(nBeginPos, nEndPos)) == false)
            {
                // @@错误处理
                this.mErrors.copyAllErrors(aSchema.mErrors);
                return false;
            }
            this.add(aSchema);
            nBeginPos = nEndPos + 1;
            nEndPos = str.indexOf('^', nEndPos + 1);
        }
        LAAscriptionSchema tSchema = new LAAscriptionSchema();
        if (tSchema.decode(str.substring(nBeginPos)) == false)
        {
            // @@错误处理
            this.mErrors.copyAllErrors(tSchema.mErrors);
            return false;
        }
        this.add(tSchema);

        return true;
    }

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值