List of usage examples for java.util Set isEmpty
boolean isEmpty();
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. * @param exprProcessor - processes each input event and returns output event * @param events - input events//from ww w .j a va 2 s . co m * @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 * @return output events, one for each input event */ protected static EventBean[] getSelectEventsNoHaving(SelectExprProcessor exprProcessor, Set<MultiKey<EventBean>> events, boolean isNewData, boolean isSynthesize, ExprEvaluatorContext exprEvaluatorContext) { if ((events == null) || (events.isEmpty())) { return null; } int length = events.size(); EventBean[] result = new EventBean[length]; int count = 0; for (MultiKey<EventBean> key : events) { EventBean[] eventsPerStream = key.getArray(); result[count] = exprProcessor.process(eventsPerStream, isNewData, isSynthesize, exprEvaluatorContext); count++; } return result; }
From source file:net.lldp.checksims.ChecksimsCommandLine.java
/** * Parse basic CLI flags and produce a ChecksimsConfig. * * @param cli Parsed command line/*w w w .j a v a 2 s . c o m*/ * @return Config derived from parsed CLI * @throws ChecksimsException Thrown on invalid user input or internal error */ static ChecksimsConfig parseBaseFlags(CommandLine cli) throws ChecksimsException { checkNotNull(cli); // If we don't have a logger, set one up if (logs == null) { logs = LoggerFactory.getLogger(ChecksimsCommandLine.class); } // Create a base config to work from ChecksimsConfig config = new ChecksimsConfig(); // Parse plagiarism detection algorithm if (cli.hasOption("a")) { config = config.setAlgorithm( AlgorithmRegistry.getInstance().getImplementationInstance(cli.getOptionValue("a"))); config = config.setTokenization(config.getAlgorithm().getPercentableCalculator()); } // Parse tokenization if (cli.hasOption("t")) { config = config.setTokenization(SubmissionPercentableCalculator.fromString(cli.getOptionValue("t"))); } // Parse number of threads to use if (cli.hasOption("j")) { int numThreads = Integer.parseInt(cli.getOptionValue("j")); if (numThreads < 1) { throw new ChecksimsException("Thread count must be positive!"); } config = config.setNumThreads(numThreads); } if (cli.hasOption("ignoreInvalid")) { config = config.ignoreInvalid(); } // Parse preprocessors // Ensure no duplicates if (cli.hasOption("p")) { List<SubmissionPreprocessor> preprocessors = SetUniqueList.setUniqueList(new ArrayList<>()); String[] preprocessorsToUse = cli.getOptionValues("p"); for (String s : preprocessorsToUse) { SubmissionPreprocessor p = PreprocessorRegistry.getInstance().getImplementationInstance(s); preprocessors.add(p); } config = config.setPreprocessors(preprocessors); } // Parse output strategies // Ensure no duplicates if (cli.hasOption("o")) { String[] desiredStrategies = cli.getOptionValues("o"); Set<String> deduplicatedStrategies = new HashSet<>(Arrays.asList(desiredStrategies)); if (deduplicatedStrategies.isEmpty()) { throw new ChecksimsException("Error: did not obtain a valid output strategy!"); } // Convert to MatrixPrinters Set<MatrixPrinter> printers = new HashSet<>(); for (String name : deduplicatedStrategies) { printers.add(MatrixPrinterRegistry.getInstance().getImplementationInstance(name)); } config = config.setOutputPrinters(printers); } return config; }
From source file:com.netflix.genie.core.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 ww w . jav a 2 s .co m public static Specification<CommandEntity> find(final String name, final String user, final Set<CommandStatus> statuses, final Set<String> 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()) { final List<Predicate> orPredicates = statuses.stream() .map(status -> cb.equal(root.get(CommandEntity_.status), status)) .collect(Collectors.toList()); predicates.add(cb.or(orPredicates.toArray(new Predicate[orPredicates.size()]))); } if (tags != null && !tags.isEmpty()) { predicates .add(cb.like(root.get(CommandEntity_.tags), JpaSpecificationUtils.getTagLikeString(tags))); } return cb.and(predicates.toArray(new Predicate[predicates.size()])); }; }
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. * @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/*w w w . j a v a 2 s .com*/ * @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[] getSelectEventsNoHaving(SelectExprProcessor exprProcessor, OrderByProcessor orderByProcessor, Set<MultiKey<EventBean>> events, boolean isNewData, boolean isSynthesize, ExprEvaluatorContext exprEvaluatorContext) { if ((events == null) || (events.isEmpty())) { return null; } int length = events.size(); EventBean[] result = new EventBean[length]; EventBean[][] eventGenerators = null; if (orderByProcessor != null) { eventGenerators = new EventBean[length][]; } int count = 0; for (MultiKey<EventBean> key : events) { EventBean[] eventsPerStream = key.getArray(); result[count] = exprProcessor.process(eventsPerStream, isNewData, isSynthesize, exprEvaluatorContext); if (orderByProcessor != null) { eventGenerators[count] = eventsPerStream; } count++; } if (orderByProcessor != null) { return orderByProcessor.sort(result, eventGenerators, isNewData, exprEvaluatorContext); } else { return result; } }
From source file:de.iteratec.iteraplan.businesslogic.reports.query.postprocessing.HideSubInformationSystemReleasesWithConnectionMergingStrategy.java
/** * Merges to sets of transports.// w w w. j av a 2s . c o m * * @param transports1 * Transport set 1. * @param transports2 * Transport set 2. * @param symetricMerge * The transports are symmetric. * @return The merged transports. */ private static Set<Transport> mergeTransports(Set<Transport> transports1, Set<Transport> transports2, boolean symetricMerge) { LOGGER.debug("merging transports {0} and {1}", transports1, transports2); if ((transports1 == null) || transports1.isEmpty()) { return transports2; } if ((transports2 == null) || transports2.isEmpty()) { return transports1; } Map<Integer, Transport> newTransports = createNewTransportsMapFromTransportSet(transports1); for (Transport transport : transports2) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("(bo2: {0})", transport.getBusinessObject().getId()); } Transport existingTransport = newTransports.get(transport.getBusinessObject().getId()); if (existingTransport != null) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("transports to be merged carried same bo {0}", transport.getBusinessObject().getName()); } setNewDirectionsForExistingTransport(transport, existingTransport, symetricMerge); } else { LOGGER.debug("transports to be merged did not carry same bo"); setNewDirectionsForNewTransport(symetricMerge, transport); newTransports.put(transport.getBusinessObject().getId(), transport); } } if (LOGGER.isDebugEnabled()) { LOGGER.debug("done merging transports: {0}", newTransports.values()); } return new HashSet<Transport>(newTransports.values()); }
From source file:com.netflix.genie.server.repository.jpa.CommandSpecs.java
/** * Get a specification using the specified parameters. * * @param name The name of the command * @param userName 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 *///www . j av a 2s.c om public static Specification<Command> find(final String name, final String userName, final Set<CommandStatus> statuses, final Set<String> tags) { return new Specification<Command>() { @Override public Predicate toPredicate(final Root<Command> root, final CriteriaQuery<?> cq, final CriteriaBuilder cb) { final List<Predicate> predicates = new ArrayList<>(); if (StringUtils.isNotBlank(name)) { predicates.add(cb.equal(root.get(Command_.name), name)); } if (StringUtils.isNotBlank(userName)) { predicates.add(cb.equal(root.get(Command_.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 CommandStatus status : statuses) { orPredicates.add(cb.equal(root.get(Command_.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(Command_.tags))); } } } return cb.and(predicates.toArray(new Predicate[predicates.size()])); } }; }
From source file:grails.plugin.springsecurity.SpringSecurityUtils.java
public static boolean ifNotGranted(final Collection<? extends GrantedAuthority> roles) { Collection<? extends GrantedAuthority> inferred = findInferredAuthorities(getPrincipalAuthorities()); Set<String> grantedCopy = retainAll(inferred, roles); return grantedCopy.isEmpty(); }
From source file:module.signature.util.XAdESValidator.java
private static void validateSigner(Document document, Set<User> usersPermitted, Set<User> usersExcluded, boolean allUsersPermittedShouldBeThere) throws SignatureDataException { if (!allUsersPermittedShouldBeThere || ((usersExcluded != null) && !usersExcluded.isEmpty())) { //TODO implement it when needed throw new DomainException("method.not.yet.implemented"); }//w ww . j av a 2 s . c om final String ID_NR_PREFIX = "OID.2.5.4.5=BI"; ArrayList<String> usersPermittedIdNumbers = new ArrayList<String>(); for (User user : usersPermitted) { usersPermittedIdNumbers.add(user.getPerson().getRemotePerson().getDocumentIdNumber()); } //let's extract each signature // XMLDSIG NodeList nlSignature = document.getElementsByTagNameNS("http://www.w3.org/2000/09/xmldsig#", "Signature"); //DEBUG System.out.println("Got " + nlSignature.getLength() + " signatures"); if (nlSignature.getLength() < 1) { throw new SignatureException("could.not.find.a.signature.in.incoming.data", true, null); } HashSet<String> usersFoundIdNumbers = new HashSet<String>(); for (int i = 0; i < nlSignature.getLength(); i++) { //for each signature, let's extract the ID number of who did it Element signature = (Element) nlSignature.item(i); try { XMLSignature xmlSig = new XMLSignature(signature, null); KeyInfo ki = xmlSig.getKeyInfo(); String certificateIDNr = ki.getX509Certificate().getSubjectX500Principal().getName("RFC1779"); certificateIDNr = certificateIDNr .substring(certificateIDNr.indexOf(ID_NR_PREFIX) + ID_NR_PREFIX.length()); //let's take out the virgul and the last character, which is a control one certificateIDNr = certificateIDNr.substring(0, certificateIDNr.indexOf(',') - 1); usersFoundIdNumbers.add(certificateIDNr); } catch (XMLSignatureException e) { e.printStackTrace(); throw new SignatureDataException("signature.error.XMLSignatureExceptionError", e); } catch (XMLSecurityException e) { throw new SignatureDataException("signature.error.XMLSecurityException", e); } } //now let's validate the extracted info if (allUsersPermittedShouldBeThere && usersFoundIdNumbers.containsAll(usersPermittedIdNumbers)) { return; //TODO TODO URGENT uncomment the next two lines (just made possible to be able to test it!!) } else { throw new SignatureDataException("wrong.document.signer"); } //TODO the rest of the use cases aren't implemented ATM }
From source file:grails.plugin.springsecurity.SpringSecurityUtils.java
public static boolean ifAnyGranted(final Collection<? extends GrantedAuthority> roles) { Collection<? extends GrantedAuthority> inferred = findInferredAuthorities(getPrincipalAuthorities()); Set<String> grantedCopy = retainAll(inferred, roles); return !grantedCopy.isEmpty(); }
From source file:com.netflix.genie.core.jpa.specifications.JpaApplicationSpecs.java
/** * Get a specification using the specified parameters. * * @param name The name of the application * @param user 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 * @param type The type of applications to fine * @return A specification object used for querying *///ww w. j a v a2s . c o m public static Specification<ApplicationEntity> find(final String name, final String user, final Set<ApplicationStatus> statuses, final Set<String> tags, final String type) { return (final Root<ApplicationEntity> root, final CriteriaQuery<?> cq, final CriteriaBuilder cb) -> { final List<Predicate> predicates = new ArrayList<>(); if (StringUtils.isNotBlank(name)) { predicates.add(JpaSpecificationUtils.getStringLikeOrEqualPredicate(cb, root.get(ApplicationEntity_.name), name)); } if (StringUtils.isNotBlank(user)) { predicates.add(JpaSpecificationUtils.getStringLikeOrEqualPredicate(cb, root.get(ApplicationEntity_.user), user)); } if (statuses != null && !statuses.isEmpty()) { final List<Predicate> orPredicates = statuses.stream() .map(status -> cb.equal(root.get(ApplicationEntity_.status), status)) .collect(Collectors.toList()); predicates.add(cb.or(orPredicates.toArray(new Predicate[orPredicates.size()]))); } if (tags != null && !tags.isEmpty()) { predicates.add( cb.like(root.get(ApplicationEntity_.tags), JpaSpecificationUtils.getTagLikeString(tags))); } if (StringUtils.isNotBlank(type)) { predicates.add(JpaSpecificationUtils.getStringLikeOrEqualPredicate(cb, root.get(ApplicationEntity_.type), type)); } return cb.and(predicates.toArray(new Predicate[predicates.size()])); }; }