Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2011 JBoss Inc
   *
   * Licensed under the Apache 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.apache.org/licenses/LICENSE-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.drools.planner.core.domain.variable;
 
 import java.util.List;
 
 
 public class PlanningVariableDescriptor {
 
 
 
     private PlanningValueSorter valueSorter;
 
     public PlanningVariableDescriptor(PlanningEntityDescriptor planningEntityDescriptor,
             PropertyDescriptor variablePropertyDescriptor) {
         this. = planningEntityDescriptor;
         this. = variablePropertyDescriptor;
         processPropertyAnnotations();
     }
 
     private void processPropertyAnnotations() {
         PlanningVariable planningVariableAnnotation = .getReadMethod()
                 .getAnnotation(PlanningVariable.class);
         Class<? extends ComparatorstrengthComparatorClass = planningVariableAnnotation.strengthComparatorClass();
         if (strengthComparatorClass == PlanningVariable.NullStrengthComparator.class) {
             strengthComparatorClass = null;
         }
         Class<? extends PlanningValueStrengthWeightFactorystrengthWeightFactoryClass
                 = planningVariableAnnotation.strengthWeightFactoryClass();
         if (strengthWeightFactoryClass == PlanningVariable.NullStrengthWeightFactory.class) {
             strengthWeightFactoryClass = null;
         }
         if (strengthComparatorClass != null && strengthWeightFactoryClass != null) {
             throw new IllegalStateException("The planningEntityClass ("
                     + .getPlanningEntityClass()
                     + ") " + .getName() + ") cannot have a strengthComparatorClass (" + strengthComparatorClass.getName()
                     + ") and a strengthWeightFactoryClass (" + strengthWeightFactoryClass.getName()
                     + ") at the same time.");
         }
          = new PlanningValueSorter();
         if (strengthComparatorClass != null) {
             Comparator<ObjectstrengthComparator;
             try {
                 strengthComparator = strengthComparatorClass.newInstance();
             } catch (InstantiationException e) {
                 throw new IllegalArgumentException("The strengthComparatorClass ("
                         + strengthComparatorClass.getName()
                         + ") does not have a public no-arg constructor"e);
             } catch (IllegalAccessException e) {
                 throw new IllegalArgumentException("The strengthComparatorClass ("
                         + strengthComparatorClass.getName()
                         + ") does not have a public no-arg constructor"e);
             }
             .setStrengthComparator(strengthComparator);
         }
         if (strengthWeightFactoryClass != null) {
             PlanningValueStrengthWeightFactory strengthWeightFactory;
             try {
                 strengthWeightFactory = strengthWeightFactoryClass.newInstance();
             } catch (InstantiationException e) {
                 throw new IllegalArgumentException("The strengthWeightFactoryClass ("
                         + strengthWeightFactoryClass.getName()
                         + ") does not have a public no-arg constructor"e);
             } catch (IllegalAccessException e) {
                 throw new IllegalArgumentException("The strengthWeightFactoryClass ("
                         + strengthWeightFactoryClass.getName()
                         + ") does not have a public no-arg constructor"e);
             }
            .setStrengthWeightFactory(strengthWeightFactory);
        }
        Method propertyGetter = .getReadMethod();
        int valueRangeAnnotationCount = 0;
        if (propertyGetter.isAnnotationPresent(ValueRangeFromSolutionProperty.class)) {
                    propertyGetter.getAnnotation(ValueRangeFromSolutionProperty.class));
            valueRangeAnnotationCount++;
        }
        if (propertyGetter.isAnnotationPresent(ValueRangeFromPlanningEntityProperty.class)) {
                    propertyGetter.getAnnotation(ValueRangeFromPlanningEntityProperty.class));
            valueRangeAnnotationCount++;
        }
        if (propertyGetter.isAnnotationPresent(ValueRangeUndefined.class)) {
             = new UndefinedPlanningValueRangeDescriptor(this,
                    propertyGetter.getAnnotation(ValueRangeUndefined.class));
            valueRangeAnnotationCount++;
        }
        // TODO Support plugging in other ValueRange implementations
        if (valueRangeAnnotationCount <= 0) {
            throw new IllegalArgumentException("The planningEntityClass ("
                    + .getPlanningEntityClass()
                    + ") has a PlanningVariable annotated property (" + .getName()
                    + ") that has no ValueRange* annotation, such as ValueRangeFromSolutionProperty.");
        }
        if (valueRangeAnnotationCount > 1) {
            throw new IllegalArgumentException("The planningEntityClass ("
                    + .getPlanningEntityClass()
                    + ") has a PlanningVariable annotated property (" + .getName()
                    + ") that has multiple ValueRange* annotations.");
        }
    }
        return ;
    }
    public String getVariablePropertyName() {
        return .getName();
    }
        return ;
    }
    public boolean isInitialized(Object planningEntity) {
        // TODO extract to VariableInitialized interface
        Object variable = DescriptorUtils.executeGetter(planningEntity);
        return variable != null;
    }
    public void uninitialize(Object planningEntity) {
        // TODO extract to VariableInitialized interface
        DescriptorUtils.executeSetter(planningEntitynull);
    }
    public Object getValue(Object planningEntity) {
        return DescriptorUtils.executeGetter(planningEntity);
    }
    public void setValue(Object planningEntityObject value) {
        DescriptorUtils.executeSetter(planningEntityvalue);
    }
    public Collection<?> extractPlanningValues(SolutionDirector solutionDirectorObject planningEntity) {
        return .extractValues(solutionDirectorplanningEntity);
    }
    public boolean isPlanningValuesCacheable() {
        return .isValuesCacheable();
    }
New to GrepCode? Check out our FAQ X