/*
 * Java Genetic Algorithm Library (@__identifier__@).
 * Copyright (c) @__year__@ Franz Wilhelmstötter
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Author:
 *    Franz Wilhelmstötter (franz.wilhelmstoetter@gmx.at)
 */
package org.jenetics.internal.util;

import static java.lang.String.format;
import static java.util.Objects.requireNonNull;
import static org.jenetics.internal.util.Equality.eq;

import java.io.Serializable;
import java.util.function.Supplier;

/**
 * Class for lazy value initialization.
 *
 * @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
 * @since 3.0
 * @version 3.0 &mdash; <em>$Date: 2014-09-08 $</em>
 */
public final class Lazy<T> implements Supplier<T>, Serializable {
	private static final long serialVersionUID = 1L;

	private final Supplier<T> _supplier;

	private T _value;
	private volatile boolean _evaluated = false;

	private Lazy(final Supplier<T> supplier) {
		_supplier = requireNonNull(supplier);
	}

	@Override
	public T get() {
		return _evaluated ? _value : evaluate();
	}

	private synchronized T evaluate() {
		if (!_evaluated) {
			_value = _supplier.get();
			_evaluated = true;
		}

		return _value;
	}

    @Override
    public int hashCode() {
        return Hash.of(getClass()).and(get()).value();
    }

    @Override
    public boolean equals(final Object obj) {
        return Equality.of(this, obj).test(lazy -> eq(get(), lazy.get()));
    }

    @Override
    public String toString() {
        return format("Lazy[%s]", get());
    }

	/**
	 * Create a new lazy value initialization.
	 *
	 * @param supplier the lazy value supplier
	 * @param <T> the value type
	 * @return a new lazy value initialization
	 * @throws java.lang.NullPointerException if the given supplier is
	 *         {@code null}
	 */
	public static <T> Lazy<T> of(final Supplier<T> supplier) {
		return new Lazy<>(supplier);
	}

}

@@ -775,47 +775,8 @@
 l;%0A%0A
-import static java.lang.String.format;%0A
 impo
@@ -823,90 +823,62 @@
 ll;%0A
+%0A
 import 
-static org.jenetics.internal.util.Equality.eq;%0A%0Aimport java.io.Serializable
+java.io.Serializable;%0Aimport java.util.Objects
 ;%0Aim
@@ -1694,45 +1694,30 @@
 urn 
-Hash.of(getClass()).and(get()).value(
+Objects.hashCode(get()
 );%0A 
@@ -1801,65 +1801,33 @@
 urn 
-Equality.of(this, obj).test(lazy -%3E eq(get(), lazy.get())
+Objects.equals(get(), obj
 );%0A 
@@ -1896,27 +1896,25 @@
 urn 
-format(%22Lazy%5B%25s%5D%22, 
+Objects.toString(
 get(

Add 'hashCode' and 'equals' methods.