001 /*
002 * Java Genetic Algorithm Library (jenetics-1.6.0).
003 * Copyright (c) 2007-2014 Franz Wilhelmstötter
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 *
017 * Author:
018 * Franz Wilhelmstötter (franz.wilhelmstoetter@gmx.at)
019 */
020 package org.jenetics.util;
021
022 /**
023 * Interface for building hash codes. The HashCodeBuilder is created via a
024 * factory method in the {@link object} class.
025 * <p/>
026 * Example for calculating the hash code for a given class:
027 * [code]
028 * \@Override
029 * public int hashCode() {
030 * return object.hashCodeOf(getClass())
031 * .and(_prop1)
032 * .and(_prop2).value();
033 * }
034 * [/code]
035 *
036 * @see object#hashCodeOf(Class)
037 *
038 * @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
039 * @since 1.0
040 * @version 1.0 — <em>$Date: 2014-02-27 $</em>
041 *
042 * @deprecated Will be (re)moved; internal use only.
043 */
044 @Deprecated
045 public abstract class HashCodeBuilder {
046
047 protected int _hash = 0;
048
049 protected HashCodeBuilder(final Class<?> type) {
050 _hash = type.hashCode();
051 }
052
053 /**
054 * Add hash code for a {@code boolean}.
055 *
056 * @param value the value to add to the hash code.
057 * @return {@code this}
058 */
059 public abstract HashCodeBuilder and(final boolean value);
060
061 /**
062 * Add hash code for an {@code boolean} array.
063 *
064 * @param values the value to add to the hash code.
065 * @return {@code this}
066 */
067 public abstract HashCodeBuilder and(final boolean[] values);
068
069 /**
070 * Add hash code for a {@code byte}.
071 *
072 * @param value the value to add to the hash code.
073 * @return {@code this}
074 */
075 public abstract HashCodeBuilder and(final byte value);
076
077 /**
078 * Add hash code for an {@code byte} arrays.
079 *
080 * @param values the value to add to the hash code.
081 * @return {@code this}
082 */
083 public abstract HashCodeBuilder and(final byte[] values);
084
085 /**
086 * Add hash code for a {@code char}.
087 *
088 * @param value the value to add to the hash code.
089 * @return {@code this}
090 */
091 public abstract HashCodeBuilder and(final char value);
092
093 /**
094 * Add hash code for an {@code char} array.
095 *
096 * @param values the value to add to the hash code.
097 * @return {@code this}
098 */
099 public abstract HashCodeBuilder and(final char[] values);
100
101 /**
102 * Add hash code for a {@code short}.
103 *
104 * @param value the value to add to the hash code.
105 * @return {@code this}
106 */
107 public abstract HashCodeBuilder and(final short value);
108
109 /**
110 * Add hash code for an {@code short} array.
111 *
112 * @param values the value to add to the hash code.
113 * @return {@code this}
114 */
115 public abstract HashCodeBuilder and(final short[] values);
116
117 /**
118 * Add hash code for an {@code int}.
119 *
120 * @param value the value to add to the hash code.
121 * @return {@code this}
122 */
123 public abstract HashCodeBuilder and(final int value);
124
125 /**
126 * Add hash code for an {@code int} array.
127 *
128 * @param values the value to add to the hash code.
129 * @return {@code this}
130 */
131 public abstract HashCodeBuilder and(final int[] values);
132
133 /**
134 * Add hash code for a {@code long}.
135 *
136 * @param value the value to add to the hash code.
137 * @return {@code this}
138 */
139 public abstract HashCodeBuilder and(final long value);
140
141 /**
142 * Add hash code for an {@code long} array.
143 *
144 * @param values the value to add to the hash code.
145 * @return {@code this}
146 */
147 public abstract HashCodeBuilder and(final long[] values);
148
149 /**
150 * Add hash code for a {@code float}.
151 *
152 * @param value the value to add to the hash code.
153 * @return {@code this}
154 */
155 public abstract HashCodeBuilder and(final float value);
156
157 /**
158 * Add hash code for an {@code float} array.
159 *
160 * @param values the value to add to the hash code.
161 * @return {@code this}
162 */
163 public abstract HashCodeBuilder and(final float[] values);
164
165 /**
166 * Add hash code for a {@code double}.
167 *
168 * @param value the value to add to the hash code.
169 * @return {@code this}
170 */
171 public abstract HashCodeBuilder and(final double value);
172
173 /**
174 * Add hash code for an {@code double} array.
175 *
176 * @param values the value to add to the hash code.
177 * @return {@code this}
178 */
179 public abstract HashCodeBuilder and(final double[] values);
180
181 /**
182 * Add hash code for a {@code Object}.
183 *
184 * @param value the value to add to the hash code.
185 * @return {@code this}
186 */
187 public abstract HashCodeBuilder and(final Object value);
188
189 /**
190 * Add hash code for an {@code Object}.
191 *
192 * @param values the value to add to the hash code.
193 * @return {@code this}
194 */
195 public abstract HashCodeBuilder and(final Object[] values);
196
197 /**
198 * Add hash code for a {@code Seq}.
199 *
200 * @param values the value to add to the hash code.
201 * @return {@code this}
202 */
203 public abstract HashCodeBuilder and(final Seq<?> values);
204
205 /**
206 * Return the calculated hash value.
207 *
208 * @return the calculated hash value.
209 */
210 public int value() {
211 return _hash;
212 }
213
214 }
|