Example usage for java.util Set addAll

List of usage examples for java.util Set addAll

Introduction

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

Prototype

boolean addAll(Collection<? extends E> c);

Source Link

Document

Adds all of the elements in the specified collection to this set if they're not already present (optional operation).

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Set set1 = new HashSet();
    Set set2 = new HashSet();

    set1.addAll(set2);

}

From source file:de.tudarmstadt.ukp.dkpro.keyphrases.wikipediafilter.filter.util.FileFilter.java

public static void main(String[] args) throws IOException {
    Set<String> articles = new HashSet<String>();
    articles.addAll(FileUtils.readLines(new File("target/wikipedia/articles.txt")));

    BufferedWriter writer = new BufferedWriter(new FileWriter(new File("target/passwords.txt.filtered")));
    for (String line : FileUtils.readLines(new File("target/passwords.txt"))) {
        if (articles.contains(line.split("\t")[0].toLowerCase())) {
            writer.write(line);/*  ww  w .j  a  v a2 s.c o  m*/
            writer.newLine();
        }
        writer.close();
    }
}

From source file:MainClass.java

public static void main(String[] args) {

    // Create two sets.
    Set s1 = new HashSet();
    s1.add("A");//  ww w .  j  av a  2  s. c  o m
    s1.add("B");
    s1.add("C");

    Set s2 = new HashSet();
    s2.add("A");
    s2.add("B");

    Set union = new TreeSet(s1);
    union.addAll(s2); // now contains the union

    print("union", union);

    Set intersect = new TreeSet(s1);
    intersect.retainAll(s2);

    print("intersection", intersect);

}

From source file:Employee.java

public static void main(String args[]) {
    Employee emps[] = { new Employee("Finance", "A"), new Employee("Finance", "B"),
            new Employee("Finance", "C"), new Employee("Engineering", "D"), new Employee("Engineering", "E"),
            new Employee("Engineering", "F"), new Employee("Sales", "G"), new Employee("Sales", "H"),
            new Employee("Support", "I"), };
    Set set = new TreeSet(new EmpComparator());
    set.addAll(Arrays.asList(emps));
    System.out.println(set);/*  w  ww. j  a  va  2  s. c o m*/
}

From source file:MainClass.java

public static void main(String[] a) {
    String elements[] = { "A", "B", "C", "D", "E" };
    Set set = new HashSet(Arrays.asList(elements));

    elements = new String[] { "E", "F" };

    set.addAll(Arrays.asList(elements));

    System.out.println(set);//  www  . ja va 2 s  . c  o  m
}

From source file:SetStuff.java

public static void main(String[] args) {

    // Create two sets.
    Set s1 = new HashSet();
    s1.add("Ian Darwin");
    s1.add("Bill Dooley");
    s1.add("Jesse James");

    Set s2 = new HashSet();
    s2.add("Ian Darwin");
    s2.add("Doolin' Dalton");

    Set union = new TreeSet(s1);
    union.addAll(s2); // now contains the union

    print("union", union);

    Set intersect = new TreeSet(s1);
    intersect.retainAll(s2);//from  w w w .  jav a 2 s  . c o  m

    print("intersection", intersect);

}

From source file:MainClass.java

public static void main(String[] a) {
    String elements[] = { "A", "B", "C", "D", "E" };
    Set set = new HashSet(Arrays.asList(elements));

    elements = new String[] { "E", "F" };

    set.addAll(Arrays.asList(elements));

    System.out.println(set);/*from   w w w  .  java 2 s.co m*/

    set.clear();

    System.out.println(set);
}

From source file:Main.java

public static void main(String[] a) {
    String elements[] = { "A", "B", "C", "D", "E" };
    Set<String> set = new HashSet<String>(Arrays.asList(elements));

    elements = new String[] { "E", "F" };

    set.addAll(Arrays.asList(elements));

    System.out.println(set);/*w  ww. j  a v a  2s .  co  m*/

    set.clear();

    System.out.println(set);
}

From source file:Company.java

public static void main(String args[]) {
    Employee emps[] = { new Employee("Finance", "Degree, Debbie"), new Employee("Finance", "Grade, Geri"),
            new Employee("Finance", "Extent, Ester"), new Employee("Engineering", "Measure, Mary"),
            new Employee("Engineering", "Amount, Anastasia"), new Employee("Engineering", "Ratio, Ringo"),
            new Employee("Sales", "Stint, Sarah"), new Employee("Sales", "Pitch, Paula"),
            new Employee("Support", "Rate, Rhoda"), };
    Set set = new TreeSet(Arrays.asList(emps));
    System.out.println(set);/*from   w  ww.j a  v  a2 s.co  m*/
    Set set2 = new TreeSet(Collections.reverseOrder());
    set2.addAll(Arrays.asList(emps));
    System.out.println(set2);

    Set set3 = new TreeSet(new EmpComparator());
    for (int i = 0, n = emps.length; i < n; i++) {
        set3.add(emps[i]);
    }
    System.out.println(set3);
}

From source file:com.khartec.waltz.jobs.sample.FlowGenerator.java

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);

    AuthoritativeSourceDao authSourceDao = ctx.getBean(AuthoritativeSourceDao.class);
    ApplicationService applicationDao = ctx.getBean(ApplicationService.class);
    DataTypeService dataTypesDao = ctx.getBean(DataTypeService.class);
    DataFlowService dataFlowDao = ctx.getBean(DataFlowService.class);
    OrganisationalUnitService orgUnitDao = ctx.getBean(OrganisationalUnitService.class);
    DataSource dataSource = ctx.getBean(DataSource.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);

    List<AuthoritativeSource> authSources = authSourceDao.findByEntityKind(EntityKind.ORG_UNIT);
    List<String> dataTypes = dataTypesDao.getAll().stream().map(dt -> dt.code()).collect(toList());
    List<Application> apps = applicationDao.findAll();
    List<OrganisationalUnit> orgUnits = orgUnitDao.findAll();

    Set<DataFlow> expectedFlows = authSources.stream().flatMap(a -> {
        long orgUnitId = a.parentReference().id();

        return IntStream.range(0, rnd.nextInt(40))
                .mapToObj(i -> ImmutableDataFlow.builder().dataType(a.dataType())
                        .source(a.applicationReference()).target(randomAppPick(apps, orgUnitId)).build());
    }).collect(Collectors.toSet());

    Set<DataFlow> probableFlows = authSources.stream().flatMap(a -> IntStream.range(0, rnd.nextInt(30))
            .mapToObj(i -> ImmutableDataFlow.builder().dataType(a.dataType()).source(a.applicationReference())
                    .target(randomAppPick(apps, randomPick(orgUnits).id().get())).build()))
            .collect(Collectors.toSet());

    Set<DataFlow> randomFlows = apps.stream()
            .map(a -> ImmutableDataFlow.builder().source(a.toEntityReference()))
            .map(b -> b.target(randomAppPick(apps, randomPick(orgUnits).id().get())))
            .map(b -> b.dataType(randomPick(dataTypes)).build()).collect(Collectors.toSet());

    dsl.deleteFrom(DATA_FLOW).execute();

    Set<DataFlow> all = new HashSet<>();
    all.addAll(randomFlows);
    all.addAll(expectedFlows);//from  www . jav  a  2 s.c o m
    all.addAll(probableFlows);

    dataFlowDao.addFlows(new ArrayList<>(all));

    System.out.println("Done");

}