List of usage examples for java.util Set isEmpty
boolean isEmpty();
From source file:de.iteratec.iteraplan.presentation.ajax.DojoUtils.java
public static Map<String, Object> convertToMap(InformationSystemRelease entity, HttpServletRequest req) { Map<String, Object> result = new HashMap<String, Object>(); result.put("id", entity.getId()); result.put("name", entity.getNameWithoutVersion()); result.put("version", entity.getVersion()); result.put("description", entity.getDescription()); LocalDateTime modificationTime = new LocalDateTime(entity.getLastModificationTime()); result.put("lastModified", ISO_DATE_TIME_FORMATTER.print(modificationTime)); String status = MessageAccess.getString(entity.getTypeOfStatusAsString(), Locale.ENGLISH); result.put("status", status); if (entity.getRuntimePeriod() != null && entity.getRuntimePeriod().getStart() != null) { LocalDateTime startDate = new LocalDateTime(entity.getRuntimePeriod().getStart()); result.put("startDate", ISO_DATE_FORMATTER.print(startDate)); }/*from w w w . j av a 2 s .c o m*/ if (entity.getRuntimePeriod() != null && entity.getRuntimePeriod().getEnd() != null) { LocalDateTime endDate = new LocalDateTime(entity.getRuntimePeriod().getEnd()); result.put("endDate", ISO_DATE_FORMATTER.print(endDate)); } if (entity.getParent() != null) { String parentUri = URLBuilder.getEntityURL(entity.getParent(), req, URLBuilder.EntityRepresentation.JSON); result.put("parentUri", parentUri); } AttributesComponentModel attributesModel = new AttributesComponentModel(ComponentMode.READ, "") { private static final long serialVersionUID = 1L; @Override public boolean showATG(AttributeTypeGroup atg) { return true; } }; attributesModel.initializeFrom(entity); result.put("attributes", attributesModel.getAtgParts()); Set<String> buURIs = Sets.newTreeSet(); for (BusinessMapping bm : entity.getBusinessMappings()) { if (bm.getBusinessUnit() != null) { buURIs.add( URLBuilder.getEntityURL(bm.getBusinessUnit(), req, URLBuilder.EntityRepresentation.JSON)); } } if (!buURIs.isEmpty()) { result.put("connectedBusinessUnits", buURIs); } return result; }
From source file:com.cloudera.whirr.cm.CmServerClusterInstance.java
public static Map<String, String> getDeviceMappings(ClusterSpec specification, Set<Instance> instances) { Map<String, String> deviceMappings = new HashMap<String, String>(); if (specification != null && instances != null && !instances.isEmpty()) { deviceMappings//www .j a v a 2s.com .putAll(new VolumeManager().getDeviceMappings(specification, instances.iterator().next())); } return deviceMappings; }
From source file:models.NotificationMail.java
/** * Sends notification mails for the given event. * * @param event/*from ww w. ja v a 2 s. c om*/ * @see <a href="https://github.com/nforge/yobi/blob/master/docs/technical/watch.md>watch.md</a> */ private static void sendNotification(NotificationEvent event) { Set<User> receivers = event.receivers; // Remove inactive users. Iterator<User> iterator = receivers.iterator(); while (iterator.hasNext()) { User user = iterator.next(); if (user.state != UserState.ACTIVE) { iterator.remove(); } } receivers.remove(User.anonymous); if (receivers.isEmpty()) { return; } HashMap<String, List<User>> usersByLang = new HashMap<>(); for (User receiver : receivers) { String lang = receiver.lang; if (lang == null) { lang = Locale.getDefault().getLanguage(); } if (usersByLang.containsKey(lang)) { usersByLang.get(lang).add(receiver); } else { usersByLang.put(lang, new ArrayList<>(Arrays.asList(receiver))); } } for (String langCode : usersByLang.keySet()) { final EventEmail email = new EventEmail(event); try { if (hideAddress) { email.setFrom(Config.getEmailFromSmtp(), event.getSender().name); email.addTo(Config.getEmailFromSmtp(), utils.Config.getSiteName()); } else { email.setFrom(event.getSender().email, event.getSender().name); } for (User receiver : usersByLang.get(langCode)) { if (hideAddress) { email.addBcc(receiver.email, receiver.name); } else { email.addTo(receiver.email, receiver.name); } } if (email.getToAddresses().isEmpty()) { continue; } Lang lang = Lang.apply(langCode); String message = event.getMessage(lang); String urlToView = event.getUrlToView(); String reference = Url.removeFragment(event.getUrlToView()); email.setSubject(event.title); Resource resource = event.getResource(); if (resource.getType() == ResourceType.ISSUE_COMMENT) { IssueComment issueComment = IssueComment.find.byId(Long.valueOf(resource.getId())); resource = issueComment.issue.asResource(); } email.setHtmlMsg(getHtmlMessage(lang, message, urlToView, resource)); email.setTextMsg(getPlainMessage(lang, message, Url.create(urlToView))); email.setCharset("utf-8"); email.addReferences(); email.setSentDate(event.created); Mailer.send(email); String escapedTitle = email.getSubject().replace("\"", "\\\""); String logEntry = String.format("\"%s\" %s", escapedTitle, email.getBccAddresses()); play.Logger.of("mail").info(logEntry); } catch (Exception e) { Logger.warn("Failed to send a notification: " + email + "\n" + ExceptionUtils.getStackTrace(e)); } } }
From source file:com.netflix.genie.web.controllers.RestControllerIntegrationTestBase.java
private static String getLinkedResourceExpectedUri(final String entityApi, final String entityId, @Nullable final Set<String> optionalHalParams, final String linkedEntityType) { final String uriPath = entityApi + "/" + entityId + "/" + linkedEntityType; // Append HAL parameters separately to avoid URI encoding final StringBuilder halParamsStringBuilder = new StringBuilder(); if (optionalHalParams != null && !optionalHalParams.isEmpty()) { halParamsStringBuilder.append("{?").append(StringUtils.join(optionalHalParams, ",")).append("}"); }/* w w w . ja v a 2s . com*/ return uriPath + halParamsStringBuilder.toString(); }
From source file:edu.jhuapl.openessence.web.util.ControllerUtils.java
/** * Check if the specified user is authorized to access the given data source. * * @param authentication user's authentication *///from w ww. j a v a2s . c om public static boolean isUserAuthorized(Authentication authentication, JdbcOeDataSource ds) { Set<String> roles = ds.getRoles(); if (roles == null || roles.isEmpty()) { return true; } for (GrantedAuthority eachAuthority : authentication.getAuthorities()) { if (roles.contains(eachAuthority.toString())) { return true; } } return false; }
From source file:edu.wpi.checksims.algorithm.smithwaterman.SmithWatermanAlgorithm.java
/** * Get the closest coordinate to the origin from a given set. * * @param coordinates Coordinates to search within * @return Closest coordinate to origin --- (0,0) *//* ww w. j ava 2 s. c o m*/ static Coordinate getFirstMatchCoordinate(Set<Coordinate> coordinates) { checkNotNull(coordinates); checkArgument(!coordinates.isEmpty(), "Cannot get first match coordinate as match set is empty!"); if (coordinates.size() == 1) { return Iterables.get(coordinates, 0); } Coordinate candidate = Iterables.get(coordinates, 0); // Search for a set of coordinates closer to the origin for (Coordinate coord : coordinates) { if (coord.getX() <= candidate.getX() && coord.getY() <= candidate.getY()) { candidate = coord; } } return candidate; }
From source file:com.vmware.bdd.utils.CommonUtil.java
public static String inputsConvert(Set<String> words) { String newWordStr = ""; if (words != null && !words.isEmpty()) { StringBuffer wordsBuff = new StringBuffer(); for (String word : words) { wordsBuff.append(word).append(","); }/*from w w w . j a v a 2s . com*/ wordsBuff.delete(wordsBuff.length() - 1, wordsBuff.length()); newWordStr = wordsBuff.toString(); } return newWordStr; }
From source file:com.google.gsa.valve.modules.krb.KerberosAuthenticationProcess.java
/** * Gets the main principal from the user subject got as a result * of the Kerberos authentication process * //from www. j av a 2 s.com * @param subject user subject * * @return the user principal */ public static String getPrincipalStr(Subject subject) { String principal = null; logger.debug("Getting principal from Subject"); try { Set principals = subject.getPrincipals(); if (!principals.isEmpty()) { logger.debug("Subject contains at least one Principal"); Iterator it = principals.iterator(); if (it.hasNext()) { Principal ppal = (Principal) it.next(); principal = ppal.getName().substring(0, ppal.getName().indexOf("@")); logger.debug("Getting the first principal: " + principal); } } } catch (Exception e) { logger.error("Error retrieving the client's Principal from the Subject: " + e.getMessage(), e); } return principal; }
From source file:com.amalto.core.storage.inmemory.InMemoryJoinResults.java
private static Set<Object> _evaluateConditions(Storage storage, InMemoryJoinNode node) { if (node.expression != null) { Set<Object> expressionIds = new HashSet<Object>(); StorageResults results = storage.fetch(node.expression); // Expects an active transaction here try {// w w w .j a v a 2 s . c o m for (DataRecord result : results) { for (FieldMetadata field : result.getSetFields()) { expressionIds.add(result.get(field)); } } } finally { results.close(); } return expressionIds; } else { Executor executor = getExecutor(node); Set<Object> ids = new HashSet<Object>(); switch (node.merge) { case UNION: case NONE: for (InMemoryJoinNode child : node.children.keySet()) { ids.addAll(executor.execute(storage, child)); } break; case INTERSECTION: for (InMemoryJoinNode child : node.children.keySet()) { if (ids.isEmpty()) { ids.addAll(executor.execute(storage, child)); } else { ids.retainAll(executor.execute(storage, child)); } } break; default: throw new NotImplementedException("No support for '" + node.merge + "'."); } // Set<Object> returnIds = new HashSet<Object>(); if (node.childProperty != null) { if (ids.isEmpty()) { return Collections.emptySet(); } long execTime = System.currentTimeMillis(); { UserQueryBuilder qb = from(node.type).selectId(node.type) .where(buildConditionFromValues(null, node.childProperty, ids)); node.expression = qb.getSelect(); StorageResults results = storage.fetch(qb.getSelect()); // Expects an active transaction here try { for (DataRecord result : results) { for (FieldMetadata field : result.getSetFields()) { returnIds.add(result.get(field)); } } } finally { results.close(); } } node.execTime = System.currentTimeMillis() - execTime; } return returnIds; } }
From source file:com.netflix.genie.server.repository.jpa.ApplicationSpecs.java
/** * Get a specification using the specified parameters. * * @param name The name of the application * @param userName The name of the user who created the application * @param statuses The status of the application * @param tags The set of tags to search the command for * @return A specification object used for querying *//*from w w w . ja v a2 s . c om*/ public static Specification<Application> find(final String name, final String userName, final Set<ApplicationStatus> statuses, final Set<String> tags) { return new Specification<Application>() { @Override public Predicate toPredicate(final Root<Application> root, final CriteriaQuery<?> cq, final CriteriaBuilder cb) { final List<Predicate> predicates = new ArrayList<>(); if (StringUtils.isNotBlank(name)) { predicates.add(cb.equal(root.get(Application_.name), name)); } if (StringUtils.isNotBlank(userName)) { predicates.add(cb.equal(root.get(Application_.user), userName)); } if (statuses != null && !statuses.isEmpty()) { //Could optimize this as we know size could use native array final List<Predicate> orPredicates = new ArrayList<>(); for (final ApplicationStatus status : statuses) { orPredicates.add(cb.equal(root.get(Application_.status), status)); } predicates.add(cb.or(orPredicates.toArray(new Predicate[orPredicates.size()]))); } if (tags != null) { for (final String tag : tags) { if (StringUtils.isNotBlank(tag)) { predicates.add(cb.isMember(tag, root.get(Application_.tags))); } } } return cb.and(predicates.toArray(new Predicate[predicates.size()])); } }; }