001/**
002 * Copyright 2005-2018 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.krad.datadictionary.validation.constraint.resolver;
017
018import org.kuali.rice.krad.datadictionary.validation.capability.Constrainable;
019import org.kuali.rice.krad.datadictionary.validation.capability.SimpleConstrainable;
020import org.kuali.rice.krad.datadictionary.validation.constraint.Constraint;
021
022import java.util.ArrayList;
023import java.util.Collections;
024import java.util.List;
025
026public class SimpleConstraintResolver<T extends Constrainable> implements ConstraintResolver<T> {
027
028    /**
029     * Return SimpleConstraint if SimpleConstrainable, otherwise return an empty list.
030     *
031     * @param definition Definition to extract a SimpleConstraint from
032     * @param <C> SimpleConstraint
033     * @return SimpleConstraint if SimpleConstrainable, otherwise return an empty list.
034     */
035    public <C extends Constraint> List<C> resolve(T definition) {
036        if (definition instanceof SimpleConstrainable) {
037            C simpleConstraint = (C) (((SimpleConstrainable) definition).getSimpleConstraint());
038            return Collections.singletonList(simpleConstraint);
039        } else {
040            return new ArrayList<C>();
041        }
042    }
043}