add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / facet / src / java / org / apache / lucene / facet / taxonomy / writercache / cl2o / LabelToOrdinal.java
1 package org.apache.lucene.facet.taxonomy.writercache.cl2o;
2
3 import org.apache.lucene.facet.taxonomy.CategoryPath;
4
5 /**
6  * Licensed to the Apache Software Foundation (ASF) under one or more
7  * contributor license agreements.  See the NOTICE file distributed with
8  * this work for additional information regarding copyright ownership.
9  * The ASF licenses this file to You under the Apache License, Version 2.0
10  * (the "License"); you may not use this file except in compliance with
11  * the License.  You may obtain a copy of the License at
12  *
13  *     http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21
22 /**
23  * Abstract class for storing Label->Ordinal mappings in a taxonomy. 
24  * 
25  * @lucene.experimental
26  */
27 public abstract class LabelToOrdinal {
28
29   protected int counter;
30   public static final int InvalidOrdinal = -2;
31
32   /**
33    * return the maximal Ordinal assigned so far
34    */
35   public int getMaxOrdinal() {
36     return this.counter;
37   }
38
39   /**
40    * Returns the next unassigned ordinal. The default behavior of this method
41    * is to simply increment a counter.
42    */
43   public int getNextOrdinal() {
44     return this.counter++;
45   }
46
47   /**
48    * Adds a new label if its not yet in the table.
49    * Throws an {@link IllegalArgumentException} if the same label with
50    * a different ordinal was previoulsy added to this table.
51    */
52   public abstract void addLabel(CategoryPath label, int ordinal);
53
54   /**
55    * Adds a new label if its not yet in the table.
56    * Throws an {@link IllegalArgumentException} if the same label with
57    * a different ordinal was previoulsy added to this table.
58    */
59   public abstract void addLabel(CategoryPath label, int prefixLen, int ordinal);
60
61   /**
62    * @return the ordinal assigned to the given label, 
63    * or {@link #InvalidOrdinal} if the label cannot be found in this table.
64    */
65   public abstract int getOrdinal(CategoryPath label);
66
67   /**
68    * @return the ordinal assigned to the given label, 
69    * or {@link #InvalidOrdinal} if the label cannot be found in this table.
70    */
71   public abstract int getOrdinal(CategoryPath label, int prefixLen);
72
73 }