List of usage examples for java.util Set contains
boolean contains(Object o);
From source file:edu.uci.ics.jung.utils.GraphUtils.java
/** * Copies the labels of vertices from one StringLabeller to another. Only * the labels of vertices that are equivalent are copied. * //from w w w .j a va 2 s. co m * @param source * the source StringLabeller * @param target * the target StringLabeller */ public static void copyLabels(StringLabeller source, StringLabeller target) throws UniqueLabelException { Graph g1 = source.getGraph(); Graph g2 = target.getGraph(); Set s1 = g1.getVertices(); Set s2 = g2.getVertices(); for (Iterator iter = s1.iterator(); iter.hasNext();) { Vertex v = (Vertex) iter.next(); if (s2.contains(v)) { target.setLabel((Vertex) v.getEqualVertex(g2), source.getLabel(v)); } } }
From source file:com.igormaznitsa.charsniffer.CharSnifferMojo.java
static boolean checkForCodes(@Nonnull final String text, @Nonnull final CheckConfig config, @Nonnull final StringBuilder errorBuffer) { final Set<Character> errorChars = new HashSet<Character>(); if (config.minCode >= 0 || config.maxCode >= 0) { for (int i = 0; i < text.length(); i++) { final char c = text.charAt(i); if (config.minCode >= 0) { if (c < config.minCode) { if (!errorChars.contains(c)) { errorChars.add(c); if (errorBuffer.length() > 0) { errorBuffer.append(','); }/*from www . j a v a2 s.com*/ errorBuffer.append('\'').append(c).append('\''); } } } if (config.maxCode >= 0) { if (c > config.maxCode) { if (!errorChars.contains(c)) { errorChars.add(c); if (errorBuffer.length() > 0) { errorBuffer.append(','); } errorBuffer.append('\'').append(c).append('\''); } } } } } return errorChars.isEmpty(); }
From source file:com.openkm.module.db.base.BaseFolderModule.java
/** * Check if a node is being used in a running workflow (Helper) *///w ww . j av a 2s .c o m private static boolean hasWorkflowNodesInDepth(String fldUuid, Set<String> workflowNodes) throws WorkflowException, PathNotFoundException, DatabaseException { for (NodeDocument nDoc : NodeDocumentDAO.getInstance().findByParent(fldUuid)) { if (workflowNodes.contains(nDoc.getUuid())) { return true; } } for (NodeFolder nFld : NodeFolderDAO.getInstance().findByParent(fldUuid)) { return hasWorkflowNodesInDepth(nFld.getUuid(), workflowNodes); } return false; }
From source file:Main.java
public static boolean validProcess(String xml) { try {//w w w .java 2s. c o m Set<String> classifiers = new HashSet<String>(); InputStream is = new ByteArrayInputStream(xml.getBytes()); DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); Document document = docBuilder.parse(is); // iterate over all operators NodeList nodes = document.getElementsByTagName("operator"); for (int i = 0; i < nodes.getLength(); i++) { Element element = (Element) nodes.item(i); String className = element.getAttribute("class"); if (classifiers.contains(className)) { return false; } classifiers.add(className); } return true; } catch (Exception e) { return false; } }
From source file:nu.yona.server.analysis.service.AnalysisEngineService.java
static Set<GoalDto> determineRelevantGoals(ActivityPayload payload) { boolean onlyNoGoGoals = payload.isNetworkActivity() && payload.deviceAnonymized.getOperatingSystem() == OperatingSystem.ANDROID; Set<UUID> matchingActivityCategoryIds = payload.activityCategories.stream().map(ActivityCategoryDto::getId) .collect(Collectors.toSet()); Set<GoalDto> goalsOfUser = payload.userAnonymized.getGoals(); return goalsOfUser.stream().filter(g -> !g.isHistoryItem()) .filter(g -> matchingActivityCategoryIds.contains(g.getActivityCategoryId())) .filter(g -> g.isNoGoGoal() || !onlyNoGoGoals) .filter(g -> g.getCreationTime().get().isBefore( TimeUtil.toUtcLocalDateTime(payload.startTime.plus(DEVICE_TIME_INACCURACY_MARGIN)))) .collect(Collectors.toSet()); }
From source file:it.units.malelab.ege.util.Utils.java
private static <T> boolean innerValidate(Node<T> tree, Grammar<T> grammar, Set<T> terminals) { //validate node content if (!grammar.getRules().keySet().contains(tree.getContent()) && !terminals.contains(tree.getContent())) { return false; }/*from ww w . j av a2s . co m*/ if (terminals.contains(tree.getContent())) { return true; } //validate node children sequence (option) List<T> childContents = new ArrayList<>(); for (Node<T> child : tree.getChildren()) { childContents.add(child.getContent()); } if (!grammar.getRules().get(tree.getContent()).contains(childContents)) { return false; } for (Node<T> child : tree.getChildren()) { if (!innerValidate(child, grammar, terminals)) { return false; } } return true; }
From source file:com.kibana.multitenancy.plugin.kibana.KibanaSeed.java
public static void setDashboards(String user, Set<String> projects, Set<String> roles, Client esClient, String kibanaIndex, String kibanaVersion) { //GET .../.kibana/index-pattern/_search?pretty=true&fields= // compare results to projects; handle any deltas (create, delete?) //check projects for default and remove for (String project : BLACKLIST_PROJECTS) if (projects.contains(project)) { logger.debug("Black-listed project '{}' found. Not adding as an index pattern", project); projects.remove(project);//from ww w. j a va2 s. co m } Set<String> indexPatterns = getIndexPatterns(user, esClient, kibanaIndex); logger.debug("Found '{}' Index patterns for user", indexPatterns.size()); // Check roles here, if user is a cluster-admin we should add .operations to their project? -- correct way to do this? logger.debug("Checking for '{}' in users roles '{}'", OPERATIONS_ROLES, roles); /*for ( String role : OPERATIONS_ROLES ) if ( roles.contains(role) ) { logger.debug("{} is an admin user", user); projects.add(OPERATIONS_PROJECT); break; }*/ List<String> sortedProjects = new ArrayList<String>(projects); Collections.sort(sortedProjects); if (sortedProjects.isEmpty()) sortedProjects.add(BLANK_PROJECT); logger.debug("Setting dashboards given user '{}' and projects '{}'", user, projects); // If none have been set yet if (indexPatterns.isEmpty()) { create(user, sortedProjects, true, esClient, kibanaIndex, kibanaVersion); //TODO : Currently it is generating wrong search properties when integrated with ES 2.1 //createSearchProperties(user, esClient, kibanaIndex); } else { List<String> common = new ArrayList<String>(indexPatterns); // Get a list of all projects that are common common.retainAll(sortedProjects); sortedProjects.removeAll(common); indexPatterns.removeAll(common); // for any to create (remaining in projects) call createIndices, createSearchmapping?, create dashboard create(user, sortedProjects, false, esClient, kibanaIndex, kibanaVersion); // cull any that are in ES but not in OS (remaining in indexPatterns) remove(user, indexPatterns, esClient, kibanaIndex); common.addAll(sortedProjects); Collections.sort(common); // Set default index to first index in common if we removed the default String defaultIndex = getDefaultIndex(user, esClient, kibanaIndex, kibanaVersion); logger.debug("Checking if '{}' contains '{}'", indexPatterns, defaultIndex); if (indexPatterns.contains(defaultIndex) || StringUtils.isEmpty(defaultIndex)) { logger.debug("'{}' does contain '{}' and common size is {}", indexPatterns, defaultIndex, common.size()); if (common.size() > 0) setDefaultIndex(user, common.get(0), esClient, kibanaIndex, kibanaVersion); } } }
From source file:edu.jhuapl.graphs.jfreechart.JFreeChartTimeSeriesGraphSource.java
private static void checkSeries(TimeSeriesInterface series, TimeResolution resolution) throws GraphException { Set<Date> seenDates = new HashSet<Date>(); for (TimePointInterface point : series.getPoints()) { Date kernelDate = getKernelDate(point.getDescriminator(), resolution); if (seenDates.contains(kernelDate)) { throw new GraphException("Time series already contains point with date " + kernelDate); }/* www . j a v a2s. c om*/ seenDates.add(kernelDate); } }
From source file:de.escalon.hypermedia.spring.uber.UberUtils.java
private static void addUberFieldsForMethodParameter(List<UberField> fields, MethodParameter methodParameter, ActionInputParameter annotatedParameter, ActionDescriptor annotatedParameters, String parentParamName, String paramName, Class parameterType, Object propertyValue, Set<String> knownFields) { if (DataType.isSingleValueType(parameterType) || DataType.isArrayOrCollection(parameterType)) { if (annotatedParameter.isIncluded(paramName) && !knownFields.contains(parentParamName + paramName)) { ActionInputParameter constructorParamInputParameter = new SpringActionInputParameter( methodParameter, propertyValue); final Object[] possibleValues = annotatedParameter.getPossibleValues(methodParameter, annotatedParameters); // dot-separated property path as field name UberField field = createUberField(parentParamName + paramName, propertyValue, constructorParamInputParameter, possibleValues); fields.add(field);//from www . java 2s .co m } } else { Object callValueBean; if (propertyValue instanceof Resource) { callValueBean = ((Resource) propertyValue).getContent(); } else { callValueBean = propertyValue; } recurseBeanCreationParams(fields, parameterType, annotatedParameters, annotatedParameter, callValueBean, paramName + ".", knownFields); } }
From source file:com.ocs.dynamo.domain.model.util.EntityModelUtil.java
/** * Compares two entities based on the entity model and reports a list of the differences * /* w w w.j av a 2 s .c o m*/ * @param oldEntity * the old entity * @param newEntity * the new entity * @param model * the entity model * @param entityModelFactory * @param messageService * the message service * @param ignore * the names of the fields to ignore */ public static List<String> compare(Object oldEntity, Object newEntity, EntityModel<?> model, EntityModelFactory entityModelFactory, MessageService messageService, String... ignore) { List<String> results = new ArrayList<>(); Set<String> toIgnore = new HashSet<>(); if (ignore != null) { toIgnore = Sets.newHashSet(ignore); } toIgnore.addAll(ALWAYS_IGNORE); String noValue = messageService.getMessage("ocs.no.value"); for (AttributeModel am : model.getAttributeModels()) { if ((AttributeType.BASIC.equals(am.getAttributeType()) || AttributeType.MASTER.equals(am.getAttributeType())) && !toIgnore.contains(am.getName())) { Object oldValue = ClassUtils.getFieldValue(oldEntity, am.getName()); Object newValue = ClassUtils.getFieldValue(newEntity, am.getName()); if (!ObjectUtils.equals(oldValue, newValue)) { String oldValueStr = TableUtils.formatPropertyValue(entityModelFactory, model, messageService, am.getName(), oldValue); String newValueStr = TableUtils.formatPropertyValue(entityModelFactory, model, messageService, am.getName(), newValue); results.add(messageService.getMessage("ocs.value.changed", am.getDisplayName(), oldValue == null ? noValue : oldValueStr, newValue == null ? noValue : newValueStr)); } } else if (AttributeType.DETAIL.equals(am.getAttributeType())) { Collection<?> ocol = (Collection<?>) ClassUtils.getFieldValue(oldEntity, am.getName()); Collection<?> ncol = (Collection<?>) ClassUtils.getFieldValue(newEntity, am.getName()); for (Object o : ncol) { if (!ocol.contains(o)) { results.add(messageService.getMessage("ocs.value.added", getDescription(o, am.getNestedEntityModel()), am.getDisplayName())); } } for (Object o : ocol) { if (!ncol.contains(o)) { results.add(messageService.getMessage("ocs.value.removed", getDescription(o, am.getNestedEntityModel()), am.getDisplayName())); } } for (Object o : ocol) { for (Object o2 : ncol) { if (o.equals(o2)) { List<String> nested = compare(o, o2, am.getNestedEntityModel(), entityModelFactory, messageService, ignore); results.addAll(nested); } } } } } return results; }