Example usage for java.util HashSet isEmpty

List of usage examples for java.util HashSet isEmpty

Introduction

In this page you can find the example usage for java.util HashSet isEmpty.

Prototype

public boolean isEmpty() 

Source Link

Document

Returns true if this set contains no elements.

Usage

From source file:fr.mixit.android.io.JSONHandler.java

/**
 * Returns those id's from a {@link android.net.Uri} that were not found in a given set.
 *///ww w .  j a va2 s  .c  om
protected static HashSet<String> getLostIds(Set<String> ids, Uri uri, String[] projection, int idColumnIndex,
        ContentResolver resolver) {
    final HashSet<String> lostIds = Sets.newHashSet();

    final Cursor cursor = resolver.query(uri, projection, null, null, null);
    try {
        while (cursor.moveToNext()) {
            final String id = cursor.getString(idColumnIndex);
            if (!ids.contains(id)) {
                lostIds.add(id);
            }
        }
    } finally {
        cursor.close();
    }

    if (!lostIds.isEmpty()) {
        Log.d(TAG, "Found " + lostIds.size() + " for " + uri.toString() + " that need to be removed.");
    }

    return lostIds;
}

From source file:com.fiveamsolutions.nci.commons.web.struts2.validator.HibernateValidator.java

private static Set<String> parseList(String list) {
    if (StringUtils.isBlank(list)) {
        return null;
    }/*from   www.  j  ava2s.  c o m*/
    HashSet<String> names = new HashSet<String>();
    StringTokenizer st = new StringTokenizer(list, ",");
    while (st.hasMoreTokens()) {
        String n = st.nextToken().trim();
        if (StringUtils.isNotBlank(n)) {
            names.add(n);
        }
    }
    return !names.isEmpty() ? names : null;
}

From source file:sf.net.experimaestro.utils.graphs.Sort.java

/**
 * Topological sort of a set of nodes//  w  w  w  .j  a v  a  2 s.c o  m
 *
 * @param nodes The nodes to be sorted
 * @return An ordered list of nodes
 */
static public <T extends Node> ArrayList<T> topologicalSort(List<T> nodes) {
    ArrayList<T> ordered = new ArrayList<>();
    HashSet<NodeRef<T>> dandling = new HashSet<>();

    Map<NodeRef<T>, MutableInt> remaining = new HashMap<>();
    for (Node node : nodes) {
        final Iterable<? extends Node> children = node.getChildren();
        int size = Iterables.size(children);
        if (size == 0)
            dandling.add(new NodeRef(node));
        else
            remaining.put(new NodeRef(node), new MutableInt(size));
    }

    while (!remaining.isEmpty() || !dandling.isEmpty()) {
        if (dandling.isEmpty())
            throw new XPMRuntimeException("Graph contains cycle");

        HashSet<NodeRef<T>> newDandling = new HashSet<>();
        for (NodeRef<T> ref : dandling) {
            ordered.add(ref.node);
            remaining.remove(ref);
        }

        for (NodeRef<T> ref : dandling) {
            for (Node parent : ref.node.getParents()) {
                final MutableInt children = remaining.get(new NodeRef<>(parent));
                children.decrement();
                assert children.intValue() >= 0;
                if (children.intValue() == 0)
                    newDandling.add(new NodeRef(parent));
            }

        }
        dandling = newDandling;
    }

    return ordered;

}

From source file:com.wellsandwhistles.android.redditsp.reddit.api.RedditAPICommentAction.java

public static void onActionMenuItemSelected(final RedditRenderableComment renderableComment,
        final RedditCommentView commentView, final AppCompatActivity activity,
        final CommentListingFragment commentListingFragment, final RedditCommentAction action,
        final RedditChangeDataManager changeDataManager) {

    final RedditComment comment = renderableComment.getParsedComment().getRawComment();

    switch (action) {

    case UPVOTE://from w  w w .  ja v a 2s. c o m
        action(activity, comment, RedditAPI.ACTION_UPVOTE, changeDataManager);
        break;

    case DOWNVOTE:
        action(activity, comment, RedditAPI.ACTION_DOWNVOTE, changeDataManager);
        break;

    case UNVOTE:
        action(activity, comment, RedditAPI.ACTION_UNVOTE, changeDataManager);
        break;

    case SAVE:
        action(activity, comment, RedditAPI.ACTION_SAVE, changeDataManager);
        break;

    case UNSAVE:
        action(activity, comment, RedditAPI.ACTION_UNSAVE, changeDataManager);
        break;

    case REPORT:

        new AlertDialog.Builder(activity).setTitle(R.string.action_report)
                .setMessage(R.string.action_report_sure)
                .setPositiveButton(R.string.action_report, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int which) {
                        action(activity, comment, RedditAPI.ACTION_REPORT, changeDataManager);
                    }
                }).setNegativeButton(R.string.dialog_cancel, null).show();

        break;

    case REPLY: {
        final Intent intent = new Intent(activity, CommentReplyActivity.class);
        intent.putExtra(CommentReplyActivity.PARENT_ID_AND_TYPE_KEY, comment.getIdAndType());
        intent.putExtra(CommentReplyActivity.PARENT_MARKDOWN_KEY,
                StringEscapeUtils.unescapeHtml4(comment.body));
        activity.startActivity(intent);
        break;
    }

    case EDIT: {
        final Intent intent = new Intent(activity, CommentEditActivity.class);
        intent.putExtra("commentIdAndType", comment.getIdAndType());
        intent.putExtra("commentText", StringEscapeUtils.unescapeHtml4(comment.body));
        activity.startActivity(intent);
        break;
    }

    case DELETE: {
        new AlertDialog.Builder(activity).setTitle(R.string.accounts_delete).setMessage(R.string.delete_confirm)
                .setPositiveButton(R.string.action_delete, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int which) {
                        action(activity, comment, RedditAPI.ACTION_DELETE, changeDataManager);
                    }
                }).setNegativeButton(R.string.dialog_cancel, null).show();
        break;
    }

    case COMMENT_LINKS:
        final HashSet<String> linksInComment = comment.computeAllLinks();

        if (linksInComment.isEmpty()) {
            General.quickToast(activity, R.string.error_toast_no_urls_in_comment);

        } else {

            final String[] linksArr = linksInComment.toArray(new String[linksInComment.size()]);

            final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
            builder.setItems(linksArr, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    LinkHandler.onLinkClicked(activity, linksArr[which], false);
                    dialog.dismiss();
                }
            });

            final AlertDialog alert = builder.create();
            alert.setTitle(R.string.action_comment_links);
            alert.setCanceledOnTouchOutside(true);
            alert.show();
        }

        break;

    case SHARE:

        final Intent mailer = new Intent(Intent.ACTION_SEND);
        mailer.setType("text/plain");
        mailer.putExtra(Intent.EXTRA_SUBJECT, "Comment by " + comment.author + " on Reddit");

        // TODO this currently just dumps the markdown
        mailer.putExtra(Intent.EXTRA_TEXT, StringEscapeUtils.unescapeHtml4(comment.body) + "\r\n\r\n"
                + comment.getContextUrl().generateNonJsonUri().toString());

        activity.startActivityForResult(Intent.createChooser(mailer, activity.getString(R.string.action_share)),
                1);

        break;

    case COPY_TEXT: {
        ClipboardManager manager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
        // TODO this currently just dumps the markdown
        manager.setText(StringEscapeUtils.unescapeHtml4(comment.body));
        break;
    }

    case COPY_URL: {
        ClipboardManager manager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
        // TODO this currently just dumps the markdown
        manager.setText(comment.getContextUrl().context(null).generateNonJsonUri().toString());
        break;
    }

    case COLLAPSE: {
        commentListingFragment.handleCommentVisibilityToggle(commentView);
        break;
    }

    case USER_PROFILE:
        LinkHandler.onLinkClicked(activity, new UserProfileURL(comment.author).toString());
        break;

    case PROPERTIES:
        CommentPropertiesDialog.newInstance(comment).show(activity.getSupportFragmentManager(), null);
        break;

    case GO_TO_COMMENT: {
        LinkHandler.onLinkClicked(activity, comment.getContextUrl().context(null).toString());
        break;
    }

    case CONTEXT: {
        LinkHandler.onLinkClicked(activity, comment.getContextUrl().toString());
        break;
    }
    case ACTION_MENU:
        showActionMenu(activity, commentListingFragment, renderableComment, commentView, changeDataManager,
                comment.isArchived());
        break;

    case BACK:
        activity.onBackPressed();
        break;
    }
}

From source file:com.jetyun.pgcd.rpc.localarg.LocalArgController.java

/**
 * Unregisters a LocalArgResolver</b>.
 * /*from w  w  w  .  j  a v a  2  s.com*/
 * @param argClazz
 *            The previously registered local class
 * @param argResolver
 *            The previously registered LocalArgResolver object
 * @param contextInterface
 *            The previously registered transport Context interface.
 */
public static void unregisterLocalArgResolver(Class argClazz, Class contextInterface,
        LocalArgResolver argResolver) {
    synchronized (localArgResolverMap) {
        HashSet resolverSet = (HashSet) localArgResolverMap.get(argClazz);
        if (resolverSet == null
                || !resolverSet.remove(new LocalArgResolverData(argResolver, argClazz, contextInterface))) {
            log.warn("local arg resolver " + argResolver.getClass().getName()
                    + " not registered for local class " + argClazz.getName() + " with context "
                    + contextInterface.getName());
            return;
        }
        if (resolverSet.isEmpty()) {
            localArgResolverMap.remove(argClazz);
        }
    }
    log.info("unregistered local arg resolver " + argResolver.getClass().getName() + " for local class "
            + argClazz.getName() + " with context " + contextInterface.getName());
}

From source file:com.velonuboso.made.core.common.Helper.java

/**
 * Modification by rhgarcia from the implementation of M. Jessup 
 * at StackOverflow.//from   w  w w  .j  a  v a  2  s.com
 * http://stackoverflow.com/users/294738/m-jessup
 */
public static ArrayList<Class> topologicalOrder(ArrayList<Class> classes) throws Exception {

    Node[] allNodes = new Node[classes.size()];
    HashMap<String, Node> nodes = new HashMap<String, Node>();

    for (int i = 0; i < classes.size(); i++) {
        Class c = classes.get(i);
        Node n = new Node(c);
        allNodes[i] = n;
        nodes.put(c.getSimpleName(), n);
    }

    for (int i = 0; i < allNodes.length; i++) {
        Node n = allNodes[i];
        Class c = n.getC();
        Archetype a = (Archetype) c.getConstructors()[0].newInstance();
        ArrayList<Class> dependencies = a.getDependencies();
        for (int j = 0; j < dependencies.size(); j++) {
            Class dep = dependencies.get(j);
            Node nAux = nodes.get(dep.getSimpleName());
            if (nAux != null) {
                nAux.addEdge(n);
            }
        }
    }

    //L <- Empty list that will contain the sorted elements
    ArrayList<Node> L = new ArrayList<Node>();

    //S <- Set of all nodes with no incoming edges
    HashSet<Node> S = new HashSet<Node>();
    for (Node n : allNodes) {
        if (n.inEdges.size() == 0) {
            S.add(n);
        }
    }

    //while S is non-empty do
    while (!S.isEmpty()) {
        //remove a node n from S
        Node n = S.iterator().next();
        S.remove(n);

        //insert n into L
        L.add(n);

        //for each node m with an edge e from n to m do
        for (Iterator<Edge> it = n.outEdges.iterator(); it.hasNext();) {
            //remove edge e from the graph
            Edge e = it.next();
            Node m = e.to;
            it.remove();//Remove edge from n
            m.inEdges.remove(e);//Remove edge from m

            //if m has no other incoming edges then insert m into S
            if (m.inEdges.isEmpty()) {
                S.add(m);
            }
        }
    }
    //Check to see if all edges are removed
    boolean cycle = false;
    for (Node n : allNodes) {
        if (!n.inEdges.isEmpty()) {
            cycle = true;
            break;
        }
    }
    if (cycle) {
        throw new Exception("Cycle present, topological sort not possible");
    }
    System.out.println("Topological Sort: " + Arrays.toString(L.toArray()));

    ArrayList<Class> ret = new ArrayList<Class>();
    for (Node n : L) {
        ret.add(n.getC());
    }
    return ret;
}

From source file:disko.DU.java

@SuppressWarnings("unchecked")
public static HGHandle toSynRel(HyperGraph graph, HGHandle h) {
    RelOccurrence o = graph.get(h);//www  .j a  v  a 2 s .c  o  m
    HGHandle[] targets = HGUtils.toHandleArray(o);
    HashSet<HGHandle> L = new HashSet<HGHandle>();
    L.addAll((List<HGHandle>) (List<?>) hg.findAll(graph,
            hg.and(hg.type(ScopeLink.class), hg.orderedLink(new HGHandle[] { hg.anyHandle(), h }))));
    if (L.isEmpty()) // scope unknown?!!?
        return null;
    HGHandle synRelHandle = hg.findOne(graph, hg.and(hg.type(SynRel.class), hg.link(targets)));
    if (synRelHandle == null)
        synRelHandle = graph.add(new SynRel(targets));
    for (HGHandle scopeHandle : L) {
        ScopeLink scopeLink = graph.get(scopeHandle);
        HGHandle scoping = scopeLink.getTargetAt(0);
        if (hg.findOne(graph, hg.and(hg.type(ScopeLink.class), hg.orderedLink(scoping, synRelHandle))) == null)
            graph.add(new ScopeLink(scoping, synRelHandle));
    }
    return synRelHandle;
}

From source file:edu.cens.loci.classes.LociWifiFingerprint.java

public static boolean hasCommonBeacons(LociWifiFingerprint sig1, LociWifiFingerprint sig2) {

    HashSet<String> bssid1 = sig1.getBssids();
    HashSet<String> bssid2 = sig2.getBssids();

    HashSet<String> intersection = new HashSet<String>(bssid1);
    intersection.retainAll(bssid2);//w  w w .j a va2 s.co m

    if (intersection.isEmpty())
        return false;
    else
        return true;
}

From source file:org.apache.sling.distribution.packaging.impl.DistributionPackageUtils.java

public static boolean release(File file, @Nonnull String[] holderNames) throws IOException {
    if (holderNames.length == 0) {
        throw new IllegalArgumentException("holder name cannot be null or empty");
    }//  ww w  . java 2 s. c  om

    synchronized (filelock) {
        try {

            HashSet<String> set = new HashSet<String>();

            if (file.exists()) {
                ObjectInputStream inputStream = getSafeObjectInputStream(new FileInputStream(file));
                set = (HashSet<String>) inputStream.readObject();
                IOUtils.closeQuietly(inputStream);
            }

            set.removeAll(Arrays.asList(holderNames));

            if (set.isEmpty()) {
                FileUtils.deleteQuietly(file);
                return true;
            }

            ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream(file));
            outputStream.writeObject(set);
            IOUtils.closeQuietly(outputStream);
        } catch (ClassNotFoundException e) {
            log.error("Cannot release file", e);
        }
    }
    return false;
}

From source file:amie.keys.CombinationsExplorationNew.java

public static HashSet<HashSet<Integer>> powerSet(HashSet<Integer> originalSet) {
    HashSet<HashSet<Integer>> sets = new HashSet<HashSet<Integer>>();
    if (originalSet.isEmpty()) {
        sets.add(new HashSet<Integer>());
        return sets;
    }//from w ww  .j  a v a  2 s .c  o  m
    List<Integer> list = new ArrayList<Integer>(originalSet);
    int head = list.get(0);
    HashSet<Integer> rest = new HashSet<Integer>(list.subList(1, list.size()));
    for (HashSet<Integer> set : powerSet(rest)) {
        HashSet<Integer> newSet = new HashSet<Integer>();
        newSet.add(head);
        newSet.addAll(set);
        sets.add(newSet);
        sets.add(set);
    }
    return sets;
}