Пример #1
0
  public void setValueAt(long value, int index) {
    synchronized (this) {
      int oldSize = getValuesSize();
      for (int i = oldSize; i < index + 1; i++) {
        addValue(0);
      }

      int[] offset = new int[1];
      for (int i = 0; i < index; i++) {
        DataUtil.readOffset(valuesBuff, offset);
      }

      int startOffset = offset[0];
      DataUtil.readOffset(valuesBuff, offset);
      int endOffset = offset[0];

      checkValueBufferSize(value);
      int newValLength = DataUtil.getValueLength(value);
      int oldValLength = endOffset - startOffset;
      if (newValLength != oldValLength) {
        // need to move old values
        short delta = (short) (newValLength - oldValLength);
        int len = valuesBuffOffset - endOffset;
        System.arraycopy(valuesBuff, endOffset, valuesBuff, endOffset + delta, len);
        valuesBuffOffset = (short) (valuesBuffOffset + delta);
      }
      DataUtil.writeValue(valuesBuff, value, startOffset);
    }
  }
Пример #2
0
  /* (non-Javadoc)
   * @see com.telenav.framework.data.INode#getValueAt(int)
   */
  public long getValueAt(int index) {
    if (index >= nValues) return 0;

    offsetValue[0] = 0;

    // int[] offset = new int[] { 0 };
    for (int i = 0; i < index; i++) {
      DataUtil.readOffset(valuesBuff, offsetValue);
    }
    return DataUtil.readValue(valuesBuff, offsetValue);
  }