DualInputSemanticProperties implements SemanticProperties { public void addForwardedField(int input, int sourceField, int targetField) { Map<Integer, FieldSet> fieldMapping; if (input != 0 && input != 1) { throw new IndexOutOfBoundsException(); } else if (input == 0) { fieldMapping = this.fieldMapping1; } else { fieldMapping = this.fieldMapping2; } if(isTargetFieldPresent(targetField, fieldMapping)) { throw new InvalidSemanticAnnotationException("Target field "+targetField+" was added twice to input "+input); } FieldSet targetFields = fieldMapping.get(sourceField); if (targetFields != null) { fieldMapping.put(sourceField, targetFields.addField(targetField)); } else { fieldMapping.put(sourceField, new FieldSet(targetField)); } } DualInputSemanticProperties(); @Override FieldSet getForwardingTargetFields(int input, int sourceField); @Override int getForwardingSourceField(int input, int targetField); @Override FieldSet getReadFields(int input); void addForwardedField(int input, int sourceField, int targetField); void addReadFields(int input, FieldSet readFields); @Override String toString();  }
@Test(expected = SemanticProperties.InvalidSemanticAnnotationException.class) public void testAddForwardedFieldsTargetTwice1() { DualInputSemanticProperties sp = new DualInputSemanticProperties(); sp.addForwardedField(0, 0, 2); sp.addForwardedField(0, 1, 2); }
@Test(expected = SemanticProperties.InvalidSemanticAnnotationException.class) public void testAddForwardedFieldsTargetTwice2() { DualInputSemanticProperties sp = new DualInputSemanticProperties(); sp.addForwardedField(1, 0, 2); sp.addForwardedField(1, 1, 2); }