property 표현식(특성 및 property 참조)을 사용하면 "안전한" Java 메소드를 호출할 수 있습니다.
규칙 세트에는 종종 여러 java.util.List 인스턴스가 포함되어 있습니다.
CER에는 다음과 같이 java.util.List의 안전한 메소드 목록이 포함되어 있습니다.
# java.util.List의 안전 목록 contains.safe=true containsAll.safe=true get.safe=true indexOf.safe=true isEmpty.safe=true lastIndexOf.safe=true size.safe=true subList.safe=true # 노출되지 않음 hashCode.safe=false listIterator.safe=false iterator.safe=false toArray.safe=false # 뮤테이터(mutator) - 안전하지 않음 add.safe=false addAll.safe=false clear.safe=false remove.safe=false removeAll.safe=false retainAll.safe=false
이러한 메소드의 설명은 java.util.List의 JavaDoc에서 사용 가능한 반면 가장 일반적으로 유용한 특성은 사용자가 참조하도록 여기에 포함되어 있습니다.
이 목록에 요소가 포함되지 않은 경우 true를 리턴합니다.
이 목록에 있는 요소의 수를 리턴합니다.
이 목록의 지정된 위치에 요소를 리턴합니다. CER이 Number의 인스턴스로 반올림된 숫자 값을 전달하므로 intValue를 사용하여 Number를 정수로 변환해야 합니다.
이 목록에 지정된 요소가 포함된 경우 true를 리턴합니다.
<?xml version="1.0" encoding="UTF-8"?> <RuleSet name="Example_UsefulListOperations" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation= "http://www.curamsoftware.com/CreoleRulesSchema.xsd"> <Class name="Person"> <!-- 정확히 한 사람(각 가정에서)이 가정의 세대주로 지정됩니다. --> <Attribute name="isHeadOfHousehold"> <type> <javaclass name="Boolean"/> </type> <derivation> <specified/> </derivation> </Attribute> <!-- 이 개인의 자녀입니다. --> <Attribute name="children"> <type> <javaclass name="List"> <ruleclass name="Person"/> </javaclass> </type> <derivation> <specified/> </derivation> </Attribute> <!-- 이 개인에게 자녀가 있는지 여부입니다. 목록의 isEmpty 특성을 테스트합니다. --> <Attribute name="hasChildren"> <type> <javaclass name="Boolean"/> </type> <derivation> <not> <property name="isEmpty"> <object> <reference attribute="children"/> </object> </property> </not> </derivation> </Attribute> <Attribute name="numberOfChildren"> <type> <javaclass name="Number"/> </type> <derivation> <property name="size"> <object> <reference attribute="children"/> </object> </property> </derivation> </Attribute> <!-- 이 개인의 두 번째 자녀입니다(있는 경우). 없으면 널입니다. --> <Attribute name="secondChild"> <type> <ruleclass name="Person"/> </type> <derivation> <!-- 개인의 자녀가 둘 이상인지를 확인해야 합니다. --> <choose> <type> <ruleclass name="Person"/> </type> <when> <condition> <compare comparison=">="> <reference attribute="numberOfChildren"/> <Number value="2"/> </compare> </condition> <value> <!-- "get" 특성을 사용하여 색인 1로 표시된(Java의 목록은 0 기반임) 두 번째 항목을 가져옵니다. --> <property name="get"> <object> <reference attribute="children"/> </object> <arguments> <!-- 숫자는 정수로 변환해야 합니다. (List.subList에 필수입니다.) --> <property name="intValue"> <object> <Number value="1"/> </object> </property> </arguments> </property> </value> </when> <otherwise> <!-- 이 개인에게는 둘째 자녀가 없음 --> <value> <null/> </value> </otherwise> </choose> </derivation> </Attribute> <Attribute name="isChildOfHeadOfHousehold"> <type> <javaclass name="Boolean"/> </type> <derivation> <property name="contains"> <object> <!-- 세대주의 자녀 --> <reference attribute="children"> <!-- isHeadOfHousehold가 true인 하나의 Person 규칙 오브젝트를 검색합니다.--> <singleitem onEmpty="error" onMultiple="error"> <readall ruleclass="Person"> <match retrievedattribute="isHeadOfHousehold"> <true/> </match> </readall> </singleitem> </reference> </object> <!-- 세대주의 자녀 목록에 이 개인이 포함되는지를 확인합니다. --> <arguments> <this/> </arguments> </property> </derivation> </Attribute> </Class> </RuleSet>