List of usage examples for java.util Set iterator
Iterator<E> iterator();
From source file:com.petalmd.armor.util.SecurityUtil.java
public static String getSearchGuardSessionIdFromCookie(final RestRequest request) { final String cookies = request.header("Cookie"); if (cookies != null) { final Set<Cookie> cookiesAsSet = new CookieDecoder().decode(cookies); log.trace("Cookies {}", cookiesAsSet); for (final Iterator iterator = cookiesAsSet.iterator(); iterator.hasNext();) { final Cookie cookie = (Cookie) iterator.next(); if ("es_armor_session".equals(cookie.getName())) { return cookie.getValue(); }//from w ww.j av a 2s .c om } } return null; }
From source file:com.mg.framework.utils.StringUtils.java
/** * Creates an encoded String from a Map of name/value pairs (MUST BE STRINGS!) * * @param map The Map of name/value pairs * @return String The encoded String/*w ww. jav a 2 s.co m*/ */ public static String mapToStr(Map<String, String> map) { if (map == null) return null; StringBuffer buf = new StringBuffer(); Set<String> keySet = map.keySet(); Iterator<String> i = keySet.iterator(); boolean first = true; while (i.hasNext()) { Object key = i.next(); Object value = map.get(key); if (!(key instanceof String) || !(value instanceof String)) continue; String encodedName = null; try { encodedName = URLEncoder.encode((String) key, "UTF-8"); } catch (UnsupportedEncodingException e) { //Debug.logError(e, module); } String encodedValue = null; try { encodedValue = URLEncoder.encode((String) value, "UTF-8"); } catch (UnsupportedEncodingException e) { //Debug.logError(e, module); } if (first) first = false; else buf.append("|"); buf.append(encodedName); buf.append("="); buf.append(encodedValue); } return buf.toString(); }
From source file:edu.uci.ics.jung.utils.GraphUtils.java
/** * Given a set of vertices, creates a new <tt>Graph</tt> that contains * all of those vertices, and all the edges that connect them. Uses the * <tt>{@link edu.uci.ics.jung.graph.filters.UnassembledGraph UnassembledGraph}</tt> * mechanism to create the graph.//from ww w . j a v a2 s .com * * @param s * A set of <tt>Vertex</tt> s that want to be a part of a new * Graph * @return A graph, created with <tt>{@link edu.uci.ics.jung.graph.Graph#newInstance Graph.newInstance}</tt>, * containing vertices equivalent to (and that are copies of!) all * the vertices in the input set. Note that if the input is an * empty set, <tt>null</tt> is returned. */ public static Graph vertexSetToGraph(Set s) { if (s.isEmpty()) return null; Vertex v = (Vertex) s.iterator().next(); Graph g = (Graph) v.getGraph(); return new UnassembledGraph("vertexSetToGraph", s, g.getEdges(), g).assemble(); }
From source file:net.sf.morph.util.TestUtils.java
public static boolean equals(Object object1, Object object2) { if (log.isTraceEnabled()) { log.trace("Testing for equality between " + ObjectUtils.getObjectDescription(object1) + " and " + ObjectUtils.getObjectDescription(object2)); }/*from w w w.ja va2s.co m*/ // if both objects are == (incl. null) they are equal if (object1 == object2) { return true; } // if one object is null and the other is not, the two objects aren't // equal if (object1 == null || object2 == null) { return false; } if (object1 instanceof Calendar && object2 instanceof Calendar) { return equals(((Calendar) object1).getTime(), ((Calendar) object2).getTime()); } if (object1 instanceof Comparable && object1.getClass() == object2.getClass()) { return ((Comparable) object1).compareTo(object2) == 0; } if (object1 instanceof Map.Entry && object2 instanceof Map.Entry) { if (object1.getClass() != object2.getClass()) { return false; } Map.Entry me1 = (Map.Entry) object1; Map.Entry me2 = (Map.Entry) object2; return equals(me1.getKey(), me2.getKey()) && equals(me1.getValue(), me2.getValue()); } // if both objects are arrays if (object1.getClass().isArray() && object2.getClass().isArray()) { // if the arrays aren't of the same class, the two objects aren't // equal if (object1.getClass() != object2.getClass()) { return false; } // else, same type of array // if the arrays are different sizes, they aren't equal if (Array.getLength(object1) != Array.getLength(object2)) { return false; } // else arrays are the same size // iterate through the arrays and check if all elements are // equal for (int i = 0; i < Array.getLength(object1); i++) { // if one item isn't equal to the other if (!equals(Array.get(object1, i), Array.get(object2, i))) { // the arrays aren't equal return false; } } // if we iterated through both arrays and found no items // that weren't equal to each other, the collections are // equal return true; } if (object1 instanceof Iterator && object2 instanceof Iterator) { Iterator iterator1 = (Iterator) object1; Iterator iterator2 = (Iterator) object2; while (iterator1.hasNext()) { if (!iterator2.hasNext()) { return false; } // if one item isn't equal to the other if (!equals(iterator1.next(), iterator2.next())) { // the arrays aren't equal return false; } } // if we iterated through both collections and found // no items that weren't equal to each other, the // collections are equal return !iterator2.hasNext(); } if (object1 instanceof Enumeration && object2 instanceof Enumeration) { return equals(new EnumerationIterator((Enumeration) object1), new EnumerationIterator((Enumeration) object2)); } if ((object1 instanceof List && object2 instanceof List) || (object1 instanceof SortedSet && object2 instanceof SortedSet)) { // if the collections aren't of the same type, they aren't equal if (object1.getClass() != object2.getClass()) { return false; } // else same type of collection return equals(((Collection) object1).iterator(), ((Collection) object2).iterator()); } if (object1 instanceof Set && object2 instanceof Set) { // if the sets aren't of the same type, they aren't equal if (object1.getClass() != object2.getClass()) { return false; } // else same type of set Set set1 = (Set) object1; Set set2 = (Set) object2; // if the sets aren't the same size, they aren't equal if (set1.size() != set2.size()) { return false; } // else sets are the same size Iterator iterator1 = set1.iterator(); while (iterator1.hasNext()) { Object next = iterator1.next(); if (!contains(set2, next)) { return false; } } return true; } if (object1 instanceof Map && object2 instanceof Map) { return equals(((Map) object1).entrySet(), ((Map) object2).entrySet()); } if (object1.getClass() == object2.getClass() && object1 instanceof StringBuffer) { return object1.toString().equals(object2.toString()); } // for primitives, use their equals methods if (object1.getClass() == object2.getClass() && (object1 instanceof String || object1 instanceof Number || object1 instanceof Boolean || //object1 instanceof StringBuffer || object1 instanceof Character)) { return object1.equals(object2); } // for non-primitives, compare field-by-field return MorphEqualsBuilder.reflectionEquals(object1, object2); }
From source file:edu.uci.ics.jung.utils.GraphUtils.java
/** * Returns the set of vertices in <code>g</code> which are equal * to the vertices in <code>g</code>. * @since 1.4//from w ww . ja v a2 s .co m */ public static Set getEqualVertices(Set s, ArchetypeGraph g) { Set rv = new HashSet(); for (Iterator iter = s.iterator(); iter.hasNext();) { ArchetypeVertex v = (ArchetypeVertex) iter.next(); ArchetypeVertex v_g = v.getEqualVertex(g); if (v_g != null) rv.add(v_g); } return rv; }
From source file:edu.uci.ics.jung.utils.GraphUtils.java
/** * Returns the set of edges in <code>g</code> which are equal * to the edges in <code>g</code>. * @since 1.4//from ww w. j ava2s .c o m */ public static Set getEqualEdges(Set s, ArchetypeGraph g) { Set rv = new HashSet(); for (Iterator iter = s.iterator(); iter.hasNext();) { ArchetypeEdge e = (ArchetypeEdge) iter.next(); ArchetypeEdge e_g = e.getEqualEdge(g); if (e_g != null) rv.add(e_g); } return rv; }
From source file:com.aurel.track.exchange.excel.ExcelFieldMatchBL.java
/** * Match by fieldConfigBean labels/*from w ww. jav a 2 s . c om*/ * @param excelColumnNames * @param fieldConfigsMap * @param previousMappings */ private static void addMatch(Set<String> excelColumnNames, Map<String, TFieldConfigBean> fieldConfigsMap, Map<String, Integer> previousMappings) { if (!excelColumnNames.isEmpty()) { Iterator<String> itrExcelColumNames = excelColumnNames.iterator(); while (itrExcelColumNames.hasNext()) { String columName = itrExcelColumNames.next(); if (fieldConfigsMap.containsKey(columName)) { TFieldConfigBean fieldConfigBean = fieldConfigsMap.get(columName); if (fieldConfigBean != null) { previousMappings.put(columName, fieldConfigBean.getObjectID()); itrExcelColumNames.remove(); } } } } }
From source file:com.gargoylesoftware.htmlunit.runners.TestCaseCorrector.java
private static void removeNotYetImplemented(final List<String> lines, final int i, final String browserString) { final String previous = lines.get(i - 1); if (previous.contains("@NotYetImplemented")) { if (previous.indexOf('(') != -1) { final int p0 = previous.indexOf('(') + 1; final int p1 = previous.lastIndexOf(')'); String browsers = previous.substring(p0, p1); if (browsers.indexOf('{') != -1) { browsers = browsers.substring(1, browsers.length() - 1).trim(); }//from w w w . ja va 2 s . c o m final Set<String> browserSet = new HashSet<>(); for (final String browser : browsers.split(",")) { browserSet.add(browser.trim()); } browserSet.remove(browserString); if (browserSet.size() == 1) { lines.set(i - 1, " @NotYetImplemented(" + browserSet.iterator().next() + ")"); } else if (browserSet.size() > 1) { lines.set(i - 1, " @NotYetImplemented({ " + StringUtils.join(browserSet, ", ") + " })"); } else { lines.remove(i - 1); } } else { final List<String> allBrowsers = new ArrayList<>( Arrays.asList("CHROME", "IE11", "FF31", "FF38", "EDGE")); for (final Iterator<String> it = allBrowsers.iterator(); it.hasNext();) { if (it.next().equals(browserString)) { it.remove(); } } lines.set(i - 1, " @NotYetImplemented({ " + StringUtils.join(allBrowsers, ", ") + " })"); } } }
From source file:com.intuit.tank.common.ScriptUtil.java
public static long calculateStepDuration(ScriptStep step, Map<String, String> variables) { long result = 0; try {/* w ww. j ava2 s. c o m*/ TankConfig config = new TankConfig(); if (step.getType().equalsIgnoreCase("request")) { result = config.getAgentConfig().getRange(step.getMethod()).getRandomValueWithin(); } else if (step.getType().equalsIgnoreCase("variable")) { Set<RequestData> data = step.getData(); for (RequestData requestData : data) { variables.put(requestData.getKey(), requestData.getValue()); } } else if (step.getType().equalsIgnoreCase("thinkTime")) { String min = "0"; String max = "0"; Set<RequestData> setData = step.getData(); if (null != setData) { Iterator<RequestData> iter = setData.iterator(); while (iter.hasNext()) { RequestData d = iter.next(); if (d.getKey().contains("min")) { min = d.getValue(); } else if (d.getKey().contains("max")) { max = d.getValue(); } } } if (ValidationUtil.isAnyVariable(min)) { String s = (String) variables.get(ValidationUtil.removeAllVariableIdentifier(min)); min = s != null ? s : min; } if (ValidationUtil.isAnyVariable(max)) { String s = (String) variables.get(ValidationUtil.removeAllVariableIdentifier(max)); max = s != null ? s : max; } result = ((TimeUtil.parseTimeString(max) + TimeUtil.parseTimeString(min)) / 2); } else if (step.getType().equalsIgnoreCase("sleep")) { Set<RequestData> setData = step.getData(); if (null != setData) { Iterator<RequestData> iter = setData.iterator(); while (iter.hasNext()) { RequestData d = iter.next(); if (d.getKey().equalsIgnoreCase("time")) { String time = d.getValue(); if (ValidationUtil.isAnyVariable(time)) { String s = (String) variables.get(ValidationUtil.removeAllVariableIdentifier(time)); time = s != null ? s : time; } result = TimeUtil.parseTimeString(time); break; } } } } else { result = config.getAgentConfig().getRange("process").getRandomValueWithin(); } } catch (Exception e) { LOG.error("Error calculating step time: " + e); } return result; }
From source file:edu.uci.ics.jung.utils.GraphUtils.java
/** * Copies the labels of vertices from one StringLabeller to another. Only * the labels of vertices that are equivalent are copied. * //from w ww.j a v a 2s . com * @param source * the source StringLabeller * @param target * the target StringLabeller */ public static void copyLabels(StringLabeller source, StringLabeller target) throws UniqueLabelException { Graph g1 = source.getGraph(); Graph g2 = target.getGraph(); Set s1 = g1.getVertices(); Set s2 = g2.getVertices(); for (Iterator iter = s1.iterator(); iter.hasNext();) { Vertex v = (Vertex) iter.next(); if (s2.contains(v)) { target.setLabel((Vertex) v.getEqualVertex(g2), source.getLabel(v)); } } }