001/* 002 * Java Genetic Algorithm Library (jenetics-7.2.0). 003 * Copyright (c) 2007-2023 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@gmail.com) 019 */ 020package io.jenetics.internal.util; 021 022import java.io.Serial; 023import java.io.Serializable; 024 025/** 026 * Int reference class, which allows the usage in an lambda expression. 027 * 028 * @author <a href="mailto:franz.wilhelmstoetter@gmail.com">Franz Wilhelmstötter</a> 029 * @since 3.0 030 * @version 3.0 031 */ 032public final class IntRef implements Serializable { 033 034 @Serial 035 private static final long serialVersionUID = 1; 036 037 /** 038 * The actual int value. 039 */ 040 public int value; 041 042 /** 043 * Create a new {@code IntRef} object with the given initial value. 044 * 045 * @param initialValue the initial int value of the reference. 046 */ 047 public IntRef(final int initialValue) { 048 value = initialValue; 049 } 050 051 /** 052 * Create a new {@code IntRef} object initialized with zero. 053 */ 054 public IntRef() { 055 this(0); 056 } 057 058 @Override 059 public int hashCode() { 060 return Integer.hashCode(value); 061 } 062 063 @Override 064 public boolean equals(final Object obj) { 065 return obj instanceof IntRef other && other.value == value; 066 } 067 068 @Override 069 public String toString() { 070 return Integer.toString(value); 071 } 072 073}