本文整理汇总了Java中org.optaplanner.core.api.domain.entity.PlanningEntity类的典型用法代码示例。如果您正苦于以下问题:Java PlanningEntity类的具体用法?Java PlanningEntity怎么用?Java PlanningEntity使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PlanningEntity类属于org.optaplanner.core.api.domain.entity包,在下文中一共展示了PlanningEntity类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: changeToPlanningEntity
import org.optaplanner.core.api.domain.entity.PlanningEntity; //导入依赖的package包/类
@Test
public void changeToPlanningEntity() {
PlannerDataObjectEditor objectEditor = createObjectEditor();
//load the editor.
objectEditor.onContextChange(context);
// reset state changed by onContextChange
Mockito.reset(view);
//emulate user input.
when(view.getPlanningEntityValue()).thenReturn(true);
//notify the presenter about the changes in the UI
objectEditor.onPlanningEntityChange();
DataObject dataObject = context.getDataObject();
//the dataObject should have been now configured as a PlanningEntity
verify(view,
times(1)).getPlanningEntityValue();
assertNotNull(dataObject.getAnnotation(PlanningEntity.class.getName()));
verify(view,
times(1)).initFieldPicker(context.getDataModel(),
dataObject,
null);
verify(view,
times(1)).showPlanningSolutionScoreType(false);
verify(view,
times(1)).showPlanningSolutionBendableScoreInput(false);
verify(view,
times(1)).setPlanningSolutionBendableScoreHardLevelsSize(0);
verify(view,
times(1)).setPlanningSolutionBendableScoreSoftLevelsSize(0);
}
示例2: getPlannerAnnotations
import org.optaplanner.core.api.domain.entity.PlanningEntity; //导入依赖的package包/类
public static Map<String, AnnotationDefinition> getPlannerAnnotations() {
HashMap<String, AnnotationDefinition> annotations = new HashMap<String, AnnotationDefinition>();
annotations.put(PlanningEntity.class.getName(),
DriverUtils.buildAnnotationDefinition(PlanningEntity.class));
annotations.put(PlanningSolution.class.getName(),
DriverUtils.buildAnnotationDefinition(PlanningSolution.class));
annotations.put(PlanningVariable.class.getName(),
DriverUtils.buildAnnotationDefinition(PlanningVariable.class));
annotations.put(ValueRangeProvider.class.getName(),
DriverUtils.buildAnnotationDefinition(ValueRangeProvider.class));
return annotations;
}
示例3: fieldPlanningEntitySettings
import org.optaplanner.core.api.domain.entity.PlanningEntity; //导入依赖的package包/类
@Test
public void fieldPlanningEntitySettings() {
PlannerDataObjectFieldEditor fieldEditor = createFieldEditor();
//first configure the DataObject as a PlanningEntity
DataObject dataObject = context.getDataObject();
dataObject.addAnnotation(new AnnotationImpl(context.getAnnotationDefinition(PlanningEntity.class.getName())));
ObjectProperty field1 = dataObject.getProperty("field1");
//emulates the selection of field1
context.setObjectProperty(field1);
//The domain editors typically reacts upon DataModelerContext changes.
//when the context changes the editor will typically be reloaded.
fieldEditor.onContextChange(context);
//emulate the user input
when(view.getPlanningVariableValue()).thenReturn(true);
when(view.getValueRangeProviderRefsValue()).thenReturn("valueRangeProviderRefsValue");
fieldEditor.onPlanningVariableChange();
fieldEditor.onValueRangeProviderRefsChange();
List<String> valueRangeProviderRefs = new ArrayList<String>();
valueRangeProviderRefs.add("valueRangeProviderRefsValue");
assertNotNull(field1.getAnnotation(PlanningVariable.class.getName()));
assertEquals(valueRangeProviderRefs,
field1.getAnnotation(PlanningVariable.class.getName()).getValue("valueRangeProviderRefs"));
}
示例4: updateDataObject
import org.optaplanner.core.api.domain.entity.PlanningEntity; //导入依赖的package包/类
public void updateDataObject(Path dataObjectPath) {
String dataObjectString = ioService.readAllString(Paths.convert(dataObjectPath));
GenerationResult generationResult = dataModelerService.loadDataObject(dataObjectPath,
dataObjectString,
dataObjectPath);
DataObject dataObject = generationResult.getDataObject();
if (dataObject != null && generationResult.getErrors() == null || generationResult.getErrors().isEmpty()) {
JavaClass comparatorObject = getComparatorObject(dataObject);
if (comparatorObject != null) {
JavaClass updatedComparatorObject = comparatorDefinitionService.updateComparatorObject(dataObject,
comparatorObject);
dataObject.removeNestedClass(comparatorObject);
dataObject.addNestedClass(updatedComparatorObject);
Annotation planningEntityAnnotation = dataObject.getAnnotation(PlanningEntity.class.getName());
if (planningEntityAnnotation != null) {
planningEntityAnnotation.setValue("difficultyComparatorClass",
dataObject.getName() + ".DifficultyComparator");
}
generationResult = dataModelerService.updateSource(dataObjectString,
dataObjectPath,
dataObject);
if (generationResult.getDataObject() != null && generationResult.getErrors() == null || generationResult.getErrors().isEmpty()) {
ioService.write(Paths.convert(dataObjectPath),
generationResult.getSource());
} else {
logger.error("Data object " + dataObject.getClassName() + " couldn't be updated, path: " + dataObjectPath + ".");
}
}
} else {
logger.error("Data object couldn't be loaded, path: " + dataObjectPath + ".");
}
}
示例5: initDataObjects
import org.optaplanner.core.api.domain.entity.PlanningEntity; //导入依赖的package包/类
private void initDataObjects() {
Map<String, AnnotationDefinition> annotationDefinitionMap = PlannerTestUtil.getComparatorObjectAnnotations();
DataObject dataObject1 = new DataObjectImpl("bar.foo",
"DataObject1");
ObjectProperty dataObject1Property1 = new ObjectPropertyImpl("dataObject1Property1",
"java.lang.Integer",
false);
ObjectProperty dataObject1Property2 = new ObjectPropertyImpl("dataObject1Property2",
"bar.foo.DataObject2",
false);
dataObject1.addProperty(dataObject1Property1);
dataObject1.addProperty(dataObject1Property2);
JavaClassImpl comparatorObject = new JavaClassImpl("",
"DifficultyComparator");
comparatorObject.addInterface(Comparator.class.getName());
comparatorObject.addAnnotation(new AnnotationImpl(annotationDefinitionMap.get(Generated.class.getName())));
Method compareMethod = new MethodImpl("compare",
Arrays.asList(new ParameterImpl(new TypeImpl(dataObject1.getClassName()),
"o1"),
new ParameterImpl(new TypeImpl(dataObject1.getClassName()),
"o2")),
"foo",
new TypeImpl("int"),
Visibility.PUBLIC);
comparatorObject.addMethod(compareMethod);
dataObject1.addNestedClass(comparatorObject);
AnnotationImpl planningEntityAnnotation = new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningEntity.class));
planningEntityAnnotation.setValue("difficultyComparatorClass",
dataObject1.getName() + "." + "DifficultyComparator.class");
dataObject1.addAnnotation(planningEntityAnnotation);
ObjectPropertyPath objectPropertyPath = new ObjectPropertyPathImpl();
objectPropertyPath.appendObjectProperty(dataObject1Property2);
objectPropertyPath.appendObjectProperty(dataObject1Property1);
List<ObjectPropertyPath> objectPropertyPathList = new ArrayList<>(1);
objectPropertyPathList.add(objectPropertyPath);
Annotation comparatorDefinitionAnnotation = ComparatorDefinitionAnnotationValueHandler.createAnnotation(objectPropertyPathList,
annotationDefinitionMap);
comparatorObject.addAnnotation(comparatorDefinitionAnnotation);
DataObject dataObject2 = new DataObjectImpl("bar.foo",
"DataObject2");
ObjectProperty dataObject2Property1 = new ObjectPropertyImpl("dataObject2Property1",
"java.lang.Double",
false);
dataObject2.addProperty(dataObject2Property1);
this.dataObject = dataObject1;
this.comparatorObject = comparatorObject;
}
示例6: process
import org.optaplanner.core.api.domain.entity.PlanningEntity; //导入依赖的package包/类
@Override
public void process(DefaultIndexBuilder builder,
JavaType javaType) {
try {
final List<Annotation> comparatorDefinitions;
Annotation planningEntityAnnotation = javaType.getAnnotation(PlanningEntity.class.getName());
if (planningEntityAnnotation == null) {
return;
}
String difficultyComparatorClass = planningEntityAnnotation.getStringValue("difficultyComparatorClass");
if (difficultyComparatorClass != null && javaType instanceof JavaClassSource && difficultyComparatorClass.matches("\\w[\\.\\w]+\\.class")) {
String[] difficultyComparatorTokens = difficultyComparatorClass.split("\\.");
comparatorDefinitions = ((JavaClassSource) javaType).getNestedTypes().stream()
.filter(t -> t instanceof JavaClassSource
&& t.getName().equals(difficultyComparatorTokens[difficultyComparatorTokens.length - 2])
&& t.getAnnotation(ComparatorDefinition.class.getName()) != null
&& t.getAnnotation(Generated.class.getName()) != null
&& ((JavaClassSource) t).getInterfaces().stream().anyMatch(i -> i.startsWith(Comparator.class.getName())))
.map(t -> t.getAnnotation(ComparatorDefinition.class.getName()))
.collect(Collectors.toList());
} else {
return;
}
if (javaType.getSyntaxErrors() == null || javaType.getSyntaxErrors().isEmpty()) {
for (Annotation comparatorDefinition : comparatorDefinitions) {
Annotation[] fieldPathDefinitions = comparatorDefinition.getAnnotationArrayValue("objectPropertyPaths");
String previousFullyQualifiedClassname = null;
if (fieldPathDefinitions != null) {
for (Annotation fieldPathDefinition : fieldPathDefinitions) {
Annotation[] fieldDefinitions = fieldPathDefinition.getAnnotationArrayValue("objectProperties");
if (fieldDefinitions != null && fieldDefinitions.length > 0) {
previousFullyQualifiedClassname = fieldDefinitions[0].getStringValue("type");
if (previousFullyQualifiedClassname != null && previousFullyQualifiedClassname.matches("\\w[\\.\\w]+\\.class")) {
for (int i = 1; i < fieldDefinitions.length; i++) {
ResourceReference resourceReference = new ResourceReference(previousFullyQualifiedClassname.substring(0,
previousFullyQualifiedClassname.indexOf(".class")),
ResourceType.JAVA);
resourceReference.addPartReference(fieldDefinitions[i].getStringValue("name"),
PartType.FIELD);
previousFullyQualifiedClassname = fieldDefinitions[i].getStringValue("type");
builder.addGenerator(resourceReference);
}
}
}
}
}
}
}
} catch (Exception e) {
logger.error("Unable to index comparator definition for " + javaType.getQualifiedName());
}
}