Я новичок в слюни и java, и я пытаюсь понять, как работает это правило из примера составления списка медсестер, особенно в первой части о шаблоне $.
rule "unwantedPatternShiftType3DaysPattern"
when
$pattern : ShiftType3DaysPattern(
$dayIndex0ShiftType : dayIndex0ShiftType,
$dayIndex1ShiftType : dayIndex1ShiftType,
$dayIndex2ShiftType : dayIndex2ShiftType
)
PatternContractLine(
pattern == $pattern, $contract : contract
)
ShiftAssignment(
shiftType == $dayIndex0ShiftType,
contract == $contract,
$employee : employee, $firstDayIndex : shiftDateDayIndex
)
ShiftAssignment(
shiftType == $dayIndex1ShiftType,
employee == $employee,
shiftDateDayIndex == ($firstDayIndex + 1)
)
ShiftAssignment(
shiftType == $dayIndex2ShiftType,
employee == $employee,
shiftDateDayIndex == ($firstDayIndex + 2)
)
then
scoreHolder.addSoftConstraintMatch(kcontext, - $pattern.getWeight());
end
В частности, как слюнки узнают, какое значение находится в: dayIndex0ShiftType, dayIndex1ShiftType, dayIndex2ShiftType? Он вызывает класс ShiftType3DaysPattern с этими значениями, но как эти значения определяются?
Кроме того, когда он делает этот вызов:
ShiftType3DaysPattern (dayIndex0ShiftType, dayIndex1ShiftType, dayIndex2ShiftType)
который относится к следующему:
@XStreamAlias("ShiftType3DaysPattern")
public class ShiftType3DaysPattern extends Pattern {
private ShiftType dayIndex0ShiftType;
private ShiftType dayIndex1ShiftType;
private ShiftType dayIndex2ShiftType;
public ShiftType getDayIndex0ShiftType() {
return dayIndex0ShiftType;
}
public void setDayIndex0ShiftType(ShiftType dayIndex0ShiftType) {
this.dayIndex0ShiftType = dayIndex0ShiftType;
}
public ShiftType getDayIndex1ShiftType() {
return dayIndex1ShiftType;
}
public void setDayIndex1ShiftType(ShiftType dayIndex1ShiftType) {
this.dayIndex1ShiftType = dayIndex1ShiftType;
}
public ShiftType getDayIndex2ShiftType() {
return dayIndex2ShiftType;
}
public void setDayIndex2ShiftType(ShiftType dayIndex2ShiftType) {
this.dayIndex2ShiftType = dayIndex2ShiftType;
}
@Override
public String toString() {
return "Work pattern: " + dayIndex0ShiftType + ", " + dayIndex1ShiftType + ", " + dayIndex2ShiftType;
}
}
Это сокращение для ShiftType3DaysPattern.getDayIndex0ShiftType
, ShiftType3DaysPattern.getDayIndex1ShiftType
и ShiftType3DaysPattern.getDayIndex2ShiftType
?
И если это так, как ShiftType3DaysPattern знает, какой шаблон вернуть, если в исходных файлах xml имеется более одного «трехдневного шаблона»? Что мне не хватает?
Более того, если существует более одного «трехдневного паттерна», то как слюни автоматически применяют это правило ко всем этим «трехдневным паттернам»?