Example usage for java.util Set add

List of usage examples for java.util Set add

Introduction

In this page you can find the example usage for java.util Set add.

Prototype

boolean add(E e);

Source Link

Document

Adds the specified element to this set if it is not already present (optional operation).

Usage

From source file:Main.java

public static void main(String[] args) throws java.lang.Exception {
    List<Person> people = new ArrayList<Person>();
    people.add(new Person("J", "S"));
    people.add(new Person("J", "S"));
    people.add(new Person("J", "F"));
    people.add(new Person("J", "W"));
    people.add(new Person("J", "B"));
    Set<Object> seen = new HashSet<Object>();
    for (Person p : people) {

        Wrap wrap = new Wrap(p);
        if (seen.add(wrap)) {
            System.out.println(p + " is new");
        } else {// w  w w . ja  v  a 2 s. c o m
            System.out.println(p + " is a duplicate");
        }
    }
}

From source file:Main.java

public static void main(String args[]) {
    Set set = new HashSet();
    Set set2 = new HashSet();
    StringBuffer buff1 = new StringBuffer("Irish Setter");
    StringBuffer buff2 = new StringBuffer("Irish Setter");
    set.add(buff1);
    set2.add(buff2);//from   w ww  .j av a  2s.  c  o  m
    System.out.println(set.addAll(set2));
    System.out.println(set.addAll(set));
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.parse(new File("Table.xml"));

    XPathFactory xFactory = XPathFactory.newInstance();
    XPath path = xFactory.newXPath();
    XPathExpression exp = path.compile("/tables/table");
    NodeList nlTables = (NodeList) exp.evaluate(doc, XPathConstants.NODESET);
    for (int tblIndex = 0; tblIndex < nlTables.getLength(); tblIndex++) {
        Node table = nlTables.item(tblIndex);
        Node nAtt = table.getAttributes().getNamedItem("title");
        System.out.println(nAtt.getTextContent());
        exp = path.compile("headings/heading");
        NodeList nlHeaders = (NodeList) exp.evaluate(table, XPathConstants.NODESET);
        Set<String> headers = new HashSet<String>(25);
        for (int index = 0; index < nlHeaders.getLength(); index++) {
            headers.add(nlHeaders.item(index).getTextContent().trim());
        }// w w  w  .j a  v  a2  s.  c  om
        for (String header : headers) {
            System.out.println(header);
        }
        exp = path.compile("tablebody/tablerow");
        NodeList nlRows = (NodeList) exp.evaluate(table, XPathConstants.NODESET);
        for (int index = 0; index < nlRows.getLength(); index++) {
            Node rowNode = nlRows.item(index);
            exp = path.compile("tablecell/item");
            NodeList nlValues = (NodeList) exp.evaluate(rowNode, XPathConstants.NODESET);
            List<String> values = new ArrayList<String>(25);
            for (int valueIndex = 0; valueIndex < nlValues.getLength(); valueIndex++) {
                values.add(nlValues.item(valueIndex).getTextContent().trim());
            }
            for (String value : values) {
                System.out.println(value);
            }
        }
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    Set<AWTKeyStroke> set = new HashSet<AWTKeyStroke>(KeyboardFocusManager.getCurrentKeyboardFocusManager()
            .getDefaultFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));

    set.add(KeyStroke.getKeyStroke("F2"));
    KeyboardFocusManager.getCurrentKeyboardFocusManager()
            .setDefaultFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, set);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Set<AWTKeyStroke> set = new HashSet<AWTKeyStroke>(KeyboardFocusManager.getCurrentKeyboardFocusManager()
            .getDefaultFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));

    set.add(KeyStroke.getKeyStroke("F3"));
    KeyboardFocusManager.getCurrentKeyboardFocusManager()
            .setDefaultFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, set);

}

From source file:ItemSet.java

public static void main(String args[]) {
    String names[] = { "Item 1", "Item 2", "Item 3" };
    Set moons = new HashSet();
    int namesLen = names.length;
    int index;//  w  w w. ja  va2s.  c  o m
    for (int i = 0; i < 100; i++) {
        index = (int) (Math.random() * namesLen);
        moons.add(names[index]);
    }
    Iterator it = moons.iterator();
    while (it.hasNext()) {
        System.out.println(it.next());
    }
    System.out.println("---");
    Set orderedMoons = new TreeSet(moons);
    it = orderedMoons.iterator();
    while (it.hasNext()) {
        System.out.println(it.next());
    }
}

From source file:org.jaqpot.core.elastic.ElasticSearchWriter.java

License:asdf

public static void main(String... args) throws IOException {
    User u = UserBuilder.builder("jack.sparrow").setHashedPassword(UUID.randomUUID().toString())
            .setMail("jack.sparrow@gmail.com").setMaxBibTeX(17680).setMaxFeatures(12678).setMaxModels(9999)
            .setName("Jack Sparrow").setMaxSubstances(1000).setMaxWeeklyPublishedFeatures(345)
            .setMaxWeeklyPublishedModels(67).setMaxWeeklyPublishedSubstances(5).setMaxParallelTasks(10).build();

    //u.setId(null);

    BibTeX b = BibTeXBuilder.builder("WhaTevEr14").setAbstract("asdf").setAddress("sdfsdfsd")
            .setAnnotation("slkfsdlf").setAuthor("a").setBibType(BibTeX.BibTYPE.Article).setBookTitle("t6hdth")
            .setChapter("uthjsdfbkjs").setCopyright("sdfsdf").setCrossref("other").setEdition("234234")
            .setEditor("me").setISBN("23434234").setISSN("10010231230").setJournal("haha").setKey("lalala")
            .setKeywords("This is a set of keywords").setNumber("1").setPages("101-123")
            .setSeries("Some series").setTitle("Lololo").setURL("http://some.url.ch/").setVolume("100")
            .setYear("2010").build();

    ROG rog = new ROG(false);
    Model m = rog.nextModel();/*from w w w. j ava 2 s  .  c  o  m*/
    m = new ModelMetaStripper(m).strip();

    Feature f = new Feature();
    f.setId("456");
    Set<String> ontClasses = new HashSet<>();
    ontClasses.add("ot:Feature");
    ontClasses.add("ot:NumericFeature");
    f.setOntologicalClasses(ontClasses);
    f.setMeta(MetaInfoBuilder.builder().addComments("this is a comment", "and a second one")
            .addTitles("My first feature", "a nice feature").addSubjects("feature of the day").build());
    f.setUnits("mJ");

    ElasticSearchWriter writer = new ElasticSearchWriter(b);
    InetSocketTransportAddress addrOpenTox = new InetSocketTransportAddress("147.102.82.32", 49101);
    InetSocketTransportAddress addrLocal = new InetSocketTransportAddress("localhost", 9300);
    writer.client = new TransportClient()
            //.addTransportAddress(addrLocal)
            .addTransportAddress(addrOpenTox);
    ObjectMapper om = new ObjectMapper();
    om.enable(SerializationFeature.INDENT_OUTPUT);
    writer.om = om;
    System.out.println("http://147.102.82.32:49234/jaqpot/"
            + XmlNameExtractor.extractName(writer.entity.getClass()) + "/" + writer.index());
}

From source file:FindDupsAndUnique.java

public static void main(String args[]) {
    Set uniques = new HashSet();
    Set dups = new HashSet();
    String[] values = new String[] { "java", "java2", "java2s", "javas", "java" };
    for (int i = 0; i < values.length; i++)
        if (!uniques.add(values[i]))
            dups.add(values[i]);/*from  w w  w .  j  ava2s.c om*/

    uniques.removeAll(dups); // Destructive set-difference

    System.out.println("Unique words:    " + uniques);
    System.out.println("Duplicate words: " + dups);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame aWindow = new JFrame("This is a Border Layout");
    aWindow.setBounds(30, 30, 300, 300);
    aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel p = new JPanel();

    p.add(new JTextField(10));
    p.add(new JTextField(10));
    p.add(new JTextField(10));
    p.add(new JTextField(10));
    p.add(new JTextField(10));
    p.add(new JTextField(10));

    Set<AWTKeyStroke> set = p.getFocusTraversalKeys(KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS);
    //set = new HashSet(set);
    KeyStroke up = KeyStroke.getKeyStroke("A");
    set.add(up);
    System.out.println(set);/* ww w  . j av  a 2 s  .  c om*/
    p.setFocusTraversalKeys(KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, set);
    aWindow.add(p);
    aWindow.setVisible(true);
}

From source file:KeyboardFocusManagerDemo.java

public static void main(String[] args) {
    JFrame aWindow = new JFrame("This is a Border Layout");
    aWindow.setBounds(30, 30, 300, 300); // Size
    aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel p = new JPanel();

    p.add(new JTextField(10));
    p.add(new JTextField(10));
    p.add(new JTextField(10));
    p.add(new JTextField(10));
    p.add(new JTextField(10));
    p.add(new JTextField(10));

    Set<AWTKeyStroke> set = p.getFocusTraversalKeys(KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS);
    set = new HashSet(set);
    KeyStroke up = KeyStroke.getKeyStroke("A");
    set.add(up);
    System.out.println(set);/* w  w  w .j  a v  a2  s  .  c  om*/

    p.setFocusTraversalKeys(KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, set);

    aWindow.add(p);

    aWindow.setVisible(true); // Display the window
}