List of usage examples for java.util Set isEmpty
boolean isEmpty();
From source file:ch.digitalfondue.jfiveparse.TreeConstructionTest.java
private static void renderNode(Node node, int depth, StringBuilder sb) { int spaces = depth == 0 ? 1 : depth * 2 + 1; sb.append("|").append(StringUtils.repeat(' ', spaces)); int depthsForTemplatesChilds = 0; if (node instanceof Element) { Element elem = (Element) node; sb.append("<"); if (Node.NAMESPACE_MATHML.equals(elem.getNamespaceURI())) { sb.append("math "); } else if (Node.NAMESPACE_SVG.equals(elem.getNamespaceURI())) { sb.append("svg "); }/* www .j a v a 2 s.co m*/ sb.append(elem.getNodeName()).append(">"); Set<String> attributesName = new TreeSet<>(elem.getAttributes().keySet()); if (!attributesName.isEmpty()) { sb.append("\n"); for (String k : attributesName) { sb.append("|").append(StringUtils.repeat(' ', spaces + 2)); AttributeNode attribute = elem.getAttributes().get(k); if (attribute.getNamespace() != null) { if (Node.NAMESPACE_XLINK.equals(attribute.getNamespace())) { sb.append("xlink "); } else if (Node.NAMESPACE_XML.equals(attribute.getNamespace())) { sb.append("xml "); } else if (Node.NAMESPACE_XMLNS.equals(attribute.getNamespace())) { sb.append("xmlns "); } } sb.append(k).append("=\"").append(attribute.getValue()).append("\"\n"); } sb.deleteCharAt(sb.length() - 1); } if (elem.is("template", Node.NAMESPACE_HTML)) { sb.append("\n|").append(StringUtils.repeat(' ', spaces + 2)).append("content"); depthsForTemplatesChilds += 1; } } else if (node instanceof Text) { sb.append("\"").append(((Text) node).getData()).append("\""); } else if (node instanceof Comment) { sb.append("<!-- ").append(((Comment) node).getData()).append(" -->"); } else if (node instanceof DocumentType) { DocumentType dt = (DocumentType) node; sb.append("<!DOCTYPE "); sb.append(dt.getName()); if (StringUtils.isNotBlank(dt.getPublicId()) || StringUtils.isNotBlank(dt.getSystemId())) { sb.append(" "); sb.append("\"").append(dt.getPublicId()).append("\""); sb.append(" "); sb.append("\"").append(dt.getSystemId()).append("\""); } sb.append(">"); } sb.append("\n"); for (Node childNode : node.getChildNodes()) { renderNode(childNode, depth + 1 + depthsForTemplatesChilds, sb); } }
From source file:ezbake.security.permissions.PermissionUtils.java
/** * Validate Accumulo-style visibility expression against a set of authorizations. * * @param auths Formal authorizations of the user * @param visibilityExpression Accumulo-style visibility expression * @return true if validation authorizations against visibility expression, false otherwise *//*from w ww. j a v a 2 s .c o m*/ public static boolean validateVisibilityExpression(Set<String> auths, String visibilityExpression) { if (StringUtils.isBlank(visibilityExpression)) { return true; // No visibility to check } if (auths == null || auths.isEmpty()) { return false; // Has visibility but no auths } final VisibilityEvaluator visEval = new VisibilityEvaluator( new org.apache.accumulo.core.security.Authorizations(auths.toArray(new String[] {}))); try { return visEval.evaluate(new ColumnVisibility(visibilityExpression)); } catch (final VisibilityParseException e) { return false; } }
From source file:org.apache.uima.examples.as.GetMetaRequest.java
/** * Creates a connection to an MBean Server identified by * <code>remoteJMXServerHostName and remoteJMXServerPort</code> * /*from w ww. j ava2 s . c o m*/ * @param remoteJMXServerHostName * - MBeanServer host name * @param remoteJMXServerPort * - MBeanServer port * @return - none * * @throws Exception */ private static void initialize(String jmxDomain, String remoteJMXServerHostname, String remoteJMXServerPort) throws Exception { // Construct connect string to the JMX MBeanServer String remoteJmxUrl = "service:jmx:rmi:///jndi/rmi://" + remoteJMXServerHostname + ":" + remoteJMXServerPort + "/jmxrmi"; try { JMXServiceURL url = new JMXServiceURL(remoteJmxUrl); jmxc = JMXConnectorFactory.connect(url, null); brokerMBeanServer = jmxc.getMBeanServerConnection(); // Its possible that the above code succeeds even though the broker runs // with no JMX Connector. At least on windows the above does not throw an // exception as expected. It appears that the broker registers self JVMs MBeanServer // but it does *not* register any Connections, nor Queues. The code below // checks if the MBean server we are connected to has any QueueMBeans registered. // A broker with jmx connector should have queue mbeans registered and thus // the code below should always succeed. Conversely, a broker with no jmx connector // reports no queue mbeans. // Query broker MBeanServer for QueueMBeans Set queueSet = brokerMBeanServer.queryNames(new ObjectName(jmxDomain + ":*,Type=Queue"), (QueryExp) null); if (queueSet.isEmpty()) { // No QueueMBeans, meaning no JMX support throw new JmxException("ActiveMQ Broker Not Configured With JMX Support"); } } catch (Exception e) { return; } // Query JMX Server for Broker MBean. We need the broker's name from an MBean to construct // queue query string. for (Object nameObject : brokerMBeanServer.queryNames(new ObjectName(jmxDomain + ":*,Type=Broker"), (QueryExp) null)) { ObjectName brokerObjectName = (ObjectName) nameObject; if (brokerObjectName.getCanonicalName().endsWith("Type=Broker")) { // Extract just the name from the canonical name brokerName = brokerObjectName.getCanonicalName().substring(0, brokerObjectName.getCanonicalName().indexOf(",")); initialized = true; break; // got the broker name } } }
From source file:org.codehaus.groovy.grails.plugins.springsecurity.AuthorizeTools.java
/** * Check if the current user has none of the specified roles. * @param roles a comma-delimited list of role names * @return <code>true</code> if the user is authenticated and has none the roles *//* w w w . ja v a 2s . c om*/ public static boolean ifNotGranted(final String roles) { List<GrantedAuthority> granted = getPrincipalAuthorities(); Set<String> grantedCopy = retainAll(granted, parseAuthoritiesString(roles)); return grantedCopy.isEmpty(); }
From source file:org.codehaus.groovy.grails.plugins.springsecurity.AuthorizeTools.java
/** * Check if the current user has any of the specified roles. * @param roles a comma-delimited list of role names * @return <code>true</code> if the user is authenticated and has any the roles *//*w w w. j av a 2 s . com*/ public static boolean ifAnyGranted(final String roles) { List<GrantedAuthority> granted = getPrincipalAuthorities(); Set<String> grantedCopy = retainAll(granted, parseAuthoritiesString(roles)); return !grantedCopy.isEmpty(); }
From source file:com.haulmont.cuba.gui.components.filter.UserSetHelper.java
public static String createIdsString(Set<String> current, Collection entities) { Set<String> convertedSet = new HashSet<>(); for (Object entity : entities) { convertedSet.add(((BaseUuidEntity) entity).getId().toString()); }//from w w w.j a va2s . co m current.addAll(convertedSet); if (current.isEmpty()) { return "NULL"; } StringBuilder listOfId = new StringBuilder(); Iterator it = current.iterator(); while (it.hasNext()) { listOfId.append(it.next()); if (it.hasNext()) { listOfId.append(','); } } return listOfId.toString(); }
From source file:com.haulmont.cuba.gui.components.filter.UserSetHelper.java
public static String removeIds(Set<String> current, Collection entities) { Set<String> convertedSet = new HashSet<>(); for (Object entity : entities) { convertedSet.add(((BaseUuidEntity) entity).getId().toString()); }/*from w ww . j a v a 2 s . c o m*/ current.removeAll(convertedSet); if (current.isEmpty()) { return "NULL"; } StringBuilder listOfId = new StringBuilder(); Iterator it = current.iterator(); while (it.hasNext()) { listOfId.append(it.next()); if (it.hasNext()) { listOfId.append(','); } } return listOfId.toString(); }
From source file:Main.java
/** * Get the elements who's tags match those passed in. * @param nodeList - the node list in which to look for elements * @param tags - the tags to match (empty returns all elements). * @return The elements that matched.//from w w w. j a v a 2s.com */ public static List<Element> getElements(NodeList nodeList, String... tags) { int nNodes = nodeList.getLength(); List<Element> elements = new ArrayList<Element>(nNodes); Set<String> tagSet = new HashSet<String>(tags.length); for (String tag : tags) { tagSet.add(tag); } for (int i = 0; i < nNodes; ++i) { Node node = nodeList.item(i); if (node instanceof Element) { Element element = (Element) node; String tagName = element.getTagName(); if (tagSet.isEmpty() || tagSet.contains(tagName)) { elements.add(element); } } } return elements; }
From source file:io.github.lxgaming.teleportbow.managers.CommandManager.java
private static Optional<AbstractCommand> getCommand(AbstractCommand parentCommand, List<String> arguments) { Set<AbstractCommand> commands = Toolbox.newLinkedHashSet(); if (parentCommand != null) { commands.addAll(parentCommand.getChildren()); } else {//w ww .ja v a2s. c om commands.addAll(getCommands()); } if (arguments.isEmpty() || commands.isEmpty()) { return Optional.ofNullable(parentCommand); } for (AbstractCommand command : commands) { if (Toolbox.containsIgnoreCase(command.getAliases(), arguments.get(0))) { arguments.remove(0); return getCommand(command, arguments); } } return Optional.ofNullable(parentCommand); }
From source file:com.net2plan.utils.CollectionUtils.java
/** * Checks whether all elements of a collection are present in another one. * * @param <A> Key type// w ww.java 2s. c o m * @param container Container collection * @param collection Collection with elements to be checked * @return {@code true} if all elements in {@code collection} are present in {@code container}, and {@code false} otherwise. If {@code container} is empty, it will return {@code false} */ public static <A> boolean containsAll(Collection<A> container, Collection<A> collection) { if (container.isEmpty()) return false; Set<A> set = new LinkedHashSet<A>(container); set.removeAll(collection); return set.isEmpty(); }