Java tutorial
/** * Copyright 2011 The Kuali Foundation Licensed under the * Educational Community License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may * obtain a copy of the License at * * http://www.osedu.org/licenses/ECL-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an "AS IS" * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express * or implied. See the License for the specific language governing * permissions and limitations under the License. */ package org.kuali.student.common.util.krms.proposition; import java.util.Collection; import org.apache.commons.collections.CollectionUtils; import org.kuali.rice.krms.api.engine.ExecutionEnvironment; import org.kuali.rice.krms.api.engine.ResultEvent; import org.kuali.rice.krms.framework.engine.Proposition; import org.kuali.rice.krms.framework.engine.PropositionResult; import org.kuali.rice.krms.framework.engine.result.BasicResult; import org.kuali.student.common.util.krms.RulesExecutionConstants; /** * Parent class for all course completion propositions * * @author alubbers */ public abstract class CourseCompletionProposition extends AbstractLeafProposition implements Proposition { protected final boolean checkForAllCompleted; protected Integer minToComplete; public CourseCompletionProposition(Integer minToComplete) { this.checkForAllCompleted = false; this.minToComplete = minToComplete; } public CourseCompletionProposition() { checkForAllCompleted = true; } @Override public PropositionResult evaluate(ExecutionEnvironment environment) { Collection<String> completedCourses = environment .resolveTerm(RulesExecutionConstants.STUDENT_COMPLETED_COURSE_IDS_TERM, this); Collection<String> termCourses = getTermCourseIds(environment); PropositionResult result = null; if (checkForAllCompleted) { result = new PropositionResult(completedCourses.containsAll(termCourses)); } else { result = new PropositionResult( CollectionUtils.intersection(completedCourses, termCourses).size() >= minToComplete); } environment.getEngineResults().addResult( new BasicResult(ResultEvent.PROPOSITION_EVALUATED, this, environment, result.getResult())); return result; } protected abstract Collection<String> getTermCourseIds(ExecutionEnvironment environment); }