pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / contrib / facet / src / java / org / apache / lucene / facet / enhancements / association / AssociationProperty.java
1 package org.apache.lucene.facet.enhancements.association;
2
3 import org.apache.lucene.facet.index.attributes.CategoryAttribute;
4 import org.apache.lucene.facet.index.attributes.CategoryProperty;
5
6 /**
7  * Licensed to the Apache Software Foundation (ASF) under one or more
8  * contributor license agreements.  See the NOTICE file distributed with
9  * this work for additional information regarding copyright ownership.
10  * The ASF licenses this file to You under the Apache License, Version 2.0
11  * (the "License"); you may not use this file except in compliance with
12  * the License.  You may obtain a copy of the License at
13  *
14  *     http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */
22
23 /**
24  * A {@link CategoryProperty} associating a single integer value to a
25  * {@link CategoryAttribute}. It should be used to describe the association
26  * between the category and the document.
27  * <p>
28  * This class leave to extending classes the definition of
29  * {@link #merge(CategoryProperty)} policy for the integer associations.
30  * <p>
31  * <B>Note:</B> The association value is added both to a special category list,
32  * and to the category tokens.
33  * 
34  * @see AssociationEnhancement
35  * @lucene.experimental
36  */
37 public abstract class AssociationProperty implements CategoryProperty {
38
39   protected long association = Integer.MAX_VALUE + 1;
40
41   /**
42    * Construct an {@link AssociationProperty}.
43    * 
44    * @param value
45    *            The association value.
46    */
47   public AssociationProperty(int value) {
48     this.association = value;
49   }
50
51   /**
52    * Returns the association value.
53    * 
54    * @return The association value.
55    */
56   public int getAssociation() {
57     return (int) association;
58   }
59
60   /**
61    * Returns whether this attribute has been set (not all categories have an
62    * association).
63    */
64   public boolean hasBeenSet() {
65     return this.association <= Integer.MAX_VALUE;
66   }
67
68   @Override
69   public String toString() {
70     return getClass().getSimpleName() + ": " + association;
71   }
72
73 }