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

com.github.uscexp.blockformatpropertyfile.PropertyCondition Maven / Gradle / Ivy

There is a newer version: 0.2.0-Beta
Show newest version
/*
 * Copyright (C) 2014 by haui - all rights reserved
 */
package com.github.uscexp.blockformatpropertyfile;

import com.github.uscexp.blockformatpropertyfile.criteriastrategy.ContainsCriteriaStrategy;
import com.github.uscexp.blockformatpropertyfile.criteriastrategy.ContainsNoCaseCriteriaStrategy;
import com.github.uscexp.blockformatpropertyfile.criteriastrategy.CriteriaStrategy;
import com.github.uscexp.blockformatpropertyfile.criteriastrategy.EqualCriteriaStrategy;
import com.github.uscexp.blockformatpropertyfile.criteriastrategy.EqualNoCaseCriteriaStrategy;
import com.github.uscexp.blockformatpropertyfile.criteriastrategy.GreaterCriteriaStrategy;
import com.github.uscexp.blockformatpropertyfile.criteriastrategy.GreaterEqualCriteriaStrategy;
import com.github.uscexp.blockformatpropertyfile.criteriastrategy.NotEqualCriteriaStrategy;
import com.github.uscexp.blockformatpropertyfile.criteriastrategy.NotEqualNoCaseCriteriaStrategy;
import com.github.uscexp.blockformatpropertyfile.criteriastrategy.SmalerCriteriaStrategy;
import com.github.uscexp.blockformatpropertyfile.criteriastrategy.SmallerEqualCriteriaStrategy;
import java.lang.reflect.Constructor;

/**
 * property condition enum.
 *
 * @author  haui
 */
public enum PropertyCondition {
	EQUAL(EqualCriteriaStrategy.class),
	NOT_EQUAL(NotEqualCriteriaStrategy.class),
	EQUAL_NOCASE(EqualNoCaseCriteriaStrategy.class),
	NOT_EQUAL_NOCASE(NotEqualNoCaseCriteriaStrategy.class),
	GREATER(GreaterCriteriaStrategy.class),
	GREATER_EQUAL(GreaterEqualCriteriaStrategy.class),
	SMALLER(SmalerCriteriaStrategy.class),
	SMALLER_EQUAL(SmallerEqualCriteriaStrategy.class),
	CONTAINS(ContainsCriteriaStrategy.class),
	CONTAINS_NOCASE(ContainsNoCaseCriteriaStrategy.class);

	private CriteriaStrategy criteriaStrategy;

	private PropertyCondition(Class strategyType) {
		try {
			createInstance(strategyType);
		} catch (ReflectiveOperationException e) {
			throw new RuntimeException(e);
		}
	}

	private void createInstance(Class strategyType)
		throws ReflectiveOperationException {
		Constructor constructor = strategyType.getDeclaredConstructor(PropertyCondition.class);
		this.criteriaStrategy = constructor.newInstance(this);
	}

	public boolean evaluate(Object value, Object object) {
		return criteriaStrategy.evaluate(value, object);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy