Beispiel #1
0
 private final void a(Buffer buffer, int i, int i_3_) {
   a();
   d = i_3_ + i;
   c = buffer;
   b = i;
   if (d > buffer.getSize()) throw new RuntimeException();
 }
Beispiel #2
0
 public Stream(Buffer buffer) {
   this(buffer, 0, buffer.getSize());
 }
Beispiel #3
0
 public Stream(Buffer buffer, int i, int i_7_) {
   this((buffer.getSize() ^ 0xffffffff) <= -4097 ? 4096 : buffer.getSize());
   a(buffer, i, i_7_);
 }
Beispiel #4
0
 public final void a(Buffer buffer) {
   a(buffer, 0, buffer.getSize());
 }
Beispiel #5
0
  public void testLegacy() {
    // 1. Tests of old methods.
    Buffer buf = new Buffer(4);
    Iterator iter = null;

    assertEquals(4, buf.getCapacity());
    assertEquals(0, buf.getSize());
    iter = buf.iterator();
    assertTrue(!iter.hasNext());
    try {
      iter.next();
      assertTrue(false);
    } catch (NoSuchElementException e) {
      assertTrue(true);
    }

    buf.add("test");
    assertEquals(1, buf.getSize());
    iter = buf.iterator();
    assertTrue(iter.hasNext());
    assertEquals("test", iter.next());
    assertTrue(!iter.hasNext());
    try {
      iter.next();
      assertTrue(false);
    } catch (NoSuchElementException e) {
    }

    buf.add("test2");
    assertEquals(2, buf.getSize());
    buf.add("test3");
    assertEquals(3, buf.getSize());
    iter = buf.iterator();
    assertTrue(iter.hasNext());
    assertEquals("test3", iter.next());
    assertTrue(iter.hasNext());
    assertEquals("test2", iter.next());
    assertTrue(iter.hasNext());
    assertEquals("test", iter.next());
    assertTrue(!iter.hasNext());

    buf.add("test4");
    assertEquals(4, buf.getSize());
    buf.add("test5");
    assertEquals(4, buf.getSize());
    iter = buf.iterator();
    assertTrue(iter.hasNext());
    assertEquals("test5", iter.next());
    assertTrue(iter.hasNext());
    assertEquals("test4", iter.next());
    assertTrue(iter.hasNext());
    assertEquals("test3", iter.next());
    assertTrue(iter.hasNext());
    assertEquals("test2", iter.next());
    assertTrue(!iter.hasNext());

    buf.add("test6");
    assertEquals(4, buf.getSize());

    // 2.  Tests of new methods.  These are definitely not sufficient.
    buf = new Buffer(4);
    assertEquals(0, buf.getSize());
    assertNull(buf.addLast("a"));
    assertEquals(1, buf.getSize());
    assertNull(buf.addLast("b"));
    assertEquals(2, buf.getSize());
    assertNull(buf.addLast("c"));
    assertEquals(3, buf.getSize());
    assertNull(buf.addLast("d"));
    assertEquals(4, buf.getSize());
    assertEquals("a", buf.first());
    assertEquals("a", buf.removeFirst());
    assertEquals(3, buf.getSize());
    assertEquals("b", buf.first());
    assertEquals("b", buf.removeFirst());
    assertEquals(2, buf.getSize());
    assertNull(buf.addFirst("b"));
    assertEquals(3, buf.getSize());
    assertNull(buf.addFirst("a"));
    assertEquals(4, buf.getSize());
    // buf=[a b c d]

    assertEquals("a", buf.addLast("e"));
    // buf=[b c d e]
    assertEquals("e", buf.last());
    assertEquals("b", buf.first());
    assertEquals("e", buf.removeLast());
    assertEquals("d", buf.removeLast());

    buf = new Buffer(4);
    iter = buf.iterator();
    buf.addFirst("a");
    try {
      iter.hasNext();
      assertTrue(false);
    } catch (ConcurrentModificationException e) {
      assertTrue(true);
    }

    buf = new Buffer(4);
    buf.addFirst("a");
    buf.addLast("b");
    buf.clear();
    assertEquals(0, buf.getSize());
    iter = buf.iterator();
    assertTrue(!iter.hasNext());

    // 3. Tests of get and set.
    buf = new Buffer(3);
    try {
      buf.get(0);
      assertTrue(false);
    } catch (IndexOutOfBoundsException e) {
    }
    try {
      buf.get(-1);
      assertTrue(false);
    } catch (IndexOutOfBoundsException e) {
    }

    buf.addLast("a");
    buf.addLast("b");
    buf.addLast("c");
    buf.addLast("d"); // clobbers a!
    assertEquals("b", buf.get(0));
    assertEquals("c", buf.get(1));
    assertEquals("d", buf.get(2));
    buf.set(2, "bb");
    assertEquals("bb", buf.get(2));

    // 4. Tests of remove and removeAll methods.
    buf = new Buffer(4);
    buf.addLast("a");
    buf.addLast("b");
    buf.addLast("c");
    buf.addLast("d");
    try {
      buf.remove(-1);
      assertTrue(false);
    } catch (IndexOutOfBoundsException e) {
    }
    assertEquals("a", (buf.remove(0)));
    assertEquals(3, buf.size());
    assertEquals("b", buf.get(0));
    assertEquals("c", buf.get(1));
    assertEquals("d", buf.get(2));

    buf = new Buffer(4);
    buf.addLast("x");
    buf.addLast("y");
    buf.addLast("a");
    buf.addLast("b");
    buf.addLast("c");
    buf.addLast("d");
    try {
      buf.remove(5);
      assertTrue(false);
    } catch (IndexOutOfBoundsException e) {
    }
    assertEquals("a", (buf.remove(0)));
    assertEquals(3, buf.size());
    assertEquals("b", buf.get(0));
    assertEquals("c", buf.get(1));
    assertEquals("d", buf.get(2));

    buf = new Buffer(4);
    buf.addLast("a");
    buf.addLast("b");
    buf.addLast("c");
    buf.addLast("d");
    try {
      buf.remove(5);
      assertTrue(false);
    } catch (IndexOutOfBoundsException e) {
    }
    assertEquals("d", buf.remove(3));
    assertEquals(3, buf.size());
    assertEquals("a", buf.get(0));
    assertEquals("b", buf.get(1));
    assertEquals("c", buf.get(2));

    buf = new Buffer(4);
    buf.addLast("a");
    buf.addLast("b");
    buf.addLast("c");
    buf.addLast("d");
    try {
      buf.remove(5);
      assertTrue(false);
    } catch (IndexOutOfBoundsException e) {
    }
    assertEquals("b", buf.remove(1));
    assertEquals(3, buf.size());
    assertEquals("a", buf.get(0));
    assertEquals("c", buf.get(1));
    assertEquals("d", buf.get(2));

    buf = new Buffer(4);
    buf.addLast("b");
    buf.addLast("b");
    buf.addLast("c");
    buf.addLast("d");
    assertTrue(buf.remove("d"));
    assertTrue(buf.remove("b"));
    assertEquals(2, buf.size());
    assertEquals("b", buf.get(0));
    assertEquals("c", buf.get(1));

    buf = new Buffer(4);
    buf.addLast("b");
    buf.addLast("b");
    buf.addLast("c");
    buf.addLast("b");
    assertTrue(buf.removeAll("b"));
    assertEquals(1, buf.size());
    assertEquals("c", buf.get(0));

    // 5. Test clone() method.
    buf = new Buffer(2);
    buf.addLast("a");
    buf.addLast("b");
    Buffer buf2 = new Buffer(buf);
    assertEquals(buf2.size(), buf.size());
    assertEquals(buf2.getCapacity(), buf.getCapacity());
    assertEquals(buf2.first(), buf.first());
    assertEquals(buf2.last(), buf.last());

    assertNotNull(buf.removeFirst()); // buf2 unmodified
    assertEquals(1, buf.size());
    assertEquals(2, buf2.size());
    assertEquals("b", buf.first());
    assertEquals("a", buf2.first());
    assertEquals("b", buf2.last());
  }
Beispiel #6
0
 /**
  * Returns the bit width of this <code>RestrictedPin</code>. (Defers to the original pin)
  *
  * @return an <code>int</code> value, always greater than 0.
  */
 public int getSize() {
   return original.getSize();
 }