List of usage examples for java.util Set isEmpty
boolean isEmpty();
From source file:de.metas.ui.web.quickinput.QuickInputDescriptorFactoryService.java
private static Map<IQuickInputDescriptorFactory.MatchingKey, IQuickInputDescriptorFactory> createFactoriesFromContext( final ApplicationContext context) { final ImmutableMap.Builder<IQuickInputDescriptorFactory.MatchingKey, IQuickInputDescriptorFactory> factories = ImmutableMap .builder();//from w w w. jav a2 s . co m for (final IQuickInputDescriptorFactory factory : context.getBeansOfType(IQuickInputDescriptorFactory.class) .values()) { final Set<IQuickInputDescriptorFactory.MatchingKey> matchingKeys = factory.getMatchingKeys(); if (matchingKeys == null || matchingKeys.isEmpty()) { logger.warn("Ignoring {} because it provides no matching keys", factory); break; } for (final IQuickInputDescriptorFactory.MatchingKey matchingKey : matchingKeys) { factories.put(matchingKey, factory); } } return factories.build(); }
From source file:com.github.javarch.jsf.tags.security.SpringSecurityELLibrary.java
/** * Method that checks if the user holds <b>all</b> of the given roles. * Returns <code>true</code>, iff the user holds all roles, <code>false</code> if no roles are given or * the first non-matching role is found//from w ww . j ava 2s .co m * * @param requiredRoles a comma seperated list of roles * @return true if all of the given roles are granted to the current user, false otherwise or if no * roles are specified at all. */ public static boolean ifAllGranted(final String requiredRoles) { // parse required roles into list Set<String> requiredAuthorities = parseAuthorities(requiredRoles); if (requiredAuthorities.isEmpty()) return false; // get granted roles GrantedAuthority[] authoritiesArray = getUserAuthorities(); Set<String> grantedAuthorities = new TreeSet<String>(); for (GrantedAuthority authority : authoritiesArray) { grantedAuthorities.add(authority.getAuthority()); } // iterate over required roles, for (String requiredAuthority : requiredAuthorities) { // check if required role is inside granted roles // if not, return false if (!grantedAuthorities.contains(requiredAuthority)) { return false; } } return true; }
From source file:com.doculibre.constellio.utils.izpack.UsersXmlFileUtils.java
private static Element toXmlElement(ConstellioUser constellioUser) { BaseElement user = new BaseElement(USER); user.addAttribute(FIRST_NAME, constellioUser.getFirstName()); user.addAttribute(LAST_NAME, constellioUser.getLastName()); user.addAttribute(LOGIN, constellioUser.getUsername()); user.addAttribute(PASSWORD_HASH, constellioUser.getPasswordHash()); if (constellioUser.getLocale() != null) { user.addAttribute(LOCALE, constellioUser.getLocaleCode()); }/*from ww w.jav a 2 s. c o m*/ Set<String> constellioRoles = constellioUser.getRoles(); if (!constellioRoles.isEmpty()) { Element roles = user.addElement(ROLES); for (String constellioRole : constellioRoles) { Element role = roles.addElement(ROLE); role.addAttribute(VALUE, constellioRole); } } return user; }
From source file:io.cloudex.framework.utils.ObjectUtils.java
/** * check if this instance is valid//from ww w . j a v a 2s. c om * @param classOfT - class of the object to validate * @param object - the object to validate * @return true if valid, false otherwise */ public static <T> boolean isValid(Class<T> classOfT, T object) { Set<ConstraintViolation<T>> violations = ObjectUtils.VALIDATOR.validate(object); return violations.isEmpty(); }
From source file:app.core.PersistenceTest.java
private static <T extends PersistentObject> T buildRecursively(T newInstance) throws Exception { Set<ConstraintViolation<T>> constraintViolations = validate(newInstance); if (constraintViolations.isEmpty()) return newInstance; // the instance is finished building for (ConstraintViolation constraintViolation : constraintViolations) { Object missingProperty;//ww w. j av a 2 s .c om Field violatedField = ReflectionUtils.getField(constraintViolation.getRootBeanClass(), constraintViolation.getPropertyPath().toString()); if (NotNull.class .isAssignableFrom(constraintViolation.getConstraintDescriptor().getAnnotation().getClass())) { if (PersistentObject.class.isAssignableFrom(violatedField.getType())) { // similar to instanceof missingProperty = newInstance((Class<PersistentObject>) violatedField.getType()); //recursion here ((PersistentObject) missingProperty).save(); // save the dependency } else { missingProperty = violatedField.getType().newInstance(); // just create a non-null property } ReflectionUtils.setFieldValue(newInstance, violatedField.getName(), missingProperty); } else if (Length.class .isAssignableFrom(constraintViolation.getConstraintDescriptor().getAnnotation().getClass())) { // TODO: implement correctly ReflectionUtils.setFieldValue(newInstance, violatedField.getName(), "0123456789"); } // TODO: support more annotations } return buildRecursively(newInstance); }
From source file:edu.harvard.med.lincs.screensaver.io.libraries.ReagentAttachmentImporter.java
private static void execute(final ReagentAttachmentImporter app) { final GenericEntityDAO dao = (GenericEntityDAO) app.getSpringBean("genericEntityDao"); final LibrariesDAO librariesDao = (LibrariesDAO) app.getSpringBean("librariesDao"); dao.doInTransaction(new DAOTransaction() { @Override//from ww w .j a v a 2 s . c om public void runTransaction() { String fileName = app.getCommandLineOptionValue(OPTION_INPUT_FILE[SHORT_OPTION_INDEX]); String facilityId = app.getCommandLineOptionValue(OPTION_INPUT_FACILITY_ID[SHORT_OPTION_INDEX]); Integer saltId = app.getCommandLineOptionValue(OPTION_INPUT_SALT_ID[SHORT_OPTION_INDEX], Integer.class); Integer batchId = app.getCommandLineOptionValue(OPTION_INPUT_BATCH_ID[SHORT_OPTION_INDEX], Integer.class); String attachmentType = app.getCommandLineOptionValue( OPTION_INPUT_QC_ATTACMENT_TYPE[SHORT_OPTION_INDEX], String.class); if (!attachmentTypes.contains(attachmentType)) { log.error( "unknown attachment type: " + attachmentType + ", must be one of: " + attachmentTypes); System.exit(1); } File file = new File(fileName); if (!file.exists()) { log.error("file does not exist: " + fileName); System.exit(1); } Set<SmallMoleculeReagent> reagents = librariesDao.findReagents(facilityId, saltId, batchId, true); if (reagents.isEmpty()) { log.error("no reagents found!"); System.exit(1); } ReagentAttachedFileType attachedFileType = dao.findEntityByProperty(ReagentAttachedFileType.class, "value", attachmentType); if (attachedFileType == null) { log.error("Could not find the attached file type: " + attachmentType + ", make sure that this value has been created in the database table."); System.exit(1); } for (SmallMoleculeReagent reagent : reagents) { try { AttachedFile attachedFile1 = reagent.createAttachedFile(file.getName(), attachedFileType, null, new FileInputStream(fileName)); dao.saveOrUpdateEntity(attachedFile1); dao.saveOrUpdateEntity(reagent); } catch (IOException e) { throw new DAOTransactionRollbackException("File not found: " + fileName, e); } } log.info("saved attachment for reagent(s): "); for (SmallMoleculeReagent reagent : reagents) { log.info("\tattached to:" + reagent.getWell().getWellKey() + ": " + reagent.getWell().getFacilityId() + "-" + reagent.getSaltFormId() + "-" + reagent.getFacilityBatchId()); } } }); }
From source file:fr.paris.lutece.plugins.extend.util.ExtendUtils.java
/** * Builds the stop message.//from ww w . ja va2s .c om * * @param <A> the generic type * @param listErrors the list errors * @return the string */ public static <A> String buildStopMessage(Set<ConstraintViolation<A>> listErrors) { StringBuilder sbError = new StringBuilder(); if ((listErrors != null) && !listErrors.isEmpty()) { for (ConstraintViolation<A> error : listErrors) { sbError.append(error.getMessage()); sbError.append(HTML_BR); } } return sbError.toString(); }
From source file:cop.raml.utils.Utils.java
/** * Converts enum constants as array {@code arr} to enum string without any duplication. * * @param arr array of enum items/*ww w . ja v a 2 s .co m*/ * @return {@code null} or not empty enum string (e.g. [one,two]) */ public static String toEnumStr(String... arr) { Set<String> res = asSet(arr); return res.isEmpty() ? null : res.stream().collect(Collectors.joining(",", "[", "]")); }
From source file:info.magnolia.importexport.Bootstrapper.java
/** * Bootstrap a specific repository./*from w w w. j av a 2 s.c om*/ */ public static boolean bootstrapRepository(String[] bootdirs, String repositoryName, BootstrapFilter filter) { Set<File> xmlfileset = getBootstrapFiles(bootdirs, repositoryName, filter); if (xmlfileset.isEmpty()) { log.debug("No bootstrap files found for repository [{}], skipping...", repositoryName); return true; } log.info("Trying to import content from {} files into repository [{}]", Integer.toString(xmlfileset.size()), repositoryName); final File[] files = xmlfileset.toArray(new File[xmlfileset.size()]); return bootstrapFiles(repositoryName, files); }
From source file:musite.prediction.feature.InstanceUtil.java
private static String extractMarkedPeptide(Protein protein, PTM ptm, int start, int end) { Set<Integer> sites = PTMAnnotationUtil.getSites(protein, ptm); String seq = protein.getSequence(); if (sites == null || sites.isEmpty()) { return seq.substring(start, end); }/*from www . j av a 2s . com*/ StringBuilder sb = new StringBuilder(); int s = start; for (int site : sites) { if (site >= start && site < end) { int t = site; sb.append(seq.substring(s, t + 1)); sb.append("#"); s = site + 1; } } if (s < end) { sb.append(seq.substring(s, end)); } return sb.toString(); }