Example usage for java.util LinkedHashSet add

List of usage examples for java.util LinkedHashSet add

Introduction

In this page you can find the example usage for java.util LinkedHashSet 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:com.floragunn.searchguard.HeaderAwareJestClientFactory.java

public HeaderAwareJestHttpClient getObject() {
    final HeaderAwareJestHttpClient client = new HeaderAwareJestHttpClient();

    if (httpClientConfig != null) {
        log.debug("Creating HTTP client based on configuration");
        client.setServers(httpClientConfig.getServerList());
        final HttpClientConnectionManager connectionManager = createConnectionManager();
        client.setHttpClient(createHttpClient(connectionManager));

        // set custom gson instance
        final Gson gson = httpClientConfig.getGson();
        if (gson != null) {
            client.setGson(gson);/*from ww w .  j  a va  2s. c om*/
        }

        // set discovery (should be set after setting the httpClient on jestClient)
        if (httpClientConfig.isDiscoveryEnabled()) {
            log.info("Node Discovery Enabled...");
            final NodeChecker nodeChecker = new NodeChecker(httpClientConfig, client);
            client.setNodeChecker(nodeChecker);
            nodeChecker.startAsync();
            nodeChecker.awaitRunning();
        } else {
            log.info("Node Discovery Disabled...");
        }

        // schedule idle connection reaping if configured
        if (httpClientConfig.getMaxConnectionIdleTime() > 0) {
            log.info("Idle connection reaping enabled...");

            final IdleConnectionReaper reaper = new IdleConnectionReaper(httpClientConfig,
                    new HttpReapableConnectionManager(connectionManager));
            client.setIdleConnectionReaper(reaper);
            reaper.startAsync();
            reaper.awaitRunning();
        }

    } else {
        log.debug(
                "There is no configuration to create http client. Going to create simple client with default values");
        client.setHttpClient(HttpClients.createDefault());
        final LinkedHashSet<String> servers = new LinkedHashSet<String>();
        servers.add("http://localhost:9200");
        client.setServers(servers);
    }

    client.setAsyncClient(HttpAsyncClients.custom().setRoutePlanner(getRoutePlanner()).build());
    return client;
}

From source file:org.owasp.dependencytrack.model.RolesTest.java

@Test
@Transactional/*from   w  w w.  j a  v  a  2s.c  om*/
public void testObject() throws Exception {
    LinkedHashSet<Permissions> perms = new LinkedHashSet<>();
    Permissions p1 = new Permissions("dosomething");
    Permissions p2 = new Permissions("dosomethingelse");
    perms.add(p1);
    perms.add(p2);

    LinkedHashSet<User> users = new LinkedHashSet<>();
    User u1 = new User();
    u1.setUsername("Fred");
    User u2 = new User();
    u2.setUsername("Barney");
    users.add(u1);
    users.add(u2);

    Roles r1 = new Roles("Role 1");
    r1.setId(1);
    r1.setPerm(perms);
    r1.setUsr(users);

    Roles r2 = new Roles();
    r2.setRole("Role 2");
    r2.setId(1);
    r2.setPerm(perms);
    r2.setUsr(users);

    assertEquals(new Integer(1), r1.getId());
    assertEquals("Role 1", r1.getRole());
    assertEquals("Role 2", r2.getRole());
    assertEquals(2, r1.getPerm().size());
    assertEquals(2, r1.getUsr().size());
    assertEquals("dosomething", r1.getPerm().iterator().next().getPermissionname());
    assertEquals("Fred", r1.getUsr().iterator().next().getUsername());
}

From source file:com.persinity.ndt.dbdiff.rel.JsonTransformEntityStore.java

private Set<String> convertToStringSet(final JSONArray jsonArray) {
    final LinkedHashSet<String> res = new LinkedHashSet<>();
    for (int j = 0; j < jsonArray.length(); j++) {
        res.add(jsonArray.getString(j));
    }//from www . j  a  v a  2  s .  co  m
    return res;
}

From source file:edu.ksu.cs.a4vm.bse.Classification.java

@Override
public void onResume() {
    super.onResume();
    try {/*from   w ww.j a  v  a2  s  .  c o  m*/

        //display fields
        Util.setFields(
                SharedPrefUtil.getValue(getApplicationContext(), Constant.PREFS_CLASSIFICATION_INFO, bullKey),
                fields);
        //display toggle buttons
        Util.setToggleButtons(
                SharedPrefUtil.getValue(getApplicationContext(), Constant.PREFS_CLASSIFICATION_INFO, bullKey),
                tgBtns);

        save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (tgbtn.getCurrentTextColor() == ContextCompat.getColor(getApplicationContext(),
                        R.color.colorAccent)
                        || tgbtn1.getCurrentTextColor() == ContextCompat.getColor(getApplicationContext(),
                                R.color.colorAccent)
                        || tgbtn2.getCurrentTextColor() == ContextCompat.getColor(getApplicationContext(),
                                R.color.colorAccent)
                        || tgbtn3.getCurrentTextColor() == ContextCompat.getColor(getApplicationContext(),
                                R.color.colorAccent)) {
                    LinkedHashSet<String> data = new LinkedHashSet<String>();
                    data.add(tgbtn.getText().toString().trim() + "=" + tgbtn.getCurrentTextColor());
                    data.add(tgbtn1.getText().toString().trim() + "=" + tgbtn1.getCurrentTextColor());
                    data.add(tgbtn2.getText().toString().trim() + "=" + tgbtn2.getCurrentTextColor());
                    data.add(tgbtn3.getText().toString().trim() + "=" + tgbtn3.getCurrentTextColor());
                    data.add(comments.getHint().toString().trim() + "="
                            + comments.getText().toString().trim().replace(",", ";"));

                    //save to shared pref
                    SharedPrefUtil.saveGroup(getApplicationContext(), Constant.PREFS_CLASSIFICATION_INFO,
                            bullKey, data);

                    Intent goPrev = new Intent(getApplicationContext(), BullExam.class);
                    goPrev.putExtra("bullKey", bullKey);
                    startActivity(goPrev);

                    //display fields
                    /*Util.setFields(SharedPrefUtil.getValue(getApplicationContext(), Constant.PREFS_CLASSIFICATION_INFO,
                        bullKey), fields);
                    //display toggle buttons
                    Util.setToggleButtons(SharedPrefUtil.getValue(getApplicationContext(), Constant.PREFS_CLASSIFICATION_INFO,
                        bullKey), tgBtns);*/

                    Toast.makeText(getApplicationContext(), "Saved!", Toast.LENGTH_SHORT).show();
                }

            }
        });
    } catch (Exception e) {
        Toast.makeText(getApplicationContext(), "Invalid data entered", Toast.LENGTH_SHORT).show();
    }
}

From source file:com.geewhiz.pacify.filter.PacifyVelocityFilter.java

@Override
public LinkedHashSet<Defect> filter(PFile pFile, Map<String, String> propertyValues) {
    LinkedHashSet<Defect> defects = new LinkedHashSet<Defect>();

    if (!BEGIN_TOKEN.equals(pFile.getBeginToken())) {
        defects.add(new WrongTokenDefinedDefect(pFile, "If you use the PacifyVelocityFilter class, only \""
                + BEGIN_TOKEN + "\" is allowed as start token."));
    }/*from w  ww . j  a v  a2 s  .  c o  m*/

    if (!END_TOKEN.equals(pFile.getEndToken())) {
        defects.add(new WrongTokenDefinedDefect(pFile, "If you use the PacifyVelocityFilter class, only \""
                + END_TOKEN + "\" is allowed as end token."));
    }

    if (!defects.isEmpty()) {
        return defects;
    }

    File fileToFilter = pFile.getFile();
    File tmpFile = FileUtils.createEmptyFileWithSamePermissions(fileToFilter);

    Template template = getTemplate(fileToFilter, pFile.getEncoding());
    Context context = getContext(propertyValues, fileToFilter);

    try {
        FileWriterWithEncoding fw = new FileWriterWithEncoding(tmpFile, pFile.getEncoding());
        template.merge(context, fw);
        fw.close();
        if (!fileToFilter.delete()) {
            throw new RuntimeException("Couldn't delete file [" + fileToFilter.getPath() + "]... Aborting!");
        }
        if (!tmpFile.renameTo(fileToFilter)) {
            throw new RuntimeException("Couldn't rename filtered file from [" + tmpFile.getPath() + "] to ["
                    + fileToFilter.getPath() + "]... Aborting!");
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    return defects;
}

From source file:net.sf.taverna.t2.activities.apiconsumer.ApiConsumerActivityHealthChecker.java

public VisitReport visit(ApiConsumerActivity subject, List<Object> ancestors) {
    // Check if we can find the jar containing the apiconsumer's class
    Processor p = (Processor) VisitReport.findAncestor(ancestors, Processor.class);
    if (p == null) {
        return null;
    }/*from   w ww  . j  a va2s .  co  m*/

    List<VisitReport> reports = new ArrayList<VisitReport>();
    JsonNode configuration = subject.getConfiguration();

    /*      String className = configuration.getClassName();
          try {
             // Try to load the API consumer's class
             ClassLoader classLoader = subject.getClassLoader();
             classLoader.loadClass(className);
             reports.add(new VisitReport(HealthCheck.getInstance(), p, "Class found", HealthCheck.NO_PROBLEM, Status.OK));
             // All is fine
          } catch (ClassNotFoundException e) {
             VisitReport vr = new VisitReport(HealthCheck.getInstance(), p, "Class missing", HealthCheck.MISSING_CLASS, Status.SEVERE);
             vr.setProperty("className", className);
    reports.add(vr);
          }
    */
    // Check if we can find all the API consumer's dependencies
    LinkedHashSet<String> localDependencies = new LinkedHashSet<>();
    for (JsonNode localDependency : configuration.get("localDependency")) {
        localDependencies.add(localDependency.textValue());
    }

    if (!localDependencies.isEmpty()) {
        String[] jarArray = subject.libDir.list(new FileExtFilter(".jar"));
        if (jarArray != null) {
            List<String> jarFiles = Arrays.asList(jarArray); // URLs of all jars found in the lib directory
            for (String jar : localDependencies) {
                if (jarFiles.contains(jar)) {
                    localDependencies.remove(jar);
                }
            }
            if (localDependencies.isEmpty()) { // all dependencies found
                reports.add(new VisitReport(HealthCheck.getInstance(), p, "Dependencies found",
                        HealthCheck.NO_PROBLEM, Status.OK));
            } else {
                VisitReport vr = new VisitReport(HealthCheck.getInstance(), p, "Dependencies missing",
                        HealthCheck.MISSING_DEPENDENCY, Status.SEVERE);
                vr.setProperty("dependencies", localDependencies);
                vr.setProperty("directory", subject.libDir);
                reports.add(vr);
            }
        }
    }
    Status status = VisitReport.getWorstStatus(reports);
    VisitReport report = new VisitReport(HealthCheck.getInstance(), p, "API Consumer report",
            HealthCheck.NO_PROBLEM, status, reports);

    return report;
}

From source file:cc.kave.commons.pointsto.evaluation.ContextSampler.java

public List<Context> sample(Path contextsDirectory, int number) throws IOException {
    Map<ZipArchive, Integer> registry = buildRegistry(contextsDirectory);

    try {/*from w ww . j a va  2 s.  c  o m*/
        int totalNumContexts = registry.values().stream().mapToInt(Integer::intValue).sum();
        LinkedHashSet<Integer> contextIndices = new LinkedHashSet<>();
        if (totalNumContexts < number) {
            for (int i = 0; i < totalNumContexts; ++i) {
                contextIndices.add(i);
            }
        } else {
            for (int i = 0; i < number; ++i) {
                int index;
                do {
                    index = rndGenerator.nextInt(totalNumContexts);
                } while (contextIndices.contains(index));
                contextIndices.add(index);
            }
        }

        List<Context> contexts = new ArrayList<>(number);
        for (Integer index : contextIndices) {
            Context ctxt = getContext(registry, index);
            if (ctxt == null) {
                ctxt = new Context();
            }
            contexts.add(ctxt);
        }

        return contexts;
    } finally {
        closeRegistry(registry);
    }
}

From source file:com.petalmd.armor.HeaderAwareJestClientFactory.java

public HeaderAwareJestHttpClient getObject() {
    final HeaderAwareJestHttpClient client = new HeaderAwareJestHttpClient();

    if (httpClientConfig != null) {
        log.debug("Creating HTTP client based on configuration");
        client.setServers(httpClientConfig.getServerList());
        final HttpClientConnectionManager connectionManager = createConnectionManager();
        client.setHttpClient(createHttpClient(connectionManager));

        // set custom gson instance
        final Gson gson = httpClientConfig.getGson();
        if (gson != null) {
            client.setGson(gson);/*from  w  ww.  j  a va 2 s .  c  o  m*/
        }

        // set discovery (should be set after setting the httpClient on jestClient)
        if (httpClientConfig.isDiscoveryEnabled()) {
            log.info("Node Discovery Enabled...");
            final NodeChecker nodeChecker = new NodeChecker(client, httpClientConfig);
            client.setNodeChecker(nodeChecker);
            nodeChecker.startAsync();
            nodeChecker.awaitRunning();
        } else {
            log.info("Node Discovery Disabled...");
        }

        // schedule idle connection reaping if configured
        if (httpClientConfig.getMaxConnectionIdleTime() > 0) {
            log.info("Idle connection reaping enabled...");

            final IdleConnectionReaper reaper = new IdleConnectionReaper(httpClientConfig,
                    new HttpReapableConnectionManager(connectionManager, getAsyncConnectionManager()));
            client.setIdleConnectionReaper(reaper);
            reaper.startAsync();
            reaper.awaitRunning();
        }

    } else {
        log.debug(
                "There is no configuration to create http client. Going to create simple client with default values");
        client.setHttpClient(HttpClients.createDefault());
        final LinkedHashSet<String> servers = new LinkedHashSet<String>();
        servers.add("http://localhost:9200");
        client.setServers(servers);
    }

    client.setAsyncClient(HttpAsyncClients.custom().setRoutePlanner(getRoutePlanner()).build());
    return client;
}

From source file:org.alfresco.repo.forms.processor.node.NodeFormProcessor.java

@SuppressWarnings("unchecked")
private void addAssocToMap(QName name, NodeRef target, HashMap<QName, Serializable> assocs) {
    Serializable value = assocs.get(name);
    if (value == null) {
        LinkedHashSet<NodeRef> values = new LinkedHashSet<NodeRef>();
        values.add(target);
        assocs.put(name, values);//from   w  ww.j  av  a 2 s. c  o  m
    } else {
        if (value instanceof Set<?>) {
            ((Set<NodeRef>) value).add(target);
        }
    }
}

From source file:org.osaf.cosmo.atom.provider.DetachedItemCollectionAdapter.java

private NoteItem detachOccurrence(NoteItem master, NoteItem copy, NoteItem occurrence) {

    ThisAndFutureHelper tafHelper = new ThisAndFutureHelper();
    LinkedHashSet<ContentItem> updates = new LinkedHashSet<ContentItem>();

    // need to update master, create new master
    updates.add(master);
    updates.add(copy);//w ww. jav a  2  s  .c  o m

    // get all modifications to remove/add
    updates.addAll(tafHelper.breakRecurringEvent(master, copy, occurrence));

    // This service call will update/remove/create items in one transaction
    // Any new items will be added to all specified parents.
    getContentService().updateContentItems(master.getParents(), updates);

    return copy;
}