List of usage examples for java.util LinkedHashSet add
boolean add(E e);
From source file:net.sf.taverna.t2.activities.beanshell.BeanshellActivityHealthChecker.java
public VisitReport visit(BeanshellActivity activity, List<Object> ancestors) { Object subject = (Processor) VisitReport.findAncestor(ancestors, Processor.class); if (subject == null) { // Fall back to using the activity itself as the subject of the reports subject = activity;/*from ww w .j a va 2s .c o m*/ } List<VisitReport> reports = new ArrayList<VisitReport>(); String script = activity.getConfiguration().get("script").textValue(); if (!script.trim().endsWith(";")) { /** Missing ; on last line is not allowed by Parser, * but is allowed by Interpreter.eval() used at runtime */ script = script + ";"; } Parser parser = new Parser(new StringReader(script)); try { while (!parser.Line()) ; reports.add(new VisitReport(HealthCheck.getInstance(), subject, "Script OK", HealthCheck.NO_PROBLEM, Status.OK)); } catch (ParseException e) { VisitReport report = new VisitReport(HealthCheck.getInstance(), subject, e.getMessage(), HealthCheck.INVALID_SCRIPT, Status.SEVERE); report.setProperty("exception", e); reports.add(report); } // Check if we can find all the Beanshell's dependencies if (activity.getConfiguration().has("localDependency")) { LinkedHashSet<String> localDependencies = new LinkedHashSet<>(); for (JsonNode localDependency : activity.getConfiguration().get("localDependency")) { localDependencies.add(localDependency.textValue()); } String[] jarArray = activity.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(), subject, "Beanshell dependencies found", HealthCheck.NO_PROBLEM, Status.OK)); } else { VisitReport vr = new VisitReport(HealthCheck.getInstance(), subject, "Beanshell dependencies missing", HealthCheck.MISSING_DEPENDENCY, Status.SEVERE); vr.setProperty("dependencies", localDependencies); vr.setProperty("directory", activity.libDir); reports.add(vr); } } Status status = VisitReport.getWorstStatus(reports); VisitReport report = new VisitReport(HealthCheck.getInstance(), subject, "Beanshell report", HealthCheck.NO_PROBLEM, status, reports); return report; }
From source file:azkaban.utils.PropsUtils.java
private static String resolveVariableReplacement(String value, Props props, LinkedHashSet<String> visitedVariables) { StringBuffer buffer = new StringBuffer(); int startIndex = 0; Matcher matcher = VARIABLE_REPLACEMENT_PATTERN.matcher(value); while (matcher.find(startIndex)) { if (startIndex < matcher.start()) { // Copy everything up front to the buffer buffer.append(value.substring(startIndex, matcher.start())); }/*w w w.java2 s .c o m*/ String subVariable = matcher.group(1); // Detected a cycle if (visitedVariables.contains(subVariable)) { throw new IllegalArgumentException( String.format("Circular variable substitution found: [%s] -> [%s]", StringUtils.join(visitedVariables, "->"), subVariable)); } else { // Add substitute variable and recurse. String replacement = props.get(subVariable); visitedVariables.add(subVariable); if (replacement == null) { throw new UndefinedPropertyException( String.format("Could not find variable substitution for variable(s) [%s]", StringUtils.join(visitedVariables, "->"))); } buffer.append(resolveVariableReplacement(replacement, props, visitedVariables)); visitedVariables.remove(subVariable); } startIndex = matcher.end(); } if (startIndex < value.length()) { buffer.append(value.substring(startIndex)); } return buffer.toString(); }
From source file:com.qwazr.library.realm.table.TableRealmConnector.java
@Override public Account verify(final String id, final Credential credential) { // This realm only support one type of credential if (!(credential instanceof PasswordCredential)) throw new RuntimeException("Unsupported credential type: " + credential.getClass().getName()); PasswordCredential passwordCredential = (PasswordCredential) credential; // We request the database final Map<String, ?> row; try {/*from w w w.ja v a 2s . c o m*/ row = tableService.getRow(table_name, id, columns); if (row == null) return null; } catch (WebApplicationException e) { if (e.getResponse().getStatusInfo().getFamily() == Response.Status.Family.CLIENT_ERROR) return authenticationFailure("Unknown user: " + id); throw e; } Object password = row.get(password_column); if (password == null) return null; if (password instanceof String[]) { String[] passwordArray = (String[]) password; if (passwordArray.length == 0) return null; password = passwordArray[0]; } // The password is stored hashed final String passwd = new String(passwordCredential.getPassword()); String digest = DigestUtils.sha256Hex(passwd); if (!digest.equals(password)) return authenticationFailure("Wrong password: " + id + " " + digest + '/' + passwd + '/' + password); //We retrieve the roles final Object object = row.get(roles_column); final LinkedHashSet<String> roles = new LinkedHashSet<>(); if (object instanceof String[]) { for (Object o : (String[]) object) roles.add(o.toString()); } else roles.add(object.toString()); return new Account() { @Override public Principal getPrincipal() { return () -> id; } @Override public Set<String> getRoles() { return roles; } }; }
From source file:com.qwazr.connectors.TableRealmConnector.java
@Override public Account verify(String id, Credential credential) { // This realm only support one type of credential if (!(credential instanceof PasswordCredential)) throw new RuntimeException("Unsupported credential type: " + credential.getClass().getName()); PasswordCredential passwordCredential = (PasswordCredential) credential; // We request the database final LinkedHashMap<String, Object> row; try {/* w w w .j ava 2s . c o m*/ row = tableService.getRow(table_name, id, columns); if (row == null) return null; } catch (WebApplicationException e) { if (e.getResponse().getStatusInfo().getFamily() == Response.Status.Family.CLIENT_ERROR) return authenticationFailure("Unknown user: " + id); throw e; } Object password = row.get(password_column); if (password == null) return null; if (password instanceof String[]) { String[] passwordArray = (String[]) password; if (passwordArray.length == 0) return null; password = passwordArray[0]; } // The password is stored hashed final String passwd = new String(passwordCredential.getPassword()); String digest = DigestUtils.sha256Hex(passwd); if (!digest.equals(password)) return authenticationFailure("Wrong password: " + id + " " + digest + '/' + passwd + '/' + password); //We retrieve the roles Object object = row.get(roles_column); LinkedHashSet<String> roles = new LinkedHashSet<String>(); if (object instanceof String[]) { for (Object o : (String[]) object) roles.add(o.toString()); } else roles.add(object.toString()); return new Account() { @Override public Principal getPrincipal() { return new Principal() { @Override public String getName() { return id; } }; } @Override public Set<String> getRoles() { return roles; } }; }
From source file:ca.on.oicr.pde.workflows.GATKGenotypeGVCFsWorkflow.java
private <T, S> Set<T> getLeftCollection(Collection<Pair<T, S>> pairs) { LinkedHashSet<T> ts = new LinkedHashSet<>(); for (Pair<T, S> p : pairs) { ts.add(p.getLeft()); }//from w ww.ja v a2 s. c o m return ts; }
From source file:ca.on.oicr.pde.workflows.GATKGenotypeGVCFsWorkflow.java
private <S, T> Set<T> getRightCollection(Collection<Pair<S, T>> pairs) { LinkedHashSet<T> ts = new LinkedHashSet<>(); for (Pair<S, T> p : pairs) { ts.add(p.getRight()); }/* www. ja v a 2s . c o m*/ return ts; }
From source file:biomine.bmvis2.pipeline.RepresentiveHighlightOperation.java
public ArrayList<VisualNode> initList(VisualGraph g) { SimpleVisualGraph sg = new SimpleVisualGraph(g.getRootNode().getDescendants()); ArrayList<ProbDijkstra> positive = new ArrayList<ProbDijkstra>(); ArrayList<ProbDijkstra> negative = new ArrayList<ProbDijkstra>(); int poicount = 0; LinkedHashSet<Integer> remaining = new LinkedHashSet<Integer>(); for (int i = 0; i < sg.n; i++) remaining.add(i); for (Map.Entry<VisualNode, Double> ent : g.getNodesOfInterest().entrySet()) { VisualNode vn = ent.getKey();/*w w w.j a v a2s .c om*/ double val = ent.getValue(); int ivn = sg.getInt(vn); remaining.remove(ivn); ProbDijkstra pd = new ProbDijkstra(sg, ivn); if (val > 0) positive.add(pd); else negative.add(pd); poicount++; } ArrayList<VisualNode> rlist = new ArrayList<VisualNode>(); ArrayList<Double> posProb = new ArrayList<Double>(); ArrayList<Double> posSquareSum = new ArrayList<Double>(); for (int i = 0; i < sg.n; i++) { double p = 1; double ss = 0; for (ProbDijkstra pd : positive) { p *= pd.getProbTo(i); ss += Math.pow(pd.getProbTo(i), 2); } posProb.add(p); posSquareSum.add(ss); } ArrayList<Double> negProb = new ArrayList<Double>(); for (int i = 0; i < sg.n; i++) { double p = 1; for (ProbDijkstra pd : negative) { p *= (1 - pd.getProbTo(i)); } negProb.add(p); } int it = 0; while (negative.size() + positive.size() < sg.n) { it++; //add //select n with highest posProb[n]*(1-negProb[n]) //in case of a tie, select n with lowest square sum distance from //positive nodes int best = -1; double bestSS = 100000; double bestProb = 0; for (int n : remaining) { double prob = posProb.get(n) * (negProb.get(n)); double ss = posSquareSum.get(n); if (prob == bestProb) { if (ss < bestSS) { bestSS = ss; best = n; } } if (prob > bestProb) { bestProb = prob; bestSS = ss; best = n; } } if (best < 0) break; System.out.println("it " + it + " best = " + best + " prob = " + bestProb); rlist.add(sg.getVisualNode(best)); ProbDijkstra newPD = new ProbDijkstra(sg, best); negative.add(newPD); remaining.remove(best); for (int i : remaining) { double ol = negProb.get(i); ol *= 1 - newPD.getProbTo(i); negProb.set(i, ol); } } return rlist; }
From source file:opennlp.tools.fca.ConceptLattice.java
public void createLatticeFromBinaryContext() { LinkedHashSet<Integer> obj; ArrayList<Integer> intent; // attributes list ArrayList<Integer> attributes = new ArrayList<Integer>(); for (int i = 0; i < attributeCount; i++) { attributes.add(i);//from w w w .j a v a 2 s . c o m } // objects set LinkedHashSet<Integer> objects = new LinkedHashSet<Integer>(); for (int i = 0; i < objectCount; i++) { objects.add(i); } this.conceptList.get(0).setIntent(attributes); for (int i = 0; i < objectCount; i++) { intent = new ArrayList<Integer>(); obj = new LinkedHashSet<Integer>(); obj.add(i); for (int j = 0; j < attributeCount; j++) { if (binaryContext[i][j] == 1) { intent.add(j); } } this.AddIntent(intent, obj, 0); } }
From source file:de.ovgu.featureide.featurehouse.FeatureHouseComposer.java
private static LinkedHashSet<String> createExtensions() { LinkedHashSet<String> extensions = new LinkedHashSet<String>(); extensions.add("java"); extensions.add("cs"); extensions.add("c"); extensions.add("h"); extensions.add("hs"); extensions.add("jj"); extensions.add("als"); extensions.add("xmi"); return extensions; }
From source file:com.cenrise.test.azkaban.PropsUtils.java
private static String resolveVariableReplacement(final String value, final Props props, final LinkedHashSet<String> visitedVariables) { final StringBuffer buffer = new StringBuffer(); int startIndex = 0; final Matcher matcher = VARIABLE_REPLACEMENT_PATTERN.matcher(value); while (matcher.find(startIndex)) { if (startIndex < matcher.start()) { // Copy everything up front to the buffer buffer.append(value.substring(startIndex, matcher.start())); }/*from w w w . ja v a2 s . co m*/ final String subVariable = matcher.group(1); // Detected a cycle if (visitedVariables.contains(subVariable)) { throw new IllegalArgumentException( String.format("Circular variable substitution found: [%s] -> [%s]", StringUtils.join(visitedVariables, "->"), subVariable)); } else { // Add substitute variable and recurse. final String replacement = props.get(subVariable); visitedVariables.add(subVariable); if (replacement == null) { throw new UndefinedPropertyException( String.format("Could not find variable substitution for variable(s) [%s]", StringUtils.join(visitedVariables, "->"))); } buffer.append(resolveVariableReplacement(replacement, props, visitedVariables)); visitedVariables.remove(subVariable); } startIndex = matcher.end(); } if (startIndex < value.length()) { buffer.append(value.substring(startIndex)); } return buffer.toString(); }