Example usage for org.apache.lucene.util IntsRef IntsRef

List of usage examples for org.apache.lucene.util IntsRef IntsRef

Introduction

In this page you can find the example usage for org.apache.lucene.util IntsRef IntsRef.

Prototype

public IntsRef(int[] ints, int offset, int length) 

Source Link

Document

This instance will directly reference ints w/o making a copy.

Usage

From source file:com.sindicetech.siren.analysis.filter.TestVIntSirenPayload.java

License:Open Source License

@Test
public void testSimpleVInt() throws Exception {
    IntsRef ints = new IntsRef(new int[] { 12, 43 }, 0, 2);
    int pos = 256;
    BytesRef bytes = codec.encode(ints, pos);
    codec.decode(bytes);//  www.  j a v  a 2s . co m

    IntsRef node = codec.getNode();
    assertEquals(ints.ints[0], node.ints[node.offset]);
    assertEquals(ints.ints[1], node.ints[node.offset + 1]);
    assertEquals(pos, codec.getPosition());

    ints = new IntsRef(new int[] { 3, 2 }, 0, 2);
    pos = 2;
    bytes = codec.encode(ints, pos);
    codec.decode(bytes);

    node = codec.getNode();
    assertEquals(ints.ints[0], node.ints[node.offset]);
    assertEquals(ints.ints[1], node.ints[node.offset + 1]);
    assertEquals(pos, codec.getPosition());

    ints = new IntsRef(new int[] { 0, 1 }, 0, 2);
    pos = 0;
    bytes = codec.encode(ints, pos);
    codec.decode(bytes);

    node = codec.getNode();
    assertEquals(ints.ints[0], node.ints[node.offset]);
    assertEquals(ints.ints[1], node.ints[node.offset + 1]);
    assertEquals(pos, codec.getPosition());
}

From source file:com.sindicetech.siren.analysis.filter.TestVIntSirenPayload.java

License:Open Source License

@Test
public void testRandomVInt2() throws Exception {
    final Random r = LuceneTestCase.random();
    for (int i = 0; i < 10000; i++) {
        final int value1 = r.nextInt(Integer.MAX_VALUE);
        final int value2 = r.nextInt(Integer.MAX_VALUE);

        final IntsRef ints = new IntsRef(new int[] { value1, value2 }, 0, 2);
        final int pos = r.nextInt(Integer.MAX_VALUE);
        final BytesRef bytes = codec.encode(ints, pos);
        codec.decode(bytes);//from  w w w .  j  av  a2s .c o  m

        final IntsRef node = codec.getNode();
        assertEquals(ints.ints[0], node.ints[node.offset]);
        assertEquals(ints.ints[1], node.ints[node.offset + 1]);
        assertEquals(pos, codec.getPosition());
    }
}

From source file:com.sindicetech.siren.analysis.filter.TestVIntSirenPayload.java

License:Open Source License

@Test
public void testRandomVInt3() throws Exception {
    final Random r = LuceneTestCase.random();
    for (int i = 0; i < 10000; i++) {
        final int value1 = r.nextInt(Integer.MAX_VALUE);
        final int value2 = r.nextInt(Integer.MAX_VALUE);
        final int value3 = r.nextInt(Integer.MAX_VALUE);

        final IntsRef ints = new IntsRef(new int[] { value1, value2, value3 }, 0, 3);
        final int pos = r.nextInt(Integer.MAX_VALUE);
        final BytesRef bytes = codec.encode(ints, pos);
        codec.decode(bytes);//www . jav  a 2s . c  om

        final IntsRef node = codec.getNode();
        assertEquals(ints.ints[0], node.ints[node.offset]);
        assertEquals(ints.ints[1], node.ints[node.offset + 1]);
        assertEquals(ints.ints[2], node.ints[node.offset + 2]);
        assertEquals(pos, codec.getPosition());
    }
}

From source file:com.sindicetech.siren.analysis.MockSirenToken.java

License:Open Source License

public static IntsRef node(final int... id) {
    return new IntsRef(id, 0, id.length);
}