add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / facet / src / java / org / apache / lucene / facet / enhancements / association / AssociationFloatProperty.java
1 package org.apache.lucene.facet.enhancements.association;
2
3 import org.apache.lucene.facet.index.attributes.CategoryProperty;
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  * An {@link AssociationProperty} which treats the association as float - the
24  * association bits are actually float bits, and thus merging two associations
25  * is done by float summation.
26  * 
27  * @lucene.experimental
28  */
29 public class AssociationFloatProperty extends AssociationProperty {
30
31   /**
32    * Constructor.
33    * 
34    * @param value
35    *            The association value.
36    */
37   public AssociationFloatProperty(float value) {
38     super(Float.floatToIntBits(value));
39   }
40
41   @Override
42   public boolean equals(Object other) {
43     if (other == this) {
44       return true;
45     }
46     if (!(other instanceof AssociationFloatProperty)) {
47       return false;
48     }
49     AssociationFloatProperty o = (AssociationFloatProperty) other;
50     return o.association == this.association;
51   }
52
53   @Override
54   public int hashCode() {
55     return "AssociationFloatProperty".hashCode() * 31 + (int) association;
56   }
57
58   public void merge(CategoryProperty other) {
59     AssociationFloatProperty o = (AssociationFloatProperty) other;
60     this.association = Float.floatToIntBits(Float
61         .intBitsToFloat((int) this.association)
62         + Float.intBitsToFloat((int) o.association));
63   }
64
65   public float getFloatAssociation() {
66     return Float.intBitsToFloat((int) association);
67   }
68
69   @Override
70   public String toString() {
71     return getClass().getSimpleName() + ": " + Float.intBitsToFloat(getAssociation());
72   }
73
74 }