Example #1
0
    public boolean equals(Object other) {
      if (!super.equals(other)) {
        return false;
      }

      Persistent2 otherPersistent2 = (Persistent2) other;

      if (int2 != otherPersistent2.int2) {
        System.out.println("int2 failed");
        return false;
      }

      if (string2 != otherPersistent2.string2
          && (string2 != null
              && !string2.equals(otherPersistent2.string2)
              && otherPersistent2.string2 != null)) {
        System.out.println("string2 failed");
        return false;
      }

      if (buffer2 != otherPersistent2.buffer2
          && (buffer2 != null
              && !buffer2.equals(otherPersistent2.buffer2)
              && otherPersistent2.buffer2 != null)) {
        System.out.println("buffer2 failed");
        return false;
      }

      return true;
    }
Example #2
0
    public void encode(Encoder encoder) {
      super.encode(encoder);

      encoder.encodeInt(int2);
      encoder.encodeString(string2);
      encoder.encodeInt(buffer2.remaining());
      encoder.encodeKnownLengthBuffer(buffer2);
    }
Example #3
0
  public void testByteBufferCoder() {
    Persistent3 three =
        new Persistent3(
            10,
            (float) 4.444,
            555555555555L,
            true,
            "this is the fourth persistent string",
            new Date(),
            new byte[] {10, 20, 30, 40, 50, 60, 70, 80, 90, 100},
            null);

    Persistent2 two =
        new Persistent2(
            1,
            (float) 2.222,
            333333333333L,
            false,
            "this is the first persistent string",
            new Date(),
            new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
            three,
            4,
            "this is the second persistent string",
            (ByteBuffer) ByteBuffer.allocateDirect(17).putInt(1234).rewind());

    Persistent1 one =
        new Persistent1(
            2,
            (float) 3.333,
            4444444444444L,
            true,
            "this is the third persistent string",
            new Date(),
            new byte[] {10, 9, 8, 7, 6, 5, 4, 3, 2, 1},
            two);

    ByteBuffer buffer = ByteBuffer.allocateDirect(8 * 1024);
    ByteBufferCoder encoder = new ByteBufferCoder(buffer, true);

    encoder.encodeCodable(one);
    buffer.rewind();

    ByteBufferCoder decoder = new ByteBufferCoder(buffer, true, new Delegate());
    Persistent1 anotherOne = (Persistent1) decoder.decodeCodable();

    if (!one.equals(anotherOne)) {
      fail("unarchived object with type checking does not equal archived one");
    }

    buffer.clear();
    encoder = new ByteBufferCoder(buffer, false);

    encoder.encodeCodable(one);
    buffer.rewind();

    decoder = new ByteBufferCoder(buffer, false, new Delegate());
    anotherOne = (Persistent1) decoder.decodeCodable();

    if (!one.equals(anotherOne)) {
      fail("unarchived object without type checking does not equal archived one");
    }
  }