/*
 * 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.Objects;
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-30 $</em>
 */
public class Equality<T> {
	private final T _self;
	private final Optional<T> _other;

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

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

	public boolean test() {
		return _other.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);
	}

}

@@ -782,152 +782,116 @@
 ort 
-static org.jenetics.internal.util.reflect.typeOf;%0A%0Aimport java.util.Objects;%0Aimport java.util.Optional;%0Aimport java.util.function.Predicate;%0A%0A/*
+java.util.Objects;%0Aimport java.util.function.Predicate;%0A%0A/**%0A * Interface for calculating object equality.%0A 
 *%0A *
@@ -1052,13 +1052,17 @@
 lic 
-class
+interface
  Equ
@@ -1076,587 +1076,895 @@
 %3E %7B%0A
-%09private final T _self;%0A%09private final Optional%3CT%3E _other;%0A%0A%09private Equality(final T self, final Optional%3CT%3E other) %7B%0A%09%09_self = Objects.requireNonNull(self);%0A%09%09_other = Objects.requireNonNull(other);%0A%09%7D%0A%0A%09public boolean test(final Predicate%3CT%3E equality) %7B%0A%09%09return _other.isPresent() &&%0A%09%09%09_other.filter(o -%3E o == _self).isPresent() %7C%7C%0A%09%09%09_other.filter(equality).isPresent();%0A%09%7D%0A%0A%09public boolean test() %7B%0A%09%09return _other.isPresent();%0A%09%7D%0A%0A%09public static %3CT%3E Equality%3CT%3E of(final T self, final Object other) %7B%0A%09%09return new Equality%3C%3E(self, cast(typeOf(self), other));%0A%09%7D%0A%0A%09private
+%0A%09/**%0A%09 * Perform additional object equality tests.%0A%09 *%0A%09 * @param equality the object equality test%0A%09 * @return the overall object equality.%0A%09 */%0A%09public boolean test(final Predicate%3CT%3E equality);%0A%0A%09/**%0A%09 * Test if objects are from the same type.%0A%09 *%0A%09 * @return %7B@code true%7D if the tested object are from the same type,%0A%09 *         %7B@code false%7D otherwise.%0A%09 */%0A%09public default boolean test() %7B%0A%09%09return test(o -%3E true);%0A%09%7D%0A%0A%09/**%0A%09 * Create a new %7B@code Equality%7D object for testing object equality.%0A%09 *%0A%09 * @param self the %7B@code this%7D object to test; must not be %7B@code null%7D%0A%09 * @param other the %7B@code other%7D object to test; maybe %7B@code null%7D%0A%09 * @param %3CT%3E the object type%0A%09 * @return the %7B@code Equality%7D object for equality testing%0A%09 * @throws java.lang.NullPointerException if the %7B@code self%7D parameter is%0A%09 *         %7B@code null%7D%0A%09 */%0A%09@SuppressWarnings(%22unchecked%22)%0A%09public
  sta
@@ -1972,47 +1972,38 @@
 ic %3C
-A%3E Optional%3CA%3E cast(final Class%3CA%3E type
+T%3E Equality%3CT%3E of(final T self
 , fi
@@ -2018,71 +2018,113 @@
 ct o
-bject
+ther
 ) %7B%0A%09%09
-return Optional.ofNullable(object)%0A%09%09%09.filter(o -%3E o
+Objects.requireNonNull(self);%0A%09%09return self == other ?%0A%09%09%09p -%3E true :%0A%09%09%09(other == null %7C%7C self
 .get
@@ -2135,35 +2135,68 @@
 s() 
-== type)%0A%09%09%09.map(type::cast
+!= other.getClass()) ?%0A%09%09%09%09p -%3E false : p -%3E p.test((T)other
 );%0A%09

Simplify 'Equality' class.