Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.drools.planner.core.domain.entity;
  
 import java.util.Map;
 
 
 public class PlanningEntityDescriptor {
 
     private final SolutionDescriptor solutionDescriptor;
 
     private final Class<?> planningEntityClass;
     private final BeanInfo planningEntityBeanInfo;
 
 
     public PlanningEntityDescriptor(SolutionDescriptor solutionDescriptorClass<?> planningEntityClass) {
         this. = solutionDescriptor;
         this. = planningEntityClass;
         try {
              = Introspector.getBeanInfo(planningEntityClass);
         } catch (IntrospectionException e) {
             throw new IllegalStateException("The planningEntityClass (" + planningEntityClass
                     + ") is not a valid java bean."e);
         }
         processEntityAnnotations();
         processPropertyAnnotations();
     }
 
     private void processEntityAnnotations() {
         PlanningEntity planningEntityAnnotation = .getAnnotation(PlanningEntity.class);
         if (planningEntityAnnotation == null) {
             throw new IllegalStateException("The planningEntityClass (" + 
                     + ") has been specified as a planning entity in the configuration," +
                     " but does not have a PlanningEntity annotation.");
         }
         Class<? extends ComparatordifficultyComparatorClass = planningEntityAnnotation.difficultyComparatorClass();
         if (difficultyComparatorClass == PlanningEntity.NullDifficultyComparator.class) {
             difficultyComparatorClass = null;
         }
         Class<? extends PlanningEntityDifficultyWeightFactorydifficultyWeightFactoryClass
                 = planningEntityAnnotation.difficultyWeightFactoryClass();
         if (difficultyWeightFactoryClass == PlanningEntity.NullDifficultyWeightFactory.class) {
             difficultyWeightFactoryClass = null;
         }
         if (difficultyComparatorClass != null && difficultyWeightFactoryClass != null) {
             throw new IllegalStateException("The planningEntityClass (" + 
                     + ") cannot have a difficultyComparatorClass (" + difficultyComparatorClass.getName()
                     + ") and a difficultyWeightFactoryClass (" + difficultyWeightFactoryClass.getName()
                     + ") at the same time.");
         }
          = new PlanningEntitySorter();
         if (difficultyComparatorClass != null) {
             Comparator<ObjectdifficultyComparator;
             try {
                 difficultyComparator = difficultyComparatorClass.newInstance();
             } catch (InstantiationException e) {
                 throw new IllegalArgumentException("The difficultyComparatorClass ("
                         + difficultyComparatorClass.getName()
                         + ") does not have a public no-arg constructor"e);
             } catch (IllegalAccessException e) {
                 throw new IllegalArgumentException("The difficultyComparatorClass ("
                         + difficultyComparatorClass.getName()
                         + ") does not have a public no-arg constructor"e);
             }
             .setDifficultyComparator(difficultyComparator);
         }
         if (difficultyWeightFactoryClass != null) {
             PlanningEntityDifficultyWeightFactory difficultyWeightFactory;
             try {
                 difficultyWeightFactory = difficultyWeightFactoryClass.newInstance();
             } catch (InstantiationException e) {
                 throw new IllegalArgumentException("The difficultyWeightFactoryClass ("
                         + difficultyWeightFactoryClass.getName()
                         + ") does not have a public no-arg constructor"e);
             } catch (IllegalAccessException e) {
                 throw new IllegalArgumentException("The difficultyWeightFactoryClass ("
                         + difficultyWeightFactoryClass.getName()
                         + ") does not have a public no-arg constructor"e);
             }
             .setDifficultyWeightFactory(difficultyWeightFactory);
         }
     }
 
     private void processPropertyAnnotations() {
         int mapSize = .getPropertyDescriptors().length;
        boolean noPlanningVariableAnnotation = true;
        for (PropertyDescriptor propertyDescriptor : .getPropertyDescriptors()) {
            Method propertyGetter = propertyDescriptor.getReadMethod();
            if (propertyGetter.isAnnotationPresent(PlanningVariable.class)) {
                noPlanningVariableAnnotation = false;
                if (propertyDescriptor.getWriteMethod() == null) {
                    throw new IllegalStateException("The planningEntityClass (" + 
                            + ") has a PlanningVariable annotated property (" + propertyDescriptor.getName()
                            + ") that should have a setter.");
                }
                PlanningVariableDescriptor planningVariableDescriptor = new PlanningVariableDescriptor(
                        thispropertyDescriptor);
                .put(propertyDescriptor.getName(), planningVariableDescriptor);
            }
        }
        if (noPlanningVariableAnnotation) {
            throw new IllegalStateException("The planningEntityClass (" + 
                    + ") should have at least 1 getter with a PlanningVariable annotation.");
        }
    }
        return ;
    }
    public Class<?> getPlanningEntityClass() {
        return ;
    }
        return ;
    }
        return .values();
    }
    public boolean isInitialized(Object planningEntity) {
        for (PlanningVariableDescriptor planningVariableDescriptor : .values()) {
            if (!planningVariableDescriptor.isInitialized(planningEntity)) {
                return false;
            }
        }
        return true;
    }
    public void uninitialize(Object planningEntity) {
        for (PlanningVariableDescriptor planningVariableDescriptor : .values()) {
            planningVariableDescriptor.uninitialize(planningEntity);
        }
    }
New to GrepCode? Check out our FAQ X