List of usage examples for java.util LinkedList isEmpty
boolean isEmpty();
From source file:jp.co.ctc_g.jse.vid.ViewId.java
private static ViewId history(int history, ViewIdStore store) { ViewId id = null;/*w w w . j a va2 s . c o m*/ synchronized (store.semaphore()) { LinkedList<ViewId> ids = store.find(false); id = (ids != null && !ids.isEmpty() && ids.size() > history) ? ids.get(ids.size() - history - 1) : null; } return id; }
From source file:org.rhq.enterprise.gui.legacy.util.SessionUtils.java
/** * Returns the size of a workflow's stack. * * @param session The HttpSesion to get and save the workflow to/from * @param workflowName The name of the workflow scope to save the input under. *//* w w w . ja va2s .c o m*/ public static int countWorkflow(HttpSession session, String workflowName) { HashMap workflows = (HashMap) session.getAttribute(AttrConstants.WORKFLOW_SES_ATTR); if (workflows == null) { return 0; } LinkedList urlStack = (LinkedList) workflows.get(workflowName); if ((urlStack == null) || urlStack.isEmpty()) { return 0; } return urlStack.size(); }
From source file:org.rhq.enterprise.gui.legacy.util.SessionUtils.java
/** * Takes the current returnPath and pops it off of the workflow's stack. * * @param session The HttpSesion to get and save the workflow to/from * @param workflowName The name of the workflow scope to save the input under. * @return return path or null if it can't be retrieved */// w w w. ja v a 2s . co m public static String popWorkflow(HttpSession session, String workflowName) { HashMap workflows = (HashMap) session.getAttribute(AttrConstants.WORKFLOW_SES_ATTR); if (workflows == null) { return null; } LinkedList urlStack = (LinkedList) workflows.get(workflowName); if ((urlStack == null) || urlStack.isEmpty()) { return null; } String returnUrl = (String) urlStack.removeLast(); workflows.put(workflowName, urlStack); session.setAttribute(AttrConstants.WORKFLOW_SES_ATTR, workflows); return returnUrl; }
From source file:org.apache.hadoop.hive.ql.exec.SerializationUtilities.java
/** * Clones using the powers of XML. Do not use unless necessary. * @param roots The roots.//from w w w . jav a2 s . c o m * @return The clone. */ public static List<Operator<?>> cloneOperatorTree(List<Operator<?>> roots) { ByteArrayOutputStream baos = new ByteArrayOutputStream(4096); CompilationOpContext ctx = roots.isEmpty() ? null : roots.get(0).getCompilationOpContext(); serializePlan(roots, baos, true); @SuppressWarnings("unchecked") List<Operator<?>> result = deserializePlan(new ByteArrayInputStream(baos.toByteArray()), roots.getClass(), true); // Restore the context. LinkedList<Operator<?>> newOps = new LinkedList<>(result); while (!newOps.isEmpty()) { Operator<?> newOp = newOps.poll(); newOp.setCompilationOpContext(ctx); List<Operator<?>> children = newOp.getChildOperators(); if (children != null) { newOps.addAll(children); } } return result; }
From source file:org.apache.hadoop.hive.ql.exec.SerializationUtilities.java
public static List<Operator<?>> cloneOperatorTree(List<Operator<?>> roots, int indexForTezUnion) { ByteArrayOutputStream baos = new ByteArrayOutputStream(4096); CompilationOpContext ctx = roots.isEmpty() ? null : roots.get(0).getCompilationOpContext(); serializePlan(roots, baos, true);/* w w w. jav a 2 s .c o m*/ @SuppressWarnings("unchecked") List<Operator<?>> result = deserializePlan(new ByteArrayInputStream(baos.toByteArray()), roots.getClass(), true); // Restore the context. LinkedList<Operator<?>> newOps = new LinkedList<>(result); while (!newOps.isEmpty()) { Operator<?> newOp = newOps.poll(); newOp.setIndexForTezUnion(indexForTezUnion); newOp.setCompilationOpContext(ctx); List<Operator<?>> children = newOp.getChildOperators(); if (children != null) { newOps.addAll(children); } } return result; }
From source file:org.rhq.enterprise.gui.legacy.util.SessionUtils.java
/** * Retrieve the "return path" that locates the point at which a subflow was included into a primary workflow. * * @param session the http session/*from w w w. ja v a 2s. c om*/ */ public static String getReturnPath(HttpSession session) { LinkedList stack = (LinkedList) session.getAttribute(AttrConstants.RETURN_LOC_SES_ATTR); if ((stack == null) || stack.isEmpty()) { return null; } ReturnPath returnPath = (ReturnPath) stack.getFirst(); return returnPath.getPath(); }
From source file:org.rhq.enterprise.gui.legacy.util.SessionUtils.java
/** * Retrieve wether the "return path" should be paid attention to for new. should default to false, which means that * it is not ignored.// w w w .jav a 2s . c om * * @param session the http session * * @return whether or not to ignore the return path */ public static Boolean getReturnPathIgnoredForOk(HttpSession session) { LinkedList stack = (LinkedList) session.getAttribute(AttrConstants.RETURN_LOC_SES_ATTR); if ((stack == null) || stack.isEmpty()) { return Boolean.FALSE; } ReturnPath returnPath = (ReturnPath) stack.getFirst(); if (returnPath == null) { return Boolean.FALSE; } return returnPath.getIgnore(); }
From source file:de.vanita5.twittnuker.util.net.ssl.AbstractCheckSignatureVerifier.java
public static final boolean verify(final String host, final String[] cns, final String[] subjectAlts, final boolean strictWithSubDomains) { // Build the list of names we're going to check. Our DEFAULT and // STRICT implementations of the HostnameVerifier only use the // first CN provided. All other CNs are ignored. // (Firefox, wget, curl, Sun Java 1.4, 5, 6 all work this way). final LinkedList<String> names = new LinkedList<String>(); if (cns != null && cns.length > 0 && cns[0] != null) { names.add(cns[0]);/*from w w w .j a va 2 s. c o m*/ } if (subjectAlts != null) { for (final String subjectAlt : subjectAlts) { if (subjectAlt != null) { names.add(subjectAlt); } } } if (names.isEmpty()) return false; // StringBuilder for building the error message. final StringBuilder buf = new StringBuilder(); // We're can be case-insensitive when comparing the host we used to // establish the socket to the hostname in the certificate. final String hostName = normaliseIPv6Address(host.trim().toLowerCase(Locale.US)); boolean match = false; for (final Iterator<String> it = names.iterator(); it.hasNext();) { // Don't trim the CN, though! String cn = it.next(); cn = cn.toLowerCase(Locale.US); // Store CN in StringBuilder in case we need to report an error. buf.append(" <"); buf.append(cn); buf.append('>'); if (it.hasNext()) { buf.append(" OR"); } // The CN better have at least two dots if it wants wildcard // action. It also can't be [*.co.uk] or [*.co.jp] or // [*.org.uk], etc... final String parts[] = cn.split("\\."); final boolean doWildcard = parts.length >= 3 && parts[0].endsWith("*") && validCountryWildcard(cn) && !isIPAddress(host); if (doWildcard) { final String firstpart = parts[0]; if (firstpart.length() > 1) { // e.g. server* // e.g. server final String prefix = firstpart.substring(0, firstpart.length() - 1); // skip wildcard part from cn final String suffix = cn.substring(firstpart.length());// skip // wildcard part from host final String hostSuffix = hostName.substring(prefix.length()); match = hostName.startsWith(prefix) && hostSuffix.endsWith(suffix); } else { match = hostName.endsWith(cn.substring(1)); } if (match && strictWithSubDomains) { // If we're in strict mode, then [*.foo.com] is not // allowed to match [a.b.foo.com] match = countDots(hostName) == countDots(cn); } } else { match = hostName.equals(normaliseIPv6Address(cn)); } if (match) { break; } } return match; }
From source file:org.deegree.services.wms.controller.WMSController.java
private static void addHeaders(HttpResponseBuffer response, LinkedList<String> headers) { while (!headers.isEmpty()) { String s = headers.poll(); response.addHeader("Warning", s); }/*from w ww . jav a2s. c o m*/ }
From source file:org.dcm4che3.conf.core.misc.DeepEquals.java
/** * Compare two objects with a 'deep' comparison. This will traverse the * Object graph and perform either a field-by-field comparison on each * object (if no .equals() method has been overridden from Object), or it * will call the customized .equals() method if it exists. This method will * allow object graphs loaded at different times (with different object ids) * to be reliably compared. Object.equals() / Object.hashCode() rely on the * object's identity, which would not consider to equivalent objects necessarily * equals. This allows graphs containing instances of Classes that did no * overide .equals() / .hashCode() to be compared. For example, testing for * existence in a cache. Relying on an objects identity will not locate an * object in cache, yet relying on it being equivalent will.<br/><br/> * * This method will handle cycles correctly, for example A->B->C->A. Suppose a and * a' are two separate instances of the A with the same values for all fields on * A, B, and C. Then a.deepEquals(a') will return true. It uses cycle detection * storing visited objects in a Set to prevent endless loops. * @param a Object one to compare/*from www. j a v a 2 s . c om*/ * @param b Object two to compare * @return true if a is equivalent to b, false otherwise. Equivalent means that * all field values of both subgraphs are the same, either at the field level * or via the respectively encountered overridden .equals() methods during * traversal. */ public static boolean deepEquals(Object a, Object b) { Set visited = new HashSet<DualKey>(); LinkedList<DualKey> stack = new LinkedList<DualKey>(); stack.addFirst(new DualKey(a, b)); while (!stack.isEmpty()) { DualKey dualKey = stack.removeFirst(); lastDualKey = dualKey; visited.add(dualKey); if (dualKey._key1 == dualKey._key2) { // Same instance is always equal to itself. continue; } if (dualKey._key1 == null || dualKey._key2 == null) { // check if one is null and another is an empty array if (dualKey._key1 == null) { if (dualKey._key2.getClass().isArray() && ((Object[]) dualKey._key2).length == 0) continue; } if (dualKey._key2 == null) { if (dualKey._key1.getClass().isArray() && ((Object[]) dualKey._key1).length == 0) continue; } // If either one is null, not equal (both can't be null, due to above comparison). return false; } if (!dualKey._key1.getClass().equals(dualKey._key2.getClass())) { // Must be same class return false; } // Handle all [] types. In order to be equal, the arrays must be the same // length, be of the same type, be in the same order, and all elements within // the array must be deeply equivalent. if (dualKey._key1.getClass().isArray()) { if (!compareArrays(dualKey._key1, dualKey._key2, stack, visited)) { return false; } continue; } // Special handle SortedSets because they are fast to compare because their // elements must be in the same order to be equivalent Sets. if (dualKey._key1 instanceof SortedSet) { if (!compareOrderedCollection((Collection) dualKey._key1, (Collection) dualKey._key2, stack, visited)) { return false; } continue; } // Handled unordered Sets. This is a slightly more expensive comparison because order cannot // be assumed, a temporary Map must be created, however the comparison still runs in O(N) time. if (dualKey._key1 instanceof Set) { if (!compareUnorderedCollection((Collection) dualKey._key1, (Collection) dualKey._key2, stack, visited)) { return false; } continue; } // Check any Collection that is not a Set. In these cases, element order // matters, therefore this comparison is faster than using unordered comparison. if (dualKey._key1 instanceof Collection) { if (!compareOrderedCollection((Collection) dualKey._key1, (Collection) dualKey._key2, stack, visited)) { return false; } continue; } // Compare two SortedMaps. This takes advantage of the fact that these // Maps can be compared in O(N) time due to their ordering. if (dualKey._key1 instanceof SortedMap) { if (!compareSortedMap((SortedMap) dualKey._key1, (SortedMap) dualKey._key2, stack, visited)) { return false; } continue; } // Compare two Unordered Maps. This is a slightly more expensive comparison because // order cannot be assumed, therefore a temporary Map must be created, however the // comparison still runs in O(N) time. if (dualKey._key1 instanceof Map) { if (!compareUnorderedMap((Map) dualKey._key1, (Map) dualKey._key2, stack, visited)) { return false; } continue; } if (hasCustomEquals(dualKey._key1.getClass())) { if (!dualKey._key1.equals(dualKey._key2)) { return false; } continue; } lastClass = dualKey._key1.getClass().toString(); // check if we have a custom deepequals method for this class CustomDeepEquals de = customDeepEquals.get(dualKey._key1.getClass()); if (de != null) { if (!de.deepEquals(dualKey._key1, dualKey._key2)) return false; } else { Collection<Field> fields = getDeepDeclaredFields(dualKey._key1.getClass()); for (Field field : fields) { try { DualKey dk = new DualKey(field.get(dualKey._key1), field.get(dualKey._key2), field.getName()); if (!visited.contains(dk)) { stack.addFirst(dk); } } catch (Exception ignored) { } } } } return true; }