All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.napp.util.mass.InternalEvaluator Maven / Gradle / Ivy

package com.github.napp.util.mass;


/**
 * @author Alexandru Bledea
 * @since Jul 31, 2013
 */
class InternalEvaluator {

	/**
	 * @param obj
	 * @param skipNullObjects
	 * @param generator
	 * @param skipNullValues
	 * @param result
	 * @return
	 * @throws DuplicateKeyException
	 */
	static  EvaluationResult evaluate(Obj obj, boolean skipNullObjects, IEvaluator generator,
			boolean skipNullValues, boolean allowDupes, IDupeChecker where, EvaluationResult result)
			throws DuplicateKeyException {
		result.clear();
		boolean skip = false;
		if (obj == null) {
			if (skipNullObjects) {
				skip = true;
			} else {
				throw new NullPointerException("Null Value in Collection");
			}
		} else {
			Result evaluate = generator.evaluate(obj);
			if (evaluate == null && skipNullValues) {
				skip = true;
			} else {
				if (!allowDupes && where.checkIfDupe(evaluate)) {
					throw new DuplicateKeyException(evaluate);
				}
				result.result = evaluate;
			}
		}
		result.skip = skip;
		return result;
	}

	/**
	 * @author Alexandru Bledea
	 * @since Jul 31, 2013
	 * @param 
	 */
	static interface IDupeChecker {

		/**
		 * @param what
		 * @return
		 */
		boolean checkIfDupe(What what);
	}

	/**
	 * @author Alexandru Bledea
	 * @since Jul 31, 2013
	 * @param 
	 */
	static class EvaluationResult {

		private boolean skip;
		private Result result;

		/**
		 * @return the skip
		 */
		public boolean skip() {
			return skip;
		}

		/**
		 * @return the result
		 */
		public Result getResult() {
			return result;
		}

		/**
		 *
		 */
		public void clear() {
			skip = false;
			result = null;
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy