List of usage examples for java.util Set iterator
Iterator<E> iterator();
From source file:org.zkoss.spring.security.SecurityUtil.java
private static Set rolesToAuthorities(Set grantedRoles, Collection granted) { Set target = new HashSet(); for (Iterator iterator = grantedRoles.iterator(); iterator.hasNext();) { String role = (String) iterator.next(); for (Iterator grantedIterator = granted.iterator(); grantedIterator.hasNext();) { GrantedAuthority authority = (GrantedAuthority) grantedIterator.next(); if (authority.getAuthority().equals(role)) { target.add(authority);/*from w w w . ja va 2 s .c o m*/ break; } } } return target; }
From source file:org.apache.ofbiz.solr.SolrUtil.java
public static SolrInputDocument generateSolrDocument(Map<String, Object> context) throws GenericEntityException { SolrInputDocument doc1 = new SolrInputDocument(); // add defined attributes for (int i = 0; i < solrProdAttribute.length; i++) { if (context.get(solrProdAttribute[i]) != null) { doc1.addField(solrProdAttribute[i], context.get(solrProdAttribute[i]).toString()); }//from www. j a v a 2s .c om } // add catalog if (context.get("catalog") != null) { List<String> catalog = UtilGenerics.<String>checkList(context.get("catalog")); for (String c : catalog) { doc1.addField("catalog", c); } } // add categories if (context.get("category") != null) { List<String> category = UtilGenerics.<String>checkList(context.get("category")); Iterator<String> catIter = category.iterator(); while (catIter.hasNext()) { String cat = (String) catIter.next(); doc1.addField("cat", cat); } } // add features if (context.get("features") != null) { Set<String> features = UtilGenerics.<String>checkSet(context.get("features")); Iterator<String> featIter = features.iterator(); while (featIter.hasNext()) { String feat = featIter.next(); doc1.addField("features", feat); } } // add attributes if (context.get("attributes") != null) { List<String> attributes = UtilGenerics.<String>checkList(context.get("attributes")); Iterator<String> attrIter = attributes.iterator(); while (attrIter.hasNext()) { String attr = attrIter.next(); doc1.addField("attributes", attr); } } // add title if (context.get("title") != null) { Map<String, String> title = UtilGenerics.<String, String>checkMap(context.get("title")); for (Map.Entry<String, String> entry : title.entrySet()) { doc1.addField("title_i18n_" + entry.getKey(), entry.getValue()); } } // add short_description if (context.get("description") != null) { Map<String, String> description = UtilGenerics.<String, String>checkMap(context.get("description")); for (Map.Entry<String, String> entry : description.entrySet()) { doc1.addField("description_i18n_" + entry.getKey(), entry.getValue()); } } // add short_description if (context.get("longDescription") != null) { Map<String, String> longDescription = UtilGenerics .<String, String>checkMap(context.get("longDescription")); for (Map.Entry<String, String> entry : longDescription.entrySet()) { doc1.addField("longdescription_i18n_" + entry.getKey(), entry.getValue()); } } return doc1; }
From source file:ca.on.oicr.pde.deciders.GenomicAlignmentNovoalignDecider.java
public static String _join(String separator, Set items) { StringBuffer result = new StringBuffer(); Iterator myItems = items.iterator(); while (myItems.hasNext()) { if (result.length() > 0) { result.append(separator);/*w ww. j a v a 2 s . co m*/ } result.append(myItems.next().toString()); } return result.toString(); }
From source file:models.NotificationMail.java
/** * Sends notification mails for the given event. * * @param event/*w ww . 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.android.launcher3.InstallShortcutReceiver.java
public static void removeFromInstallQueue(Context context, ArrayList<String> packageNames, UserHandleCompat user) {/*from w ww .j a va2 s .c o m*/ if (packageNames.isEmpty()) { return; } String spKey = LauncherAppState.getSharedPreferencesKey(); SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE); synchronized (sLock) { Set<String> strings = sp.getStringSet(APPS_PENDING_INSTALL, null); if (DBG) { Log.d(TAG, "APPS_PENDING_INSTALL: " + strings + ", removing packages: " + packageNames); } if (strings != null) { Set<String> newStrings = new HashSet<String>(strings); Iterator<String> newStringsIter = newStrings.iterator(); while (newStringsIter.hasNext()) { String encoded = newStringsIter.next(); PendingInstallShortcutInfo info = decode(encoded, context); if (info == null || (packageNames.contains(info.getTargetPackage()) && user.equals(info.user))) { newStringsIter.remove(); } } sp.edit().putStringSet(APPS_PENDING_INSTALL, newStrings).commit(); } } }
From source file:com.cyberway.issue.crawler.datamodel.credential.Rfc2617Credential.java
/** * Convenience method that does look up on passed set using realm for key. * * @param rfc2617Credentials Set of Rfc2617 credentials. If passed set is * not pure Rfc2617Credentials then will be ClassCastExceptions. * @param realm Realm to find in passed set. * @param context Context to use when searching the realm. * @return Credential of passed realm name else null. If more than one * credential w/ passed realm name, and there shouldn't be, we return first * found./*from w w w . ja v a2 s . co m*/ */ public static Rfc2617Credential getByRealm(Set rfc2617Credentials, String realm, CrawlURI context) { Rfc2617Credential result = null; if (rfc2617Credentials == null || rfc2617Credentials.size() <= 0) { return result; } if (rfc2617Credentials != null && rfc2617Credentials.size() > 0) { for (Iterator i = rfc2617Credentials.iterator(); i.hasNext();) { Rfc2617Credential c = (Rfc2617Credential) i.next(); try { if (c.getRealm(context).equals(realm)) { result = c; break; } } catch (AttributeNotFoundException e) { logger.severe("Failed look up by realm " + realm + " " + e); } } } return result; }
From source file:com.stv.launcher.receiver.InstallShortcutReceiver.java
public static void removeFromInstallQueue(Context context, ArrayList<String> packageNames, UserHandleCompat user) {//from ww w. j a va2 s . co m if (packageNames.isEmpty()) { return; } String spKey = LauncherState.getSharedPreferencesKey(); SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE); synchronized (sLock) { Set<String> strings = sp.getStringSet(APPS_PENDING_INSTALL, null); if (DBG) { Log.d(TAG, "APPS_PENDING_INSTALL: " + strings + ", removing packages: " + packageNames); } if (strings != null) { Set<String> newStrings = new HashSet<String>(strings); Iterator<String> newStringsIter = newStrings.iterator(); while (newStringsIter.hasNext()) { String encoded = newStringsIter.next(); PendingInstallShortcutInfo info = decode(encoded, context); if (info == null || (packageNames.contains(info.getTargetPackage()) && user.equals(info.user))) { newStringsIter.remove(); } } sp.edit().putStringSet(APPS_PENDING_INSTALL, newStrings).commit(); } } }
From source file:it.univpm.deit.semedia.musicuri.utils.experimental.LambdaCalculator.java
public static double getBestLambda(MusicURIQuery query) { //***************************************************************************** //************ Q U E R Y D A T A P R E P A R A T I O N **************** //***************************************************************************** // get the act object encapsulated in the MusicURIQuery object Mp7ACT queryMp7 = query.getAudioCompactType(); // if its null then there is some problem if (queryMp7 == null) System.out.println("Problem: queryMp7 is null"); // read the required data from the AudioCompactType AudioLLDmeta queryMean = queryMp7.featureByName(Mp7ACT.FLATNESS, Mp7ACT.MEAN); AudioLLDmeta queryVariance = queryMp7.featureByName(Mp7ACT.FLATNESS, Mp7ACT.VARIANCE); // are audioSignatureType data included in the act file? if (queryMean == null || queryVariance == null) { System.out.println(/*from w w w. j av a 2 s. c o m*/ "Problem: AudioSignatureType is not included in ACT or cannot be extracted from audio file. Aborting."); } int vectorSize = queryMean.vectorSize; // internal! stay out! read the matrix size instead float[][] queryMeanMatrix = queryMean.__rawVectors; float[][] queryVarianceMatrix = queryVariance.__rawVectors; int QueryVectorDim = vectorSize; // ==number of dimensions, subbands String queryLabelling = query.getLabel(); int queryIdentifier = Toolset.getTestCaseIdentifier(queryLabelling); StringWrapper queryWrapper = null; JaroWinkler test = new JaroWinkler(); queryLabelling = Toolset.removeTestCaseIdentifier(queryLabelling); queryWrapper = test.prepare(queryLabelling); //***************************************************************************** //********* R E F E R E N C E D A T A P R E P A R A T I O N *********** //***************************************************************************** int RefVectorDim = 0; // number of subbands, dimensions double combinedDistance; double currentLabelDistance = 0.0; double currentSignatureDistance = 0.0; double normalizedSignatureDistance = 0.0; double confidence = 0.0; Mp7ACT mp7; String currentMD5; MusicURIReference currentReference; AudioLLDmeta refMean; AudioLLDmeta refVariance; float[][] refMeanMatrix; float[][] refVarianceMatrix; StringWrapper refWrapper = null; float editDistance; int referenceIdentifier; String referenceLabelling; double lambdaYeldingSmallestCombinedDistance = 0.0; double smallestCombinedDistanceYet = 0.0; Set allMusicURIReferenceKeys = db.getSetOfMusicURIReferences(); //System.out.println("queryId: " + queryIdentifier); for (Iterator iter = allMusicURIReferenceKeys.iterator(); iter.hasNext();) { currentMD5 = (String) iter.next(); currentReference = db.getMusicURIReference(currentMD5); referenceLabelling = currentReference.getLabel(); referenceIdentifier = Toolset.getTestCaseIdentifier(referenceLabelling); if (referenceIdentifier == queryIdentifier) { mp7 = currentReference.getAudioCompactType(); if (mp7 == null) { System.out.println("Problem: No mpeg7 exists for given uri"); } refMean = mp7.featureByName(Mp7ACT.FLATNESS, Mp7ACT.MEAN); refVariance = mp7.featureByName(Mp7ACT.FLATNESS, Mp7ACT.VARIANCE); if ((refMean == null) || (refVariance == null)) { System.out.println("Skipping: problematic mpeg7 description!!! - " + mp7.getLabel() + ")"); } refMeanMatrix = refMean.__rawVectors; refVarianceMatrix = refVariance.__rawVectors; RefVectorDim = vectorSize; // number of subbands currentSignatureDistance = Toolset.getEuclidianDistance(refMeanMatrix, refVarianceMatrix, queryMeanMatrix, queryVarianceMatrix, QueryVectorDim, false); double theoreticalMaximum = (RefVectorDim * Math.sqrt(1)) * queryMeanMatrix.length; normalizedSignatureDistance = currentSignatureDistance / theoreticalMaximum; //eg (16 * sqrootof(1) ) * 10 --to scale at 0-1 String refname = currentReference.getLabel(); refname = Toolset.removeTestCaseIdentifier(refname); refWrapper = test.prepare(refname); editDistance = 1 - (float) test.score(queryWrapper, refWrapper); currentLabelDistance = editDistance; System.out.println("currentLabelDistance: " + currentLabelDistance); System.out.println("normalizedSignatureDistance: " + normalizedSignatureDistance); //combinedDistance = (0.5 * currentLabelDistance) + (0.5 * normalizedSignatureDistance); //smallestCombinedDistanceYet = (0.5 * currentLabelDistance) + (0.5 * normalizedSignatureDistance); for (double lambda = 0.0; lambda < 1.0; lambda += 0.01) { combinedDistance = lambda * currentLabelDistance + (1 - lambda) * normalizedSignatureDistance; if (combinedDistance < smallestCombinedDistanceYet) { smallestCombinedDistanceYet = combinedDistance; lambdaYeldingSmallestCombinedDistance = lambda; } } System.out.println("smallestCombinedDistanceYet: " + smallestCombinedDistanceYet); System.out.println("Best lambda: " + lambdaYeldingSmallestCombinedDistance); confidence = 100 - (100 * smallestCombinedDistanceYet); System.out.println("Best confidence: " + confidence); } } return lambdaYeldingSmallestCombinedDistance; }
From source file:com.hp.autonomy.aci.content.database.Databases.java
/** * Parses a {@code String} of database names in the format used in a <tt>query</tt> or <tt>getcontent</tt> action. * This includes parsing the output of {@link #toString()}. An empty string will be treated as equivalent to * <tt>*</tt>, even though technically there is a slight difference when working with internal databases. * * @param databases The string representation to parse * @return A {@code Databases} object/*from w w w . j a v a 2s. co m*/ */ public static Databases parse(final String databases) { Validate.notNull(databases, "Databases must not be null"); if (SPACES.matcher(databases).matches()) { return Databases.ALL; } final Set<String> databasesSet = new LinkedHashSet<String>(Arrays.asList(SEPARATORS.split(databases))); databasesSet.remove(""); if (databasesSet.isEmpty()) { return new Databases(); } if ("*".equals(databasesSet.iterator().next())) { return ALL; } databasesSet.remove("*"); databasesSet.remove(MATCH_NOTHING); return new Databases(databasesSet); }
From source file:com.basp.trabajo_al_minuto.model.business.BusinessUtils.java
public static String rollbackValidation(ConstraintViolationException cve) { Set<ConstraintViolation<?>> constraintViolations = cve.getConstraintViolations(); if (constraintViolations.size() > 0) { Iterator<ConstraintViolation<?>> iterator = constraintViolations.iterator(); List<RollbackResult> rlb = new ArrayList(); while (iterator.hasNext()) { ConstraintViolation<?> cv = iterator.next(); rlb.add(new RollbackResult(cv.getRootBean().getClass().getCanonicalName(), cv.getMessage(), cv.getInvalidValue().toString())); }//w ww . j a v a 2 s.c o m return new Gson().toJson(rlb); } return null; }