Package fi.luomus.commons.containers

Examples of fi.luomus.commons.containers.SelectionImple


  }
 
  @Override
  public Selection getAsSelection(String resourcename, int countOfFields) throws Exception {
    Document document = getAsDocument(resourcename);
    SelectionImple selection = new SelectionImple(resourcename);
    for (Node resource : document.getRootNode()) {
      String id = resource.getNode("id").getContents();
      id = Utils.toHTMLEntities(id);
      StringBuilder desc = new StringBuilder();
      int i = 0;
      for (Node resourceChild : resource) {
        if (i++ > countOfFields) break;
        if (resourceChild.getName().equals("id")) continue;
        String contents = resourceChild.getContents();
        if (contents == null) continue;
        desc.append(contents).append(" ");
      }
      Utils.removeLastChar(desc);
      selection.addOption(new SelectionOptionImple(id, desc.toString()));
    }
    return selection;
  }
View Full Code Here


  }
 
  @Override
  public Selection getAsSelection(String resourcename, int ... fieldIndexes) throws Exception {
    Document document = getAsDocument(resourcename);
    SelectionImple selection = new SelectionImple(resourcename);
    for (Node resource : document.getRootNode()) {
      String id = resource.getNode("id").getContents();
      StringBuilder desc = new StringBuilder();
      List<Node> childNodes = resource.getChildNodes();
      for (int index : fieldIndexes) {
        Node resourceChild = childNodes.get(index);
        String contents = resourceChild.getContents();
        if (contents == null) continue;
        desc.append(contents).append(", ");
      }
      Utils.removeLastChar(desc);
      Utils.removeLastChar(desc);
      selection.addOption(new SelectionOptionImple(id, desc.toString().trim()));
    }
    return selection;
  }
View Full Code Here

      assertEquals("VALUE", o.getValue());
      assertEquals("description", o.getText());
    }

    public void test___selections() {
      Selection s = new SelectionImple("PESA.puulaji");
      //assertEquals("pesa.puulaji", s.getName());
      try {
        s.get("a");
        fail("Should throw exception: does not contain value");
      } catch (IllegalArgumentException e) {
        assertEquals("Selection pesa.puulaji does not define value 'a'.", e.getMessage());
      }
    }
View Full Code Here

        assertEquals("Selection pesa.puulaji does not define value 'a'.", e.getMessage());
      }
    }

    public void test__adding_option() {
      SelectionImple s = new SelectionImple("name");
      s.addOption(new SelectionOptionImple("value", "descripTION"));
      assertEquals("VALUE", s.getOptions().iterator().next().getValue());
      assertEquals("descripTION", s.getOptions().iterator().next().getText());
    }
View Full Code Here

      assertEquals("VALUE", s.getOptions().iterator().next().getValue());
      assertEquals("descripTION", s.getOptions().iterator().next().getText());
    }

    public void test__adding_option_with_existing_value() {
      SelectionImple s = new SelectionImple("my-selection");
      s.addOption(new SelectionOptionImple("myvalue", "descripTION"));
      try {
        s.addOption(new SelectionOptionImple("myvalue", "whatever"));
        fail("Should throw exception");
      } catch (IllegalStateException e) {
        assertEquals("Selection my-selection already contains value MYVALUE" , e.getMessage());
      }
    }
View Full Code Here

        assertEquals("Selection my-selection already contains value MYVALUE" , e.getMessage());
      }
    }
   
    public void test__it_maintais_correct_order() {
      SelectionImple s = new SelectionImple("name");
      s.addOption(new SelectionOptionImple("a", "A"));
      s.addOption(new SelectionOptionImple("b", "B"));
      s.addOption(new SelectionOptionImple("c", "C"));
      s.addOption(new SelectionOptionImple("d", "D"));
      s.addOption(new SelectionOptionImple("e", "E"));
      s.addOption(new SelectionOptionImple("f", "F"));
      s.addOption(new SelectionOptionImple("g", "G"));
      s.addOption(new SelectionOptionImple("h", "H"));
      String descriptions = "";
      for (SelectionOption o : s) {
        descriptions += o.getText();
      }
      assertEquals("ABCDEFGH", descriptions);
View Full Code Here

      }
      assertEquals("ABCDEFGH", descriptions);
    }

    public void test___containsValue() {
      SelectionImple s = new SelectionImple("name");
      s.addOption(new SelectionOptionImple("a", "A"));
      Selection selection = s;
      assertTrue("Should contain this option", selection.containsOption("A"));
      assertTrue("Should contain this option", selection.containsOption("a"));
      assertFalse("Should NOT contain this option", selection.containsOption("b"));
    }
View Full Code Here

//      s.addOption(new SelectionOptionImple("a", "A <> \" ' "));
//      assertEquals("A <> \" ' ", s.get("A"));
//    }
   
    public void test___size() {
      SelectionImple s = new SelectionImple("name");
      s.addOption(new SelectionOptionImple("A", "A")); // 1
      s.addOption(new SelectionOptionImple("B", "B")); // 2
      assertEquals(2, s.getSize());
    }
View Full Code Here

      s.addOption(new SelectionOptionImple("B", "B")); // 2
      assertEquals(2, s.getSize());
    }
   
    public void test___size_2() {
      SelectionImple s = new SelectionImple("name");
      s.addOption(new SelectionOptionImple("A", "A", "Group 1")); // 2
      s.addOption(new SelectionOptionImple("B", "B", "Group 1")); // 3
      s.addOption(new SelectionOptionImple("C", "C", "Group 2")); // 5
      assertEquals(5, s.getSize());
    }
View Full Code Here

      s.addOption(new SelectionOptionImple("C", "C", "Group 2")); // 5
      assertEquals(5, s.getSize());
    }
   
    public void test___size_3() {
      SelectionImple s = new SelectionImple("name");
      s.addOption(new SelectionOptionImple("A", "A", "")); // 1
      s.addOption(new SelectionOptionImple("B", "B", "")); // 2
      s.addOption(new SelectionOptionImple("C", "C", "Group 1")); // 4
      s.addOption(new SelectionOptionImple("D", "D", "Group 1")); // 5
      s.addOption(new SelectionOptionImple("E", "E", "")); // 6
      s.addOption(new SelectionOptionImple("F", "F", "")); // 7
      s.addOption(new SelectionOptionImple("G", "G", "Group 2")); // 9
      assertEquals(9, s.getSize());
    }
View Full Code Here

TOP

Related Classes of fi.luomus.commons.containers.SelectionImple

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.