예제 #1
0
  public boolean equalsIgnoreCase(Buffer b) {
    if (b == this) {
      return true;
    }

    if (b.length() != length()) {
      return false;
    }
    if ((this._hash != 0) && (b instanceof AbstractBuffer)) {
      AbstractBuffer ab = (AbstractBuffer) b;
      if ((ab._hash != 0) && (this._hash != ab._hash)) {
        return false;
      }
    }

    int get = getIndex();
    int bi = b.putIndex();

    byte[] array = array();
    byte[] barray = b.array();
    int i;
    if ((array != null) && (barray != null)) {
      for (i = putIndex(); i-- > get; ) {
        byte b1 = array[i];
        bi--;
        byte b2 = barray[bi];
        if (b1 != b2) {
          if ((97 <= b1) && (b1 <= 122)) {
            b1 = (byte) (b1 - 97 + 65);
          }
          if ((97 <= b2) && (b2 <= 122)) {
            b2 = (byte) (b2 - 97 + 65);
          }
          if (b1 != b2) {
            return false;
          }
        }
      }
    } else {
      for (i = putIndex(); i-- > get; ) {
        byte b1 = peek(i);
        bi--;
        byte b2 = b.peek(bi);
        if (b1 != b2) {
          if ((97 <= b1) && (b1 <= 122)) {
            b1 = (byte) (b1 - 97 + 65);
          }

          if ((97 <= b2) && (b2 <= 122)) {
            b2 = (byte) (b2 - 97 + 65);
          }

          if (b1 != b2) {
            return false;
          }
        }
      }
    }
    return true;
  }
예제 #2
0
  public int poke(int index, Buffer src) {
    this._hash = 0;

    int length = src.length();
    if (index + length > capacity()) {
      length = capacity() - index;
    }

    byte[] srcArray = src.array();
    byte[] dstArray = array();
    if ((srcArray != null) && (dstArray != null)) {
      System.arraycopy(srcArray, src.getIndex(), dstArray, index, length);
    } else if (srcArray != null) {
      int s = src.getIndex();
      for (int i = 0; i < length; i++) {
        poke(index++, srcArray[s++]);
      }
    } else if (dstArray != null) {
      int s = src.getIndex();
      for (int i = 0; i < length; i++) {
        dstArray[index++] = src.peek(s++);
      }
    } else {
      int s = src.getIndex();
      for (int i = 0; i < length; i++) {
        poke(index++, src.peek(s++));
      }
    }
    return length;
  }
예제 #3
0
  public boolean equals(Object obj) {
    if (obj == this) {
      return true;
    }

    if ((obj == null) || (!(obj instanceof Buffer))) {
      return false;
    }
    Buffer b = (Buffer) obj;

    if ((this instanceof Buffer.CaseInsensitve) || (b instanceof Buffer.CaseInsensitve)) {
      return equalsIgnoreCase(b);
    }

    if (b.length() != length()) {
      return false;
    }

    if ((this._hash != 0) && (obj instanceof AbstractBuffer)) {
      AbstractBuffer ab = (AbstractBuffer) obj;
      if ((ab._hash != 0) && (this._hash != ab._hash)) {
        return false;
      }
    }

    int get = getIndex();
    int bi = b.putIndex();
    for (int i = putIndex(); i-- > get; ) {
      byte b1 = peek(i);
      bi--;
      byte b2 = b.peek(bi);
      if (b1 != b2) {
        return false;
      }
    }
    return true;
  }