/*
 * 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 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-28 $</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) {
		@SuppressWarnings("unchecked")
		final Class<T> type = (Class<T>)self.getClass();
		return new Equality<>(self, cast(type, 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);
	}
}

@@ -771,16 +771,74 @@
 .util;%0A%0A
+import static org.jenetics.internal.util.reflect.typeOf;%0A%0A
 import j
@@ -1042,9 +1042,9 @@
 06-2
-8
+9
  $%3C/
@@ -1466,92 +1466,8 @@
 ) %7B%0A
-%09%09@SuppressWarnings(%22unchecked%22)%0A%09%09final Class%3CT%3E type = (Class%3CT%3E)self.getClass();%0A
 %09%09re
@@ -1501,16 +1501,24 @@
 ast(type
+Of(self)
 , other)

Simplify 'Equality' class.