delivervector.java

来自「电信小灵通短信网关通讯协议SMGP的JAVA语言API开发包源代码」· Java 代码 · 共 64 行

JAVA
64
字号
/********************************************************************************
 *
 * 为提高速度和内存利用效率,自建deliverStruct的Vector结构
 *
 */

package com.ut.smgp.api.structure;

public class deliverVector {

  private deliverStruct[] data;
  private int count;

  public deliverVector() {
          this(10); // default size is 10
  }
  public deliverVector(int initialSize)
  {
    data = new deliverStruct[initialSize];
  }


  public void add(deliverStruct str)
  {
    // ignore null strings
   if(str == null) { return; }
   ensureCapacity(count + 1);
   data[count++] = str;
  }

  private void ensureCapacity(int minCapacity)
{

      int oldCapacity = data.length;
      if (minCapacity > oldCapacity) {
        deliverStruct oldData[] = data;
        int newCapacity = oldCapacity * 30;
        //if(oldCapacity>300000) oldCapacity+=100000;
        data = new deliverStruct[newCapacity];
        System.arraycopy(oldData, 0, data, 0, count);
      }


}

    public void clear()
   {
        data=new deliverStruct[10];
        count=0;
   }

   public int size()
   {
        return count;
   }

   public deliverStruct get(int i)
   {
        return data[i];
   }


}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?