List of usage examples for java.util Set isEmpty
boolean isEmpty();
From source file:org.wrml.runtime.format.application.vnd.wrml.design.schema.SchemaDesignFormatter.java
public static ObjectNode buildSchemaNode(final ObjectMapper objectMapper, final URI schemaUri, final SchemaLoader schemaLoader, final Set<URI> addedBaseSchemaUris) { final Prototype prototype = schemaLoader.getPrototype(schemaUri); if (prototype == null) { return null; }/* w w w . j av a 2s . co m*/ final ObjectNode schemaNode = objectMapper.createObjectNode(); schemaNode.put(PropertyName.localName.name(), prototype.getUniqueName().getLocalName()); schemaNode.put(PropertyName.title.name(), prototype.getTitle()); schemaNode.put(PropertyName.uri.name(), schemaUri.toString()); schemaNode.put(PropertyName.version.name(), prototype.getVersion()); String titleSlotName = prototype.getTitleSlotName(); if (StringUtils.isNotBlank(titleSlotName)) { schemaNode.put(PropertyName.titleSlotName.name(), titleSlotName); } else { titleSlotName = getTitleSlotName(schemaUri, schemaLoader); if (StringUtils.isNotBlank(titleSlotName)) { schemaNode.put(PropertyName.titleSlotName.name(), titleSlotName); } } final Set<String> allSlotNames = prototype.getAllSlotNames(); if (allSlotNames != null && !allSlotNames.isEmpty()) { final ArrayNode propertyNamesNode = objectMapper.createArrayNode(); for (final String slotName : allSlotNames) { final ProtoSlot protoSlot = prototype.getProtoSlot(slotName); if (protoSlot instanceof LinkProtoSlot) { continue; } if (protoSlot.getDeclaringSchemaUri().equals(schemaUri)) { propertyNamesNode.add(slotName); } } if (propertyNamesNode.size() > 0) { schemaNode.put(PropertyName.propertyNames.name(), propertyNamesNode); } } final Set<String> keySlotNames = prototype.getDeclaredKeySlotNames(); if (keySlotNames != null && !keySlotNames.isEmpty()) { final ArrayNode keyPropertyNamesNode = objectMapper.createArrayNode(); for (final String keySlotName : keySlotNames) { keyPropertyNamesNode.add(keySlotName); } if (keyPropertyNamesNode.size() > 0) { schemaNode.put(PropertyName.keyPropertyNames.name(), keyPropertyNamesNode); } } final Set<String> allKeySlotNames = prototype.getAllKeySlotNames(); final ArrayNode allKeySlotNamesNode = objectMapper.createArrayNode(); schemaNode.put(PropertyName.allKeySlotNames.name(), allKeySlotNamesNode); for (final String keySlotName : allKeySlotNames) { allKeySlotNamesNode.add(keySlotName); } final Set<String> comparablePropertyNames = prototype.getComparableSlotNames(); if (comparablePropertyNames != null && !comparablePropertyNames.isEmpty()) { final ArrayNode comparablePropertyNamesNode = objectMapper.createArrayNode(); for (final String comparablePropertyName : comparablePropertyNames) { comparablePropertyNamesNode.add(comparablePropertyName); } if (comparablePropertyNamesNode.size() > 0) { schemaNode.put(PropertyName.comparablePropertyNames.name(), comparablePropertyNamesNode); } } final Map<URI, LinkProtoSlot> linkProtoSlots = prototype.getLinkProtoSlots(); if (linkProtoSlots != null && !linkProtoSlots.isEmpty()) { final ArrayNode linkNamesNode = objectMapper.createArrayNode(); for (final LinkProtoSlot linkProtoSlot : linkProtoSlots.values()) { if (linkProtoSlot.getDeclaringSchemaUri().equals(schemaUri)) { linkNamesNode.add(linkProtoSlot.getName()); } } if (linkNamesNode.size() > 0) { schemaNode.put(PropertyName.linkNames.name(), linkNamesNode); } } final Set<URI> declaredBaseSchemaUris = prototype.getDeclaredBaseSchemaUris(); if (declaredBaseSchemaUris != null && !declaredBaseSchemaUris.isEmpty() && addedBaseSchemaUris != null) { final ArrayNode baseSchemasNode = objectMapper.createArrayNode(); for (final URI baseSchemaUri : declaredBaseSchemaUris) { if (!addedBaseSchemaUris.contains(baseSchemaUri)) { final ObjectNode baseSchemaNode = buildSchemaNode(objectMapper, baseSchemaUri, schemaLoader, addedBaseSchemaUris); baseSchemasNode.add(baseSchemaNode); addedBaseSchemaUris.add(baseSchemaUri); } } if (baseSchemasNode.size() > 0) { schemaNode.put(PropertyName.baseSchemas.name(), baseSchemasNode); } } return schemaNode; }
From source file:com.netflix.genie.web.data.repositories.jpa.specifications.JpaCommandSpecs.java
/** * Get a specification using the specified parameters. * * @param name The name of the command * @param user The name of the user who created the command * @param statuses The status of the command * @param tags The set of tags to search the command for * @return A specification object used for querying *///from www. j a va 2s .c o m public static Specification<CommandEntity> find(@Nullable final String name, @Nullable final String user, @Nullable final Set<CommandStatus> statuses, @Nullable final Set<TagEntity> tags) { return (final Root<CommandEntity> root, final CriteriaQuery<?> cq, final CriteriaBuilder cb) -> { final List<Predicate> predicates = new ArrayList<>(); if (StringUtils.isNotBlank(name)) { predicates.add(JpaSpecificationUtils.getStringLikeOrEqualPredicate(cb, root.get(CommandEntity_.name), name)); } if (StringUtils.isNotBlank(user)) { predicates.add(JpaSpecificationUtils.getStringLikeOrEqualPredicate(cb, root.get(CommandEntity_.user), user)); } if (statuses != null && !statuses.isEmpty()) { predicates.add( cb.or(statuses.stream().map(status -> cb.equal(root.get(CommandEntity_.status), status)) .toArray(Predicate[]::new))); } if (tags != null && !tags.isEmpty()) { final Join<CommandEntity, TagEntity> tagEntityJoin = root.join(CommandEntity_.tags); predicates.add(tagEntityJoin.in(tags)); cq.groupBy(root.get(CommandEntity_.id)); cq.having(cb.equal(cb.count(root.get(CommandEntity_.id)), tags.size())); } return cb.and(predicates.toArray(new Predicate[predicates.size()])); }; }
From source file:io.github.swagger2markup.MarkdownConverterTest.java
/** * Given a markdown document to search, this checks to see if the specified tables * have all of the expected fields listed. * Match is a "search", and not an "equals" match. * * @param doc markdown document file to inspect * @param fieldsByTable map of table name (header) to field names expected * to be found in that table. * @throws IOException if the markdown document could not be read *///from ww w . j av a2s . c o m private static void verifyMarkdownContainsFieldsInTables(File doc, Map<String, Set<String>> fieldsByTable) throws IOException { //TODO: This method is too complex, split it up in smaller methods to increase readability final List<String> lines = Files.readAllLines(doc.toPath(), Charset.defaultCharset()); final Map<String, Set<String>> fieldsLeftByTable = Maps.newHashMap(); for (Map.Entry<String, Set<String>> entry : fieldsByTable.entrySet()) { fieldsLeftByTable.put(entry.getKey(), Sets.newHashSet(entry.getValue())); } String inTable = null; for (String line : lines) { // If we've found every field we care about, quit early if (fieldsLeftByTable.isEmpty()) { return; } // Transition to a new table if we encounter a header final String currentHeader = getTableHeader(line); if (inTable == null || currentHeader != null) { inTable = currentHeader; } // If we're in a table that we care about, inspect this potential table row if (inTable != null && fieldsLeftByTable.containsKey(inTable)) { // If we're still in a table, read the row and check for the field name // NOTE: If there was at least one pipe, then there's at least 2 fields String[] parts = line.split("\\|"); if (parts.length > 1) { final String fieldName = parts[1]; final Set<String> fieldsLeft = fieldsLeftByTable.get(inTable); // Mark the field as found and if this table has no more fields to find, // remove it from the "fieldsLeftByTable" map to mark the table as done Iterator<String> fieldIt = fieldsLeft.iterator(); while (fieldIt.hasNext()) { String fieldLeft = fieldIt.next(); if (fieldName.contains(fieldLeft)) fieldIt.remove(); } if (fieldsLeft.isEmpty()) { fieldsLeftByTable.remove(inTable); } } } } // After reading the file, if there were still types, fail if (!fieldsLeftByTable.isEmpty()) { fail(String.format("Markdown file '%s' did not contain expected fields (by table): %s", doc, fieldsLeftByTable)); } }
From source file:com.gongpingjia.carplay.service.util.ActivityUtil.java
private static List<ActivityWeight> sortActivityList(List<Activity> activities, Date currentTime, Landmark nowLandmark, double maxDistance, long maxPubTime, int genderType, Set<String> toRemoveSet) { ArrayList<ActivityWeight> awList = new ArrayList<>(activities.size()); for (Activity activity : activities) { Map<String, Object> user = activity.getOrganizer(); ////from w w w. j av a2 s .c o m if (genderType == 0) { if (!StringUtils.equals(String.valueOf(user.get("gender")), Constants.UserGender.MALE)) { continue; } } else if (genderType == 1) { if (!StringUtils.equals(String.valueOf(user.get("gender")), Constants.UserGender.FEMALE)) { continue; } } if (null != toRemoveSet && !toRemoveSet.isEmpty()) { if (toRemoveSet.contains(activity.getActivityId())) { continue; } } ActivityWeight aw = new ActivityWeight(activity); // ? if (StringUtils.equals(String.valueOf(user.get("licenseAuthStatus")), Constants.AuthStatus.ACCEPT)) { aw.setCarOwnerFlag(true); } //?? if (StringUtils.equals(String.valueOf(user.get("photoAuthStatus")), Constants.AuthStatus.ACCEPT)) { aw.setAvatarFlag(true); } //TODO //? ???? //??? initWeight(currentTime, nowLandmark, aw, maxDistance, maxPubTime); awList.add(aw); } Collections.sort(awList); return awList; }
From source file:de.fraunhofer.iosb.ilt.sta.persistence.postgres.PropertyHelper.java
public static Expression<?>[] getExpressions(Path<?> qPath, Set<EntityProperty> selectedProperties) { List<Expression<?>> exprList = new ArrayList<>(); if (selectedProperties.isEmpty()) { PropertyResolver.expressionsForClass(qPath, exprList); } else {// ww w.ja va 2s.c o m for (EntityProperty property : selectedProperties) { PropertyResolver.expressionsForProperty(property, qPath, exprList); } } return exprList.toArray(new Expression<?>[exprList.size()]); }
From source file:net.lldp.checksims.ChecksimsCommandLine.java
/** * Build the collection of submissions Checksims will be run on. * * TODO add unit tests/* www.j a va 2 s .c o m*/ * * @param submissionDirs Directories to build submissions from * @param glob Glob matcher to use when building submissions * @param tokenizer Tokenizer to use when building submissions * @param recursive Whether to recursively traverse when building submissions * @return Collection of submissions which will be used to run Checksims * @throws IOException Thrown on issue reading files or traversing directories to build submissions */ public static Set<Submission> getSubmissions(Set<File> submissionDirs, String glob, boolean recursive, boolean retainEmpty) throws IOException, ChecksimsException { checkNotNull(submissionDirs); checkArgument(!submissionDirs.isEmpty(), "Must provide at least one submission directory!"); checkNotNull(glob); submissionDirs = extractTurninFiles(submissionDirs); // Generate submissions to work on Set<Submission> submissions = new HashSet<>(); for (File dir : submissionDirs) { if (logs != null) { logs.debug("Adding directory " + dir.getName()); } submissions.addAll(Submission.submissionListFromDir(dir, glob, recursive)); } // If not retaining empty submissions, filter the empty ones out if (!retainEmpty) { Set<Submission> submissionsNoEmpty = new HashSet<>(); for (Submission s : submissions) { if (s.getContentAsString().isEmpty()) { if (logs != null) { logs.warn("Discarding empty submission " + s.getName()); } } else { submissionsNoEmpty.add(s); } } return submissionsNoEmpty; } return submissions; }
From source file:com.aurel.track.admin.customize.lists.systemOption.IssueTypeBL.java
public static List<TListTypeBean> loadByPersonAndProjectAndRight(Integer personID, Integer projectID, int[] rightFlags, boolean documents) { List<TListTypeBean> resultList = new LinkedList<TListTypeBean>(); if (projectID == null) { return resultList; }//from w w w . j av a 2 s .c o m //allowed by project type TProjectBean projectBean = LookupContainer.getProjectBean(projectID); List<TListTypeBean> issueTypesAllowedByProjectType = loadAllowedByProjectType(projectBean.getProjectType(), documents); //get the roles Set<Integer> rolesSet = AccessBeans.getRolesWithRightForPersonInProject(personID, projectID, rightFlags); if (rolesSet == null || rolesSet.isEmpty()) { return resultList; } Object[] roleIDs = rolesSet.toArray(); //roles with issueType restrictions List<TRoleBean> roleWithExplicitIssueType = RoleBL.loadWithExplicitIssueType(roleIDs); //at least one role has no restrictions for listType if (roleWithExplicitIssueType != null && roleWithExplicitIssueType.size() < rolesSet.size()) { //load all list types allowed in project type return issueTypesAllowedByProjectType; } //all roles have explicit issue type restrictions //get all those explicit issueTypes for roles List<TListTypeBean> allowedByRoles = issueTypeDAO.loadForRoles(roleIDs); Map<Integer, TListTypeBean> allowedByProjectTypeMap = GeneralUtils .createMapFromList(issueTypesAllowedByProjectType); if (allowedByRoles != null) { Iterator<TListTypeBean> iterator = allowedByRoles.iterator(); while (iterator.hasNext()) { TListTypeBean listTypeBean = iterator.next(); if (!allowedByProjectTypeMap.containsKey(listTypeBean.getObjectID())) { iterator.remove(); } } } return allowedByRoles; }
From source file:com.espertech.esper.epl.core.ResultSetProcessorSimple.java
/** * Applies the select-clause to the given events returning the selected events. The number of events stays the * same, i.e. this method does not filter it just transforms the result set. * <p>//from ww w. ja va 2 s . co m * Also applies a having clause. * @param exprProcessor - processes each input event and returns output event * @param orderByProcessor - for sorting output events according to the order-by clause * @param events - input events * @param optionalHavingNode - supplies the having-clause expression * @param isNewData - indicates whether we are dealing with new data (istream) or old data (rstream) * @param isSynthesize - set to true to indicate that synthetic events are required for an iterator result set * @param exprEvaluatorContext context for expression evalauation * @return output events, one for each input event */ protected static EventBean[] getSelectEventsHaving(SelectExprProcessor exprProcessor, OrderByProcessor orderByProcessor, Set<MultiKey<EventBean>> events, ExprEvaluator optionalHavingNode, boolean isNewData, boolean isSynthesize, ExprEvaluatorContext exprEvaluatorContext) { if ((events == null) || (events.isEmpty())) { return null; } LinkedList<EventBean> result = new LinkedList<EventBean>(); List<EventBean[]> eventGenerators = null; if (orderByProcessor != null) { eventGenerators = new ArrayList<EventBean[]>(); } for (MultiKey<EventBean> key : events) { EventBean[] eventsPerStream = key.getArray(); Boolean passesHaving = (Boolean) optionalHavingNode.evaluate(eventsPerStream, isNewData, exprEvaluatorContext); if ((passesHaving == null) || (!passesHaving)) { continue; } EventBean resultEvent = exprProcessor.process(eventsPerStream, isNewData, isSynthesize, exprEvaluatorContext); result.add(resultEvent); if (orderByProcessor != null) { eventGenerators.add(eventsPerStream); } } if (!result.isEmpty()) { if (orderByProcessor != null) { return orderByProcessor.sort(result.toArray(new EventBean[result.size()]), eventGenerators.toArray(new EventBean[eventGenerators.size()][]), isNewData, exprEvaluatorContext); } else { return result.toArray(new EventBean[result.size()]); } } else { return null; } }
From source file:com.net2plan.libraries.IPUtils.java
/** * Outputs a given set of routing tables to a {@code String}. For debugging purposes. * * @param nodes List of nodes/*w w w . j a v a 2 s .c o m*/ * @param links List of links * @param f_te Destination-based routing in the form of fractions <i>f<sub>te</sub></i> (fraction of the traffic targeted to node <i>t</i> that arrives (or is generated in) node <i>a</i>(<i>e</i>) (the initial node of link <i>e</i>), that is forwarded through link <i>e</i>) * @return A {@code String} from the given routing tables */ public static String routingTableMatrixToString(List<Node> nodes, List<Link> links, DoubleMatrix2D f_te) { StringBuilder out = new StringBuilder(); final int N = nodes.size(); int i = 0; for (Node node : nodes) { out.append(String.format("Routing table for n%d%n", node.getId())); Set<Link> outgoingLinks_thisNode = node.getOutgoingLinksAllLayers(); boolean thereAreRoutes = false; if (!outgoingLinks_thisNode.isEmpty()) { for (Node egressNode : nodes) { if (node.equals(egressNode)) continue; final int t = egressNode.getIndex(); thereAreRoutes = false; StringBuilder out_thisEgressNode = new StringBuilder(); out_thisEgressNode.append(String.format("dst: n%d, gw:", egressNode.getId())); for (Link link : outgoingLinks_thisNode) { final int e = link.getIndex(); double trafficValue = f_te.get(t, e); if (trafficValue < 0) continue; out_thisEgressNode.append(String.format(" [e%d (n%d): %f]", link.getId(), links.get(link.getIndex()).getDestinationNode().getId(), trafficValue)); thereAreRoutes = true; } out_thisEgressNode.append(String.format("%n")); if (thereAreRoutes) out.append(out_thisEgressNode); } } if (!thereAreRoutes) out.append("Empty"); i++; if (i < N) { out.append(String.format("%n")); } } return out.toString(); }
From source file:de.interactive_instruments.ShapeChange.Transformation.Profiling.ProfileIdentifierMap.java
/** * @param profilesString/*from w w w.j av a 2s . c o m*/ * @param pattern * @param ownerName * name of the model element that owns the profilesString * @return * @throws MalformedProfileIdentifierException */ public static ProfileIdentifierMap parse(String profilesString, ProfileIdentifier.IdentifierPattern pattern, String ownerName) throws MalformedProfileIdentifierException { String[] profileIdentifierStrings = profilesString.split(","); Map<String, ProfileIdentifier> profileIdentifiersByName = new HashMap<String, ProfileIdentifier>(); Set<String> duplicateProfileIdentifierNames = new HashSet<String>(); for (String profileIdentifierString : profileIdentifierStrings) { ProfileIdentifier profileIdentifier = ProfileIdentifier.parse(profileIdentifierString, pattern, ownerName); if (profileIdentifiersByName.containsKey(profileIdentifier.getName())) { duplicateProfileIdentifierNames.add(profileIdentifier.getName()); // TBD: if desired, the version information could also be merged } else { profileIdentifiersByName.put(profileIdentifier.getName(), profileIdentifier); } } if (!duplicateProfileIdentifierNames.isEmpty()) { throw new MalformedProfileIdentifierException( "Duplicate profile name(s) encountered (in profile set owned by '" + ownerName + "': " + StringUtils.join(duplicateProfileIdentifierNames, ",")); } else { return new ProfileIdentifierMap(profileIdentifiersByName, ownerName); } }