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.internal.util;
021
022 import java.util.Arrays;
023
024 import org.jenetics.util.HashCodeBuilder;
025 import org.jenetics.util.Seq;
026 import org.jenetics.util.arrays;
027
028 /**
029 * @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
030 * @since 1.0
031 * @version 1.0 — <em>$Date$</em>
032 */
033 @SuppressWarnings("deprecation")
034 public final class DefaultHashCodeBuilder
035 extends HashCodeBuilder
036 implements Hash
037 {
038 private static final int P1 = 47;
039 private static final int P2 = 103;
040 private static final int P3 = 1231;
041 private static final int P4 = 1237;
042
043
044 public DefaultHashCodeBuilder(final Class<?> type) {
045 super(type);
046 }
047
048 @Override
049 public DefaultHashCodeBuilder and(final boolean value) {
050 _hash += value ? P3 : P4; return this;
051 }
052
053 @Override
054 public DefaultHashCodeBuilder and(final boolean[] values) {
055 _hash += Arrays.hashCode(values); return this;
056 }
057
058 @Override
059 public DefaultHashCodeBuilder and(final byte value) {
060 _hash += P1*value + P2; return this;
061 }
062
063 @Override
064 public DefaultHashCodeBuilder and(final byte[] values) {
065 _hash += Arrays.hashCode(values); return this;
066 }
067
068 @Override
069 public DefaultHashCodeBuilder and(final char value) {
070 _hash += P1*value + P2; return this;
071 }
072
073 @Override
074 public DefaultHashCodeBuilder and(final char[] values) {
075 _hash += Arrays.hashCode(values); return this;
076 }
077
078 @Override
079 public DefaultHashCodeBuilder and(final short value) {
080 _hash += P1*value + P2; return this;
081 }
082
083 @Override
084 public DefaultHashCodeBuilder and(final short[] values) {
085 _hash += Arrays.hashCode(values); return this;
086 }
087
088 @Override
089 public DefaultHashCodeBuilder and(final int value) {
090 _hash += P1*value + P2; return this;
091 }
092
093 @Override
094 public DefaultHashCodeBuilder and(final int[] values) {
095 _hash += Arrays.hashCode(values); return this;
096 }
097
098 @Override
099 public DefaultHashCodeBuilder and(final long value) {
100 _hash += P1*(int)(value^(value >>> 32)); return this;
101 }
102
103 @Override
104 public DefaultHashCodeBuilder and(final long[] values) {
105 _hash += Arrays.hashCode(values); return this;
106 }
107
108 @Override
109 public DefaultHashCodeBuilder and(final float value) {
110 _hash += P1*Float.floatToIntBits(value); return this;
111 }
112
113 @Override
114 public DefaultHashCodeBuilder and(final float[] values) {
115 _hash += Arrays.hashCode(values); return this;
116 }
117
118 @Override
119 public DefaultHashCodeBuilder and(final double value) {
120 long bits = Double.doubleToLongBits(value);
121 _hash += (int)(bits^(bits >>> 32));
122 return this;
123 }
124
125 @Override
126 public DefaultHashCodeBuilder and(final double[] values) {
127 _hash += Arrays.hashCode(values); return this;
128 }
129
130 @Override
131 public DefaultHashCodeBuilder and(final Object value) {
132 _hash += P1*(value == null ? 0 : value.hashCode()) + P2; return this;
133 }
134
135 @Override
136 public DefaultHashCodeBuilder and(final Object[] values) {
137 _hash += Arrays.hashCode(values); return this;
138 }
139
140 @Override
141 public DefaultHashCodeBuilder and(final Seq<?> values) {
142 _hash += arrays.hashCode(values); return this;
143 }
144
145 }
|