List of usage examples for com.google.common.collect Sets intersection
public static <E> SetView<E> intersection(final Set<E> set1, final Set<?> set2)
From source file:th.algorithms.propinquitydynamics.utils.CalculationTable.java
public static Set<Integer> CalculateCdd(Set<Integer> Nr, Set<Integer> Nd, Set<Integer> nnNr, Set<Integer> nnNd) { // (Nr + Nd) ^ (nnNr + nnNd) return Sets.intersection(Sets.union(Nr, Nd), Sets.union(nnNr, nnNd)).copyInto(new HashSet<Integer>(20)); }
From source file:com.github.gdfm.shobaidogu.StatsUtils.java
/** * Computes the Jaccard overlap between two sets. * //from w ww.ja v a 2s . c o m * @param s1 * first set. * @param s2 * second set. * @return the Jaccard overlap. */ public static <T> double jaccardOverlap(Set<T> s1, Set<T> s2) { checkNotNull(s1); checkNotNull(s2); if (s1.isEmpty() || s2.isEmpty()) return 0; double intersectSize = Sets.intersection(s1, s2).size(); double unionSize = Sets.union(s1, s2).size(); return intersectSize / unionSize; }
From source file:com.yahoo.yqlplus.engine.internal.tasks.JoinTask.java
@Override public Set<Value> getInputs() { Set<Value> values = Sets.newIdentityHashSet(); for (Task next : getNext()) { values.addAll(next.getInputs()); }/*ww w . j av a2s. co m*/ return Sets.intersection(values, getAvailable()); }
From source file:piecework.util.SearchUtility.java
public static final Query query(SearchQueryParameters queryParameters, Set<String> allowedProcessDefinitionKeys, Sanitizer sanitizer) {// w ww .ja v a 2 s . c o m Query query = new Query(); Set<String> filteredProcessDefinitionKeys; if (queryParameters.getProcessDefinitionKey() != null && !queryParameters.getProcessDefinitionKey().isEmpty()) filteredProcessDefinitionKeys = Sets.intersection(queryParameters.getProcessDefinitionKey(), allowedProcessDefinitionKeys); else filteredProcessDefinitionKeys = allowedProcessDefinitionKeys; query.addCriteria(where("processDefinitionKey").in(filteredProcessDefinitionKeys)); // if (!searchCriteria.getProcessInstanceIds().isEmpty()) // query.addCriteria(where("processInstanceId").in(searchCriteria.getProcessInstanceIds())); // if (StringUtils.isNotEmpty(searchCriteria.getBusinessKey())) // query.addCriteria(where("alias").is(searchCriteria.getBusinessKey())); // if (StringUtils.isNotEmpty(searchCriteria.getProcessDefinitionLabel())) // query.addCriteria(where("processDefinitionLabel").regex(searchCriteria.getProcessDefinitionLabel(), "i")); // if (StringUtils.isNotEmpty(searchCriteria.getProcessInstanceLabel())) // query.addCriteria(where("processInstanceLabel").regex(searchCriteria.getProcessInstanceLabel(), "i")); // if (StringUtils.isNotBlank(searchCriteria.getApplicationStatus())) // query.addCriteria(where("applicationStatus").is(searchCriteria.getApplicationStatus())); // if (StringUtils.isNotBlank(searchCriteria.getApplicationStatusExplanation())) // query.addCriteria(where("applicationStatus").regex(searchCriteria.getApplicationStatusExplanation(), "i")); // // if (StringUtils.isNotBlank(searchCriteria.getProcessStatus())) { // if (!searchCriteria.getProcessStatus().equalsIgnoreCase("all")) // query.addCriteria(where("processStatus").is(searchCriteria.getProcessStatus())); // } else if (searchCriteria.getComplete() != null && searchCriteria.getComplete().booleanValue()) // query.addCriteria(where("processStatus").is(Constants.ProcessStatuses.COMPLETE)); // else if (searchCriteria.getSuspended() != null && searchCriteria.getSuspended().booleanValue()) // query.addCriteria(where("processStatus").is(Constants.ProcessStatuses.SUSPENDED)); // else if (searchCriteria.getCancelled() != null && searchCriteria.getCancelled().booleanValue()) // query.addCriteria(where("processStatus").is(Constants.ProcessStatuses.CANCELLED)); // else if (searchCriteria.getQueued() != null && searchCriteria.getQueued().booleanValue()) // query.addCriteria(where("processStatus").is(Constants.ProcessStatuses.QUEUED)); // else if (searchCriteria.getAll() == null || !searchCriteria.getAll().booleanValue()) // query.addCriteria(where("processStatus").is(Constants.ProcessStatuses.OPEN)); // // if (StringUtils.isNotEmpty(searchCriteria.getInitiatedBy())) // query.addCriteria(where("initiatorId").is(searchCriteria.getInitiatedBy())); // // if (searchCriteria.getStartedBefore() != null && searchCriteria.getStartedAfter() != null) // query.addCriteria(where("startTime").lt(searchCriteria.getStartedBefore()).gt(searchCriteria.getStartedAfter())); // else if (searchCriteria.getStartedBefore() != null) // query.addCriteria(where("startTime").lt(searchCriteria.getStartedBefore())); // else if (searchCriteria.getStartedAfter() != null) // query.addCriteria(where("startTime").gt(searchCriteria.getStartedAfter())); // // if (searchCriteria.getCompletedBefore() != null) // query.addCriteria(where("endTime").lt(searchCriteria.getCompletedBefore())); // if (searchCriteria.getCompletedAfter() != null) // query.addCriteria(where("endTime").gt(searchCriteria.getCompletedAfter())); // // if (!searchCriteria.getKeywords().isEmpty()) { // for (String keyword : searchCriteria.getKeywords()) // query.addCriteria(where("keywords").regex(keyword.toLowerCase())); // } // // if (searchCriteria.getMaxResults() != null) // query.limit(searchCriteria.getMaxResults()); // // if (searchCriteria.getFirstResult() != null) // query.skip(searchCriteria.getFirstResult()); // // if (searchCriteria.getOrderBy() != null) { // switch (searchCriteria.getOrderBy()) { // case START_TIME_ASC: // query.with(new Sort(Sort.Direction.ASC, "startTime")); // break; // case START_TIME_DESC: // query.with(new Sort(Sort.Direction.DESC, "startTime")); // break; // case END_TIME_ASC: // query.with(new Sort(Sort.Direction.ASC, "endTime")); // break; // case END_TIME_DESC: // query.with(new Sort(Sort.Direction.DESC, "endTime")); // break; // } // } else { // query.with(new Sort(Sort.Direction.DESC, "startTime")); // } return query; }
From source file:mtsar.api.csv.AnswerCSV.java
public static Iterator<Answer> parse(Stage stage, CSVParser csv) { final Set<String> header = csv.getHeaderMap().keySet(); checkArgument(!Sets.intersection(header, Sets.newHashSet(HEADER)).isEmpty(), "Unknown CSV header: %s", String.join(",", header)); return StreamSupport.stream(csv.spliterator(), false).map(row -> { final String id = row.isSet("id") ? row.get("id") : null; final String[] tags = row.isSet("tags") && !StringUtils.isEmpty(row.get("tags")) ? row.get("tags").split("\\|") : new String[0]; final String type = row.isSet("type") ? row.get("type") : null; final String workerId = row.get("worker_id"); final String taskId = row.get("task_id"); final String[] answers = row.isSet("answers") && !StringUtils.isEmpty(row.get("answers")) ? row.get("answers").split("\\|") : new String[0]; final String datetime = row.isSet("datetime") ? row.get("datetime") : null; return new Answer.Builder().setId(StringUtils.isEmpty(id) ? null : Integer.valueOf(id)) .setStage(stage.getId()).addAllTags(Arrays.asList(tags)) .setDateTime(new Timestamp(StringUtils.isEmpty(datetime) ? System.currentTimeMillis() : Long.parseLong(datetime) * 1000L)) .setType(StringUtils.defaultIfEmpty(type, AnswerDAO.ANSWER_TYPE_DEFAULT)) .setWorkerId(Integer.valueOf(workerId)).setTaskId(Integer.valueOf(taskId)) .addAllAnswers(Arrays.asList(answers)).build(); }).iterator();// w w w .j a v a2 s . c o m }
From source file:org.fenixedu.cms.domain.PermissionEvaluation.java
public static boolean canDoThis(User user, Site site, Permission... permissions) { HashSet<Permission> requiredPerms = Sets.newHashSet(permissions); if (Group.parse("#managers").isMember(user)) { return true; }/*from w w w . ja v a2 s . c o m*/ for (Role role : site.getRolesSet()) { Set<Permission> availablePerms = role.getRoleTemplate().getPermissions().get(); Set<Permission> intersection = Sets.intersection(availablePerms, requiredPerms); if (!intersection.isEmpty() && role.getGroup().isMember(user)) { requiredPerms.removeAll(intersection); } } return requiredPerms.isEmpty(); }
From source file:com.google.errorprone.bugpatterns.ArgumentParameterSimilarityMetrics.java
/** * The similarity metric from Section 2.1 of Liu et al., "Nomen est Omen: Exploring and Exploiting * Similarities between Argument and Parameter Names," ICSE 2016. * * <p>The formula is |argTerms intersect paramTerms| / (|argTerms| + |paramTerms|) * 2. *///from w w w. j a va 2 s .c o m public static double computeNormalizedTermIntersection(String arg, String param) { // TODO(ciera): consider also using edit distance on individual words. Set<String> argSplit = splitStringTerms(arg); Set<String> paramSplit = splitStringTerms(param); // TODO(andrewrice): Handle the substring cases so that lenList matches listLength double commonTerms = Sets.intersection(argSplit, paramSplit).size() * 2; double totalTerms = argSplit.size() + paramSplit.size(); return commonTerms / totalTerms; }
From source file:edu.harvard.med.iccbl.screensaver.policy.DataSharingLevelMapper.java
public static ScreensaverUserRole getPrimaryDataSharingLevelRoleForUser(ScreenType screenType, ScreensaverUser user) {//from w ww . ja v a 2 s.com TreeSet<ScreensaverUserRole> userDslRoles = Sets .newTreeSet(Sets.intersection(user.getScreensaverUserRoles(), UserDslRoles.get(screenType))); if (!userDslRoles.isEmpty()) { return userDslRoles.last(); } return null; }
From source file:com.google.errorprone.bugpatterns.ArgumentParameterUtils.java
/** * Given the name of the argument and parameter this measures the similarity of the two strings. * The terms within the argument and parameter names are split, so "keepPath" becomes <"keep", * "path">.//from w w w . j a va 2 s . c om * * @return percentage of how many terms are similar between the argList and paramList. There is a * false positive if given terms like "fooBar" and "barFoo", the strings are not the same but * the similarity is still 1. */ public static double lexicalSimilarity(String arg, String param) { Set<String> argSplit = splitStringTermsToSet(arg); Set<String> paramSplit = splitStringTermsToSet(param); double commonTerms = Sets.intersection(argSplit, paramSplit).size() * 2; double totalTerms = argSplit.size() + paramSplit.size(); return (commonTerms / totalTerms); }
From source file:com.yahoo.yqlplus.engine.internal.tasks.RunTask.java
@Override public Set<Value> getInputs() { // we need a list of the values that we need, but do not compute ourselves Set<Value> values = Sets.newIdentityHashSet(); for (Task next : getNext()) { values.addAll(next.getInputs()); }//from w ww .ja v a 2 s. c om for (Step step : steps) { values.addAll(step.getInputs()); } for (Step step : steps) { values.remove(step.getOutput()); } return Sets.intersection(values, getAvailable()); }