## org.apache.lucene.facet.encoding
Class NOnesIntEncoder

    java.lang.Object
      org.apache.lucene.facet.encoding.IntEncoder
          org.apache.lucene.facet.encoding.ChunksIntEncoder
              org.apache.lucene.facet.encoding.FourFlagsIntEncoder
                  org.apache.lucene.facet.encoding.NOnesIntEncoder

    public class NOnesIntEncoder

extends FourFlagsIntEncoder

A variation of `FourFlagsIntEncoder` which translates the data as follows:

- Values ≥ 2 are trnalsated to `value+1` (2 ⇒ 3, 3 ⇒ 4 and so forth).
- Any `N` occurrences of 1 are encoded as a single 2.
- Otherwise, each 1 is encoded as 1.

Encoding examples:

- N = 4: the data 1,1,1,1,1 is translated to: 2, 1
- N = 3: the data 1,2,3,4,1,1,1,1,5 is translated to 1,3,4,5,2,1,6

NOTE: this encoder does not support values ≤ 0 and `Integer.MAX_VALUE`. 0 is not supported because it's not supported by `FourFlagsIntEncoder` and `Integer.MAX_VALUE` because this encoder translates N to N+1, which will cause an overflow and `Integer.MAX_VALUE` will become a negative number, which is not supported as well.
This does not mean you cannot encode `Integer.MAX_VALUE`. If it is not the first value to encode, and you wrap this encoder with `DGapIntEncoder`, then the value that will be sent to this encoder will be `MAX_VAL - prev`.

WARNING: This API is experimental and might change in incompatible ways in the next release.

Field Summary

Fields inherited from class org.apache.lucene.facet.encoding.ChunksIntEncoder
`encodeQueue, indicator, ordinal`

Constructor Summary
`NOnesIntEncoder(int n)` Constructs an encoder with a given value of N (N: Number of consecutive '1's to be translated into single target value '2').

Method Summary
`IntDecoder` `createMatchingDecoder()` Returns an `IntDecoder` which can decode the values that were encoded with this encoder.
`void` `encode(IntsRef values, BytesRef buf)` Encodes the values to the given buffer.
`String` `toString()`

Methods inherited from class org.apache.lucene.facet.encoding.ChunksIntEncoder
`encodeChunk`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### NOnesIntEncoder

    public NOnesIntEncoder(int n)

  Constructs an encoder with a given value of N (N: Number of consecutive '1's to be translated into single target value '2').

Method Detail

### encode

    public void encode(IntsRef values,
                       BytesRef buf)

  Description copied from class: `IntEncoder`
  Encodes the values to the given buffer. Note that the buffer's offset and length are set to 0.

  Overrides:
    `encode` in class `FourFlagsIntEncoder`

### createMatchingDecoder

    public IntDecoder createMatchingDecoder()

  Description copied from class: `IntEncoder`
  Returns an `IntDecoder` which can decode the values that were encoded with this encoder.

  Overrides:
    `createMatchingDecoder` in class `FourFlagsIntEncoder`

### toString

    public String toString()

  Overrides:
    `toString` in class `FourFlagsIntEncoder`

Copyright © 2000-2013 Apache Software Foundation. All Rights Reserved.