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