示例#1
0
  public boolean equals(MessageBytes mb) {
    switch (type) {
      case T_STR:
        return mb.equals(strValue);
    }

    if (mb.type != T_CHARS && mb.type != T_BYTES) {
      // it's a string or int/date string value
      return equals(mb.toString());
    }

    // mb is either CHARS or BYTES.
    // this is either CHARS or BYTES
    // Deal with the 4 cases ( in fact 3, one is simetric)

    if (mb.type == T_CHARS && type == T_CHARS) {
      return charC.equals(mb.charC);
    }
    if (mb.type == T_BYTES && type == T_BYTES) {
      return byteC.equals(mb.byteC);
    }
    if (mb.type == T_CHARS && type == T_BYTES) {
      return byteC.equals(mb.charC);
    }
    if (mb.type == T_BYTES && type == T_CHARS) {
      return mb.byteC.equals(charC);
    }
    // can't happen
    return true;
  }
示例#2
0
 /** Copy the src into this MessageBytes, allocating more space if needed */
 public void duplicate(MessageBytes src) throws IOException {
   switch (src.getType()) {
     case MessageBytes.T_BYTES:
       type = T_BYTES;
       ByteChunk bc = src.getByteChunk();
       byteC.allocate(2 * bc.getLength(), -1);
       byteC.append(bc);
       break;
     case MessageBytes.T_CHARS:
       type = T_CHARS;
       CharChunk cc = src.getCharChunk();
       charC.allocate(2 * cc.getLength(), -1);
       charC.append(cc);
       break;
     case MessageBytes.T_STR:
       type = T_STR;
       String sc = src.getString();
       this.setString(sc);
       break;
   }
 }