Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.drools.planner.core.domain.variable;
  
  import java.util.List;
  
 
 public class PlanningVariableDescriptor {
 
 
 
     private PropertyDescriptor rangePropertyDescriptor// TODO extract to RangeValue interface
 
     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();
         if (propertyGetter.isAnnotationPresent(ValueRangeFromSolutionProperty.class)) {
         } else if (propertyGetter.isAnnotationPresent(ValueRangeUndefined.class)) {
             processValueRangeUndefinedAnnotation(propertyGetter.getAnnotation(ValueRangeUndefined.class));
         } else {
             // TODO Support plugging in other ValueRange implementations
             throw new IllegalArgumentException("The planningEntityClass ("
                     + .getPlanningEntityClass()
                     + ") has a PlanningVariable annotated property (" + .getName()
                     + ") that has no ValueRange* annotation, such as ValueRangeFromSolutionProperty.");
         }
     }
 
            ValueRangeFromSolutionProperty valueRangeFromSolutionPropertyAnnotation) {
        // TODO extract to RangeValue interface
        String solutionPropertyName = valueRangeFromSolutionPropertyAnnotation.propertyName();
                .getPropertyDescriptor(solutionPropertyName);
        if ( == null) {
            String exceptionMessage = "The planningEntityClass ("
                    + .getPlanningEntityClass()
                    + ") has a PlanningVariable annotated property (" + .getName()
                    + ") that refers to a solutionClass ("
                    + .getSolutionDescriptor().getSolutionClass()
                    + ") solutionProperty (" + solutionPropertyName
                    + ") that does not exist.";
            if (solutionPropertyName.length() >= 2 && Character.isUpperCase(solutionPropertyName.charAt(1))) {
                String correctedSolutionPropertyName = solutionPropertyName.substring(0, 1).toUpperCase()
                        + solutionPropertyName.substring(1);
                exceptionMessage += " But it probably needs to be correctedSolutionPropertyName ("
                        + correctedSolutionPropertyName + ") instead because the JavaBeans spec states" +
                        " the first letter should be a upper case if the second is upper case.";
            }
            throw new IllegalArgumentException(exceptionMessage);
        }
            throw new IllegalArgumentException("The planningEntityClass ("
                    + .getPlanningEntityClass()
                    + ") has a PlanningVariable annotated property (" + .getName()
                    + ") that refers to a solutionClass ("
                    + .getSolutionDescriptor().getSolutionClass()
                    + ") solutionProperty (" + solutionPropertyName
                    + ") that does not return a Collection.");
        }
    }
    private void processValueRangeUndefinedAnnotation(ValueRangeUndefined valueRangeUndefined) {
        // TODO extract to RangeValue interface
         = null;
    }
        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 bean) {
        return DescriptorUtils.executeGetter(bean);
    }
    public void setValue(Object beanObject value) {
        DescriptorUtils.executeSetter(beanvalue);
    }
    private Collection<?> extractPlanningValueCollection(Solution solution) {
        // TODO extract to RangeValue interface
        if ( == null) {
            throw new IllegalStateException("The planningEntityClass ("
                    + .getPlanningEntityClass()
                    + ") has a PlanningVariable annotated property (" + .getName()
                    + ") which uses a @ValueRangeUndefined instead of a @ValueRangeFromSolutionProperty.");
        }
        return (Collection<?>) DescriptorUtils.executeGetter(solution);
    }
    public List<ObjectgetPlanningValueList(Solution solution) {
        return new ArrayList<Object>(extractPlanningValueCollection(solution));
    }
New to GrepCode? Check out our FAQ X