1 package org.apache.lucene.facet.taxonomy.writercache.cl2o;
3 import org.apache.lucene.facet.taxonomy.CategoryPath;
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 * Abstract class for storing Label->Ordinal mappings in a taxonomy.
25 * @lucene.experimental
27 public abstract class LabelToOrdinal {
29 protected int counter;
30 public static final int InvalidOrdinal = -2;
33 * return the maximal Ordinal assigned so far
35 public int getMaxOrdinal() {
40 * Returns the next unassigned ordinal. The default behavior of this method
41 * is to simply increment a counter.
43 public int getNextOrdinal() {
44 return this.counter++;
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.
52 public abstract void addLabel(CategoryPath label, int ordinal);
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.
59 public abstract void addLabel(CategoryPath label, int prefixLen, int ordinal);
62 * @return the ordinal assigned to the given label,
63 * or {@link #InvalidOrdinal} if the label cannot be found in this table.
65 public abstract int getOrdinal(CategoryPath label);
68 * @return the ordinal assigned to the given label,
69 * or {@link #InvalidOrdinal} if the label cannot be found in this table.
71 public abstract int getOrdinal(CategoryPath label, int prefixLen);