public List<String> write() {
   List<String> lines = new ArrayList<String>();
   StringBuilder out = new StringBuilder();
   for (Entry<String, Attribute> attribute : attributes.entrySet()) {
     out.append(attribute.getKey()).append(": ");
     Attribute attributeValue = attribute.getValue();
     if (attributeValue.size() > 1) {
       lines.add(out.toString());
       out.setLength(0);
       for (int i = 0; i < attributeValue.size(); i++) {
         Value value = attributeValue.get(i);
         out.append(" ");
         value.toString(out);
         if (i + 1 < attributeValue.size()) {
           out.append(",");
         }
         lines.add(out.toString());
         out.setLength(0);
       }
     } else {
       attributeValue.toString("", out);
       lines.add(out.toString());
       out.setLength(0);
     }
   }
   return lines;
 }
Exemple #2
0
 /**
  * Returns a string representation of the list of attributes. ' name1="value1" name2="value2" ...'
  */
 public String toString() {
   StringBuffer buf = new StringBuffer();
   for (Attribute attr : list) {
     buf.append(' ');
     buf.append(attr.toString());
   }
   return buf.toString();
 }
 @Test
 public void testToString() {
   final Constant constant = Constant.create("emptyset");
   Assert.assertEquals("§emptyset", constant.toString());
   final Variable variable = Variable.create("var");
   Assert.assertEquals("$var", variable.toString());
   final Function function = Function.create("add", constant, variable);
   Assert.assertEquals("\\add(§emptyset,$var)", function.toString());
   final Attribute attribute = Attribute.create("element", function, constant, variable);
   Assert.assertEquals("%element(\\add(§emptyset,$var),§emptyset,$var)", attribute.toString());
   final Quantifier ex = Quantifier.create("exists", variable, attribute);
   Assert.assertEquals("*exists$var%element(\\add(§emptyset,$var),§emptyset,$var)", ex.toString());
   final Quantifier all = Quantifier.create("forall", variable, attribute);
   Assert.assertEquals(
       "*forall$var%element(\\add(§emptyset,$var),§emptyset,$var)", all.toString());
   final LogicalConnective connective = LogicalConnective.create("and", ex, all);
   Assert.assertEquals(
       "&and(*exists$var%element(\\add(§emptyset,$var),§emptyset,$var),*forall$var%element(\\add(§emptyset,$var),§emptyset,$var))",
       connective.toString());
 }