X-Git-Url: https://git.mdrn.pl/pylucene.git/blobdiff_plain/a2e61f0c04805cfcb8706176758d1283c7e3a55c..aaeed5504b982cf3545252ab528713250aa33eed:/lucene-java-3.4.0/lucene/contrib/facet/src/java/org/apache/lucene/util/encoding/NOnesIntEncoder.java diff --git a/lucene-java-3.4.0/lucene/contrib/facet/src/java/org/apache/lucene/util/encoding/NOnesIntEncoder.java b/lucene-java-3.4.0/lucene/contrib/facet/src/java/org/apache/lucene/util/encoding/NOnesIntEncoder.java deleted file mode 100644 index f8e5015..0000000 --- a/lucene-java-3.4.0/lucene/contrib/facet/src/java/org/apache/lucene/util/encoding/NOnesIntEncoder.java +++ /dev/null @@ -1,115 +0,0 @@ -package org.apache.lucene.util.encoding; - -import java.io.IOException; -import java.io.OutputStream; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * A variation of {@link FourFlagsIntEncoder} which translates the data as - * follows: - *
value+1
(2 ⇒ 3, 3
- * ⇒ 4 and so forth).
- * N
occurrences of 1 are encoded as a single 2.
- * - * Encoding examples: - *
MAX_VAL - prev
.
- *
- * @lucene.experimental
- */
-public class NOnesIntEncoder extends FourFlagsIntEncoder {
-
- /** Number of consecutive '1's to be translated into single target value '2'. */
- private int n;
-
- /** Counts the number of consecutive ones seen. */
- private int onesCounter = 0;
-
- /**
- * Constructs an encoder with a given value of N (N: Number of consecutive
- * '1's to be translated into single target value '2').
- */
- public NOnesIntEncoder(int n) {
- this.n = n;
- }
-
- @Override
- public void close() throws IOException {
- // We might have ones in our buffer, encode them as neccesary.
- while (onesCounter-- > 0) {
- super.encode(1);
- }
-
- super.close();
- }
-
- @Override
- public void encode(int value) throws IOException {
- if (value == 1) {
- // Increment the number of consecutive ones seen so far
- if (++onesCounter == n) {
- super.encode(2);
- onesCounter = 0;
- }
- return;
- }
-
- // If it's not one - there might have been ones we had to encode prior to
- // this value
- while (onesCounter > 0) {
- --onesCounter;
- super.encode(1);
- }
-
- // encode value + 1 --> the translation.
- super.encode(value + 1);
- }
-
- @Override
- public IntDecoder createMatchingDecoder() {
- return new NOnesIntDecoder(n);
- }
-
- @Override
- public void reInit(OutputStream out) {
- super.reInit(out);
- onesCounter = 0;
- }
-
- @Override
- public String toString() {
- return "NOnes (" + n + ") (" + super.toString() + ")";
- }
-
-}