01 /*
02 * Java Genetic Algorithm Library (jenetics-3.5.0).
03 * Copyright (c) 2007-2016 Franz Wilhelmstötter
04 *
05 * Licensed under the Apache License, Version 2.0 (the "License");
06 * you may not use this file except in compliance with the License.
07 * You may obtain a copy of the License at
08 *
09 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * Author:
18 * Franz Wilhelmstötter (franz.wilhelmstoetter@gmx.at)
19 */
20 package org.jenetics.internal.util;
21
22 import java.io.Serializable;
23
24 /**
25 * Int reference class, which allows the usage in an lambda expression.
26 *
27 * @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
28 * @since 3.0
29 * @version 3.0
30 */
31 public final class IntRef implements Serializable {
32 private static final long serialVersionUID = 1;
33
34 /**
35 * The actual int value.
36 */
37 public int value;
38
39 /**
40 * Create a new {@code IntRef} object with the given initial value.
41 *
42 * @param initialValue the initial int value of the reference.
43 */
44 public IntRef(final int initialValue) {
45 value = initialValue;
46 }
47
48 /**
49 * Create a new {@code IntRef} object initialized with zero.
50 */
51 public IntRef() {
52 this(0);
53 }
54
55 @Override
56 public int hashCode() {
57 return Integer.hashCode(value);
58 }
59
60 @Override
61 public boolean equals(final Object obj) {
62 return obj instanceof IntRef && ((IntRef)obj).value == value;
63 }
64
65 @Override
66 public String toString() {
67 return Integer.toString(value);
68 }
69
70 }
|