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

com.gregmarut.support.beangenerator.rule.Rule Maven / Gradle / Ivy

Go to download

Supports unit testing by dynamically creating bean objects and populating their fields to default values.

There is a newer version: 2.7-RELEASE
Show newest version
/*******************************************************************************
 * 
 * Copyright (c) 2015 Greg Marut.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     Greg Marut - initial API and implementation
 * 
******************************************************************************/ package com.gregmarut.support.beangenerator.rule; import com.gregmarut.support.beangenerator.ClassConversionUtil; import com.gregmarut.support.beangenerator.value.StaticValue; import com.gregmarut.support.beangenerator.value.Value; /** * Contains the base class for determining a Rule * * @author Greg Marut */ public abstract class Rule { // holds the value for this rule private final Value value; @SuppressWarnings("unchecked") public Rule(final V value) { // make sure the value is not null if (null == value) { throw new IllegalArgumentException("value cannot be null"); } this.value = new StaticValue(value, (Class) value.getClass()); } public Rule(final Value value) { // make sure the value is not null if (null == value) { throw new IllegalArgumentException("value cannot be null"); } this.value = value; } /** * Holds the return type of the value for this rule * * @return */ @SuppressWarnings("unchecked") public Class getReturnType() { return (Class) ClassConversionUtil.convertToNonPrimitive(value.getType()); } /** * Returns the value to return when this rule is matched * * @return */ public Value getValue() { return value; } /** * Determines if this rule matches the given class type and name * * @param clazz * The type of value that is being checked * @param name * The name of the attribute * @return */ public abstract boolean isMatch(final Class clazz, final String name); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy