/*
 * 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 org.jenetics.internal.util.reflect.typeOf;

import java.util.Optional;
import java.util.function.Predicate;

/**
 * @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
 * @since 3.0
 * @version 3.0 &mdash; <em>$Date: 2014-06-29 $</em>
 */
public final class Equality<T> {
	private final T _self;
	private final Optional<T> _other;

	private Equality(final T self, final Optional<T> other) {
		_self = self;
		_other = other;
	}

	public boolean test(final Predicate<T> equality) {
		return _other.filter(o -> o == _self).isPresent() ||
			_other.filter(equality).isPresent();
	}

	public static <T> Equality<T> of(final T self, final Object other) {
		return new Equality<>(self, cast(typeOf(self), other));
	}

	private static <A> Optional<A> cast(final Class<A> type, final Object object) {
		return Optional.ofNullable(object)
			.filter(o -> o.getClass() == type)
			.map(type::cast);
	}
}

@@ -829,16 +829,42 @@
 ypeOf;%0A%0A
+import java.util.Objects;%0A
 import j
@@ -1067,10 +1067,10 @@
 -06-
-29
+30
  $%3C/
@@ -1084,22 +1084,16 @@
 %0Apublic 
-final 
 class Eq
@@ -1233,20 +1233,44 @@
 _self = 
+Objects.requireNonNull(
 self
+)
 ;%0A%09%09_oth
@@ -1274,21 +1274,45 @@
 other = 
+Objects.requireNonNull(
 other
+)
 ;%0A%09%7D%0A%0A%09p
@@ -1370,16 +1370,41 @@
 %09return 
+_other.isPresent() &&%0A%09%09%09
 _other.f
@@ -1481,24 +1481,82 @@
 sent();%0A%09%7D%0A%0A
+%09public boolean test() %7B%0A%09%09return _other.isPresent();%0A%09%7D%0A%0A
 %09public stat
@@ -1855,10 +1855,11 @@
 st);%0A%09%7D%0A
+%0A
 %7D%0A

Fix 'Equality' class.