@Test public void testString_union() { String a = "a"; String b = "b"; String c = "c"; String d = "d"; String e = "e"; String f = "f"; String g = "g"; String h = "h"; String j = "j"; Bag bagabcdefg = null; Bag bagbdfhj = null; Bag bagace = null; Bag bagaaacccef = null; Bag bagInt = null; Bag bagStringInt = null; Bag bagEmpty = null; FunctionArgumentAttributeValue attrBadType = null; try { bagabcdefg = new Bag(); bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); bagbdfhj = new Bag(); bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); bagace = new Bag(); bagace.add(DataTypes.DT_STRING.createAttributeValue(a)); bagace.add(DataTypes.DT_STRING.createAttributeValue(c)); bagace.add(DataTypes.DT_STRING.createAttributeValue(e)); bagaaacccef = new Bag(); bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(e)); bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(f)); bagInt = new Bag(); bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); bagStringInt = new Bag(); bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); bagEmpty = new Bag(); attrBadType = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.1)); } catch (Exception ex) { fail("creating attribute e="+ ex); } FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); FunctionArgumentBag attrBagbdfhj = new FunctionArgumentBag(bagbdfhj); FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); FunctionArgumentBag attrBagaaacccef = new FunctionArgumentBag(bagaaacccef); FunctionArgumentBag attrBagInt = new FunctionArgumentBag(bagInt); FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); FunctionDefinitionSet<?,?> fd = (FunctionDefinitionSet<?,?>) StdFunctions.FD_STRING_UNION; assertEquals(XACML3.ID_FUNCTION_STRING_UNION, fd.getId()); assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); assertTrue(fd.returnsBag()); arguments.clear(); arguments.add(attrBagabcdefg); arguments.add(attrBagabcdefg); ExpressionResult res = fd.evaluate(null, arguments); assertTrue(res.isOk()); Bag bag = res.getBag(); assertNotNull(bag); Iterator<AttributeValue<?>> it = bag.getAttributeValues(); assertEquals(7, bag.size()); AttributeValue<?> attrValueObject = it.next(); assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); assertEquals(a, attrValueObject.getValue() ); arguments.clear(); arguments.add(attrBagace); arguments.add(attrBagbdfhj); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); bag = res.getBag(); assertNotNull(bag); it = bag.getAttributeValues(); assertEquals(8, bag.size()); attrValueObject = it.next(); assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); assertEquals(a, attrValueObject.getValue() ); arguments.clear(); arguments.add(attrBagaaacccef); arguments.add(attrBagbdfhj); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); bag = res.getBag(); assertNotNull(bag); it = bag.getAttributeValues(); assertEquals(8, bag.size()); attrValueObject = it.next(); assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); assertEquals(a, attrValueObject.getValue() ); arguments.clear(); arguments.add(attrBagaaacccef); arguments.add(attrBagace); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); bag = res.getBag(); assertNotNull(bag); it = bag.getAttributeValues(); assertEquals(4, bag.size()); attrValueObject = it.next(); assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); assertEquals(a, attrValueObject.getValue() ); attrValueObject = it.next(); assertEquals(c, attrValueObject.getValue() ); attrValueObject = it.next(); assertEquals(e, attrValueObject.getValue() ); arguments.clear(); arguments.add(attrBagbdfhj); arguments.add(attrBagaaacccef); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); bag = res.getBag(); assertNotNull(bag); it = bag.getAttributeValues(); assertEquals(8, bag.size()); attrValueObject = it.next(); assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); assertEquals(b, attrValueObject.getValue() ); arguments.clear(); arguments.add(attrBagace); arguments.add(attrBagaaacccef); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); bag = res.getBag(); assertNotNull(bag); it = bag.getAttributeValues(); assertEquals(4, bag.size()); attrValueObject = it.next(); assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); assertEquals(a, attrValueObject.getValue() ); attrValueObject = it.next(); assertEquals(c, attrValueObject.getValue() ); attrValueObject = it.next(); assertEquals(e, attrValueObject.getValue() ); arguments.clear(); arguments.add(attrBagEmpty); arguments.add(attrBagEmpty); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); bag = res.getBag(); assertNotNull(bag); it = bag.getAttributeValues(); assertEquals(0, bag.size()); arguments.clear(); arguments.add(attrBagEmpty); arguments.add(attrBagaaacccef); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); bag = res.getBag(); assertNotNull(bag); it = bag.getAttributeValues(); assertEquals(4, bag.size()); arguments.clear(); arguments.add(attrBagaaacccef); arguments.add(attrBagEmpty); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); bag = res.getBag(); assertNotNull(bag); it = bag.getAttributeValues(); assertEquals(4, bag.size()); arguments.clear(); arguments.add(attrBagace); arguments.add(attrBagStringInt); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); bag = res.getBag(); assertNotNull(bag); it = bag.getAttributeValues(); assertEquals(4, bag.size()); attrValueObject = it.next(); assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); assertEquals(a, attrValueObject.getValue() ); arguments.clear(); arguments.add(attrBagace); arguments.add(attrBagInt); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); bag = res.getBag(); assertNotNull(bag); it = bag.getAttributeValues(); assertEquals(4, bag.size()); attrValueObject = it.next(); assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); assertEquals(a, attrValueObject.getValue() ); arguments.clear(); arguments.add(attrBadType); arguments.add(attrBagabcdefg); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:string-union Expected a bag, saw a simple value", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrBagabcdefg); arguments.add(attrBadType); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:string-union Expected a bag, saw a simple value", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(null); arguments.add(attrBagabcdefg); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:string-union Got null argument", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrBagabcdefg); arguments.add(null); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:string-union Got null argument", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrBagabcdefg); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:string-union Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:string-union Expected 2 arguments, got 0", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrBagabcdefg); arguments.add(attrBagabcdefg); arguments.add(attrBagabcdefg); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:string-union Expected 2 arguments, got 3", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); }
@Override public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) { if (arguments == null || arguments.size() != 2) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Expected 2 arguments, got " + ((arguments == null) ? "null" : arguments.size()) )); } FunctionArgument bagArgument = arguments.get(0); ConvertedArgument<Bag> convertedBagArgument = new ConvertedArgument<Bag>(bagArgument, null, true); if ( ! convertedBagArgument.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedBagArgument.getStatus())); } Bag bag1 = convertedBagArgument.getBag(); List<AttributeValue<?>> list1 = (List<AttributeValue<?>>) bag1.getAttributeValueList(); bagArgument = arguments.get(1); convertedBagArgument = new ConvertedArgument<Bag>(bagArgument, null, true); if ( ! convertedBagArgument.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedBagArgument.getStatus())); } Bag bag2 = convertedBagArgument.getBag(); List<AttributeValue<?>> list2 = (List<AttributeValue<?>>) bag2.getAttributeValueList(); ExpressionResult expressionResult = null; Bag outBag; List<AttributeValue<?>> outList; switch (operation) { case INTERSECTION: outList = new ArrayList<AttributeValue<?>>(); for (AttributeValue<?> element : list1) { if (outList.contains(element)) { continue; } if (list2.contains(element)) { outList.add(element); } } outBag = new Bag(); for (AttributeValue<?> element : outList) { outBag.add(element); } expressionResult = ExpressionResult.newBag(outBag); return expressionResult; case AT_LEAST_ONE_MEMBER_OF: for (AttributeValue<?> element : list1) { if (list2.contains(element)) { return ER_TRUE; } } return ER_FALSE; case UNION: outList = new ArrayList<AttributeValue<?>>(); for (AttributeValue<?> element : list1) { if (outList.contains(element)) { continue; } outList.add((AttributeValue<?>) element); } for (AttributeValue<?> element : list2) { if (outList.contains(element)) { continue; } outList.add((AttributeValue<?>) element); } outBag = new Bag(); for (AttributeValue<?> element : outList) { outBag.add(element); } expressionResult = ExpressionResult.newBag(outBag); return expressionResult; case SUBSET: for (AttributeValue<?> element : list1) { if ( ! list2.contains(element)) { return ER_FALSE; } } return ER_TRUE; case SET_EQUALS: for (AttributeValue<?> element : list1) { if ( ! list2.contains(element)) { return ER_FALSE; } } for (AttributeValue<?> element : list2) { if ( ! list1.contains(element)) { return ER_FALSE; } } return ER_TRUE; } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Could not evaluate Set function " + operation)); }
FunctionDefinitionSet extends FunctionDefinitionBase<O, I> { @Override public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) { if (arguments == null || arguments.size() != 2) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Expected 2 arguments, got " + ((arguments == null) ? "null" : arguments.size()) )); } FunctionArgument bagArgument = arguments.get(0); ConvertedArgument<Bag> convertedBagArgument = new ConvertedArgument<Bag>(bagArgument, null, true); if ( ! convertedBagArgument.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedBagArgument.getStatus())); } Bag bag1 = convertedBagArgument.getBag(); List<AttributeValue<?>> list1 = (List<AttributeValue<?>>) bag1.getAttributeValueList(); bagArgument = arguments.get(1); convertedBagArgument = new ConvertedArgument<Bag>(bagArgument, null, true); if ( ! convertedBagArgument.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedBagArgument.getStatus())); } Bag bag2 = convertedBagArgument.getBag(); List<AttributeValue<?>> list2 = (List<AttributeValue<?>>) bag2.getAttributeValueList(); ExpressionResult expressionResult = null; Bag outBag; List<AttributeValue<?>> outList; switch (operation) { case INTERSECTION: outList = new ArrayList<AttributeValue<?>>(); for (AttributeValue<?> element : list1) { if (outList.contains(element)) { continue; } if (list2.contains(element)) { outList.add(element); } } outBag = new Bag(); for (AttributeValue<?> element : outList) { outBag.add(element); } expressionResult = ExpressionResult.newBag(outBag); return expressionResult; case AT_LEAST_ONE_MEMBER_OF: for (AttributeValue<?> element : list1) { if (list2.contains(element)) { return ER_TRUE; } } return ER_FALSE; case UNION: outList = new ArrayList<AttributeValue<?>>(); for (AttributeValue<?> element : list1) { if (outList.contains(element)) { continue; } outList.add((AttributeValue<?>) element); } for (AttributeValue<?> element : list2) { if (outList.contains(element)) { continue; } outList.add((AttributeValue<?>) element); } outBag = new Bag(); for (AttributeValue<?> element : outList) { outBag.add(element); } expressionResult = ExpressionResult.newBag(outBag); return expressionResult; case SUBSET: for (AttributeValue<?> element : list1) { if ( ! list2.contains(element)) { return ER_FALSE; } } return ER_TRUE; case SET_EQUALS: for (AttributeValue<?> element : list1) { if ( ! list2.contains(element)) { return ER_FALSE; } } for (AttributeValue<?> element : list2) { if ( ! list1.contains(element)) { return ER_FALSE; } } return ER_TRUE; } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Could not evaluate Set function " + operation)); } }
FunctionDefinitionSet extends FunctionDefinitionBase<O, I> { @Override public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) { if (arguments == null || arguments.size() != 2) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Expected 2 arguments, got " + ((arguments == null) ? "null" : arguments.size()) )); } FunctionArgument bagArgument = arguments.get(0); ConvertedArgument<Bag> convertedBagArgument = new ConvertedArgument<Bag>(bagArgument, null, true); if ( ! convertedBagArgument.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedBagArgument.getStatus())); } Bag bag1 = convertedBagArgument.getBag(); List<AttributeValue<?>> list1 = (List<AttributeValue<?>>) bag1.getAttributeValueList(); bagArgument = arguments.get(1); convertedBagArgument = new ConvertedArgument<Bag>(bagArgument, null, true); if ( ! convertedBagArgument.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedBagArgument.getStatus())); } Bag bag2 = convertedBagArgument.getBag(); List<AttributeValue<?>> list2 = (List<AttributeValue<?>>) bag2.getAttributeValueList(); ExpressionResult expressionResult = null; Bag outBag; List<AttributeValue<?>> outList; switch (operation) { case INTERSECTION: outList = new ArrayList<AttributeValue<?>>(); for (AttributeValue<?> element : list1) { if (outList.contains(element)) { continue; } if (list2.contains(element)) { outList.add(element); } } outBag = new Bag(); for (AttributeValue<?> element : outList) { outBag.add(element); } expressionResult = ExpressionResult.newBag(outBag); return expressionResult; case AT_LEAST_ONE_MEMBER_OF: for (AttributeValue<?> element : list1) { if (list2.contains(element)) { return ER_TRUE; } } return ER_FALSE; case UNION: outList = new ArrayList<AttributeValue<?>>(); for (AttributeValue<?> element : list1) { if (outList.contains(element)) { continue; } outList.add((AttributeValue<?>) element); } for (AttributeValue<?> element : list2) { if (outList.contains(element)) { continue; } outList.add((AttributeValue<?>) element); } outBag = new Bag(); for (AttributeValue<?> element : outList) { outBag.add(element); } expressionResult = ExpressionResult.newBag(outBag); return expressionResult; case SUBSET: for (AttributeValue<?> element : list1) { if ( ! list2.contains(element)) { return ER_FALSE; } } return ER_TRUE; case SET_EQUALS: for (AttributeValue<?> element : list1) { if ( ! list2.contains(element)) { return ER_FALSE; } } for (AttributeValue<?> element : list2) { if ( ! list1.contains(element)) { return ER_FALSE; } } return ER_TRUE; } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Could not evaluate Set function " + operation)); } FunctionDefinitionSet(Identifier idIn, DataType<O> dataTypeIn, DataType<I> dataTypeArgsIn, OPERATION opIn); }
FunctionDefinitionSet extends FunctionDefinitionBase<O, I> { @Override public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) { if (arguments == null || arguments.size() != 2) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Expected 2 arguments, got " + ((arguments == null) ? "null" : arguments.size()) )); } FunctionArgument bagArgument = arguments.get(0); ConvertedArgument<Bag> convertedBagArgument = new ConvertedArgument<Bag>(bagArgument, null, true); if ( ! convertedBagArgument.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedBagArgument.getStatus())); } Bag bag1 = convertedBagArgument.getBag(); List<AttributeValue<?>> list1 = (List<AttributeValue<?>>) bag1.getAttributeValueList(); bagArgument = arguments.get(1); convertedBagArgument = new ConvertedArgument<Bag>(bagArgument, null, true); if ( ! convertedBagArgument.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedBagArgument.getStatus())); } Bag bag2 = convertedBagArgument.getBag(); List<AttributeValue<?>> list2 = (List<AttributeValue<?>>) bag2.getAttributeValueList(); ExpressionResult expressionResult = null; Bag outBag; List<AttributeValue<?>> outList; switch (operation) { case INTERSECTION: outList = new ArrayList<AttributeValue<?>>(); for (AttributeValue<?> element : list1) { if (outList.contains(element)) { continue; } if (list2.contains(element)) { outList.add(element); } } outBag = new Bag(); for (AttributeValue<?> element : outList) { outBag.add(element); } expressionResult = ExpressionResult.newBag(outBag); return expressionResult; case AT_LEAST_ONE_MEMBER_OF: for (AttributeValue<?> element : list1) { if (list2.contains(element)) { return ER_TRUE; } } return ER_FALSE; case UNION: outList = new ArrayList<AttributeValue<?>>(); for (AttributeValue<?> element : list1) { if (outList.contains(element)) { continue; } outList.add((AttributeValue<?>) element); } for (AttributeValue<?> element : list2) { if (outList.contains(element)) { continue; } outList.add((AttributeValue<?>) element); } outBag = new Bag(); for (AttributeValue<?> element : outList) { outBag.add(element); } expressionResult = ExpressionResult.newBag(outBag); return expressionResult; case SUBSET: for (AttributeValue<?> element : list1) { if ( ! list2.contains(element)) { return ER_FALSE; } } return ER_TRUE; case SET_EQUALS: for (AttributeValue<?> element : list1) { if ( ! list2.contains(element)) { return ER_FALSE; } } for (AttributeValue<?> element : list2) { if ( ! list1.contains(element)) { return ER_FALSE; } } return ER_TRUE; } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Could not evaluate Set function " + operation)); } FunctionDefinitionSet(Identifier idIn, DataType<O> dataTypeIn, DataType<I> dataTypeArgsIn, OPERATION opIn); @Override ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments); }
FunctionDefinitionSet extends FunctionDefinitionBase<O, I> { @Override public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) { if (arguments == null || arguments.size() != 2) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Expected 2 arguments, got " + ((arguments == null) ? "null" : arguments.size()) )); } FunctionArgument bagArgument = arguments.get(0); ConvertedArgument<Bag> convertedBagArgument = new ConvertedArgument<Bag>(bagArgument, null, true); if ( ! convertedBagArgument.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedBagArgument.getStatus())); } Bag bag1 = convertedBagArgument.getBag(); List<AttributeValue<?>> list1 = (List<AttributeValue<?>>) bag1.getAttributeValueList(); bagArgument = arguments.get(1); convertedBagArgument = new ConvertedArgument<Bag>(bagArgument, null, true); if ( ! convertedBagArgument.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedBagArgument.getStatus())); } Bag bag2 = convertedBagArgument.getBag(); List<AttributeValue<?>> list2 = (List<AttributeValue<?>>) bag2.getAttributeValueList(); ExpressionResult expressionResult = null; Bag outBag; List<AttributeValue<?>> outList; switch (operation) { case INTERSECTION: outList = new ArrayList<AttributeValue<?>>(); for (AttributeValue<?> element : list1) { if (outList.contains(element)) { continue; } if (list2.contains(element)) { outList.add(element); } } outBag = new Bag(); for (AttributeValue<?> element : outList) { outBag.add(element); } expressionResult = ExpressionResult.newBag(outBag); return expressionResult; case AT_LEAST_ONE_MEMBER_OF: for (AttributeValue<?> element : list1) { if (list2.contains(element)) { return ER_TRUE; } } return ER_FALSE; case UNION: outList = new ArrayList<AttributeValue<?>>(); for (AttributeValue<?> element : list1) { if (outList.contains(element)) { continue; } outList.add((AttributeValue<?>) element); } for (AttributeValue<?> element : list2) { if (outList.contains(element)) { continue; } outList.add((AttributeValue<?>) element); } outBag = new Bag(); for (AttributeValue<?> element : outList) { outBag.add(element); } expressionResult = ExpressionResult.newBag(outBag); return expressionResult; case SUBSET: for (AttributeValue<?> element : list1) { if ( ! list2.contains(element)) { return ER_FALSE; } } return ER_TRUE; case SET_EQUALS: for (AttributeValue<?> element : list1) { if ( ! list2.contains(element)) { return ER_FALSE; } } for (AttributeValue<?> element : list2) { if ( ! list1.contains(element)) { return ER_FALSE; } } return ER_TRUE; } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Could not evaluate Set function " + operation)); } FunctionDefinitionSet(Identifier idIn, DataType<O> dataTypeIn, DataType<I> dataTypeArgsIn, OPERATION opIn); @Override ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments);  }