<commit_before>/*
 * Java Genetic Algorithm Library (@!identifier!@).
 * Copyright (c) @!year!@ <NAME>
 *  
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Author:
 *     <NAME> (<EMAIL>)
 *     
 */
package org.jenetics.util;

/**
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @version $Id$
 */
public final class Predicates {

	private Predicates() {
	}
	
	public static class Nil implements Predicate<Object> {

		@Override
		public boolean evaluate(final Object object) {
			return object == null;
		}
		
	}
	
	public static class Not<T> implements Predicate<T> {
		private final Predicate<? super T> _predicate;
		
		public Not(final Predicate<? super T> predicate) {
			_predicate = Validator.nonNull(predicate);
		}
		
		@Override
		public boolean evaluate(final T object) {
			return !_predicate.equals(object);
		}
		
	}
	
	public static class And<T> implements Predicate<T> {
		private final Predicate<? super T> _a;
		private final Predicate<? super T> _b;
		
		public And(final Predicate<? super T> a, final Predicate<? super T> b) {
			_a = Validator.nonNull(a);
			_b = Validator.nonNull(b);
		}
		
		@Override
		public boolean evaluate(final T object) {
			return _a.equals(object) && _b.evaluate(object);
		}
	}
	
	public static class Or<T> implements Predicate<T> {
		private final Predicate<? super T> _a;
		private final Predicate<? super T> _b;
		
		public Or(final Predicate<? super T> a, final Predicate<? super T> b) {
			_a = Validator.nonNull(a);
			_b = Validator.nonNull(b);
		}
		
		@Override
		public boolean evaluate(final T object) {
			return _a.equals(object) || _b.evaluate(object);
		}
	}
	
	public static Predicate<Object> nil() {
		return new Nil();
	}
	
	public static <T> Predicate<T> not(final Predicate<? super T> predicate) {
		return new Not<T>(predicate);
	}
	
	public static <T> Predicate<T> and(
		final Predicate<? super T> a, 
		final Predicate<? super T> b
	) {
		return new And<T>(a, b);
	}
	
	public static <T> Predicate<T> or(
		final Predicate<? super T> a, 
		final Predicate<? super T> b
	) {
		return new Or<T>(a, b);
	}<commit_msg>Add org.jenetics.util.Predicates which contains some general purpose predicates like Not, And, Or, Nil.<commit_after>/*
 * Java Genetic Algorithm Library (@!identifier!@).
 * Copyright (c) @!year!@ <NAME>
 *  
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Author:
 *     <NAME> (<EMAIL>)
 *     
 */
package org.jenetics.util;

/**
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @version $Id$
 */
public final class Predicates {

	private Predicates() {
	}
	
	public static class Nil implements Predicate<Object> {

		@Override
		public boolean evaluate(final Object object) {
			return object == null;
		}
		
	}
	
	public static class Not<T> implements Predicate<T> {
		private final Predicate<? super T> _a;
		
		public Not(final Predicate<? super T> a) {
			_a = Validator.nonNull(a);
		}
		
		@Override
		public boolean evaluate(final T object) {
			return !_a.equals(object);
		}
		
	}
	
	public static class And<T> implements Predicate<T> {
		private final Predicate<? super T> _a;
		private final Predicate<? super T> _b;
		
		public And(final Predicate<? super T> a, final Predicate<? super T> b) {
			_a = Validator.nonNull(a);
			_b = Validator.nonNull(b);
		}
		
		@Override
		public boolean evaluate(final T object) {
			return _a.equals(object) && _b.evaluate(object);
		}
	}
	
	public static class Or<T> implements Predicate<T> {
		private final Predicate<? super T> _a;
		private final Predicate<? super T> _b;
		
		public Or(final Predicate<? super T> a, final Predicate<? super T> b) {
			_a = Validator.nonNull(a);
			_b = Validator.nonNull(b);
		}
		
		@Override
		public boolean evaluate(final T object) {
			return _a.equals(object) || _b.evaluate(object);
		}
	}
	
	public static Predicate<Object> nil() {
		return new Nil();
	}
	
	public static <T> Predicate<T> not(final Predicate<? super T> a) {
		return new Not<T>(a);
	}
	
	public static <T> Predicate<T> and(
		final Predicate<? super T> a, 
		final Predicate<? super T> b
	) {
		return new And<T>(a, b);
	}
	
	public static <T> Predicate<T> or(
		final Predicate<? super T> a, 
		final Predicate<? super T> b
	) {
		return new Or<T>(a, b);
	}
{'fraction_non_alphanumeric': 0.11208125445473985, 'fraction_numerical': 0.004632929436920884, 'mean_word_length': 3.522965350523771, 'pattern_counts': {'":': 0, '<': 81, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1994465', 'n_tokens_mistral': 1961, 'n_tokens_neox': 1738, 'n_words': 664}