Example usage for java.util HashSet size

List of usage examples for java.util HashSet size

Introduction

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

Prototype

public int size() 

Source Link

Document

Returns the number of elements in this set (its cardinality).

Usage

From source file:org.apache.phoenix.jdbc.SecureUserConnectionsIT.java

@Test
public void testHostSubstitutionInUrl() throws Exception {
    final HashSet<ConnectionInfo> connections = new HashSet<>();
    final String princ1 = getServicePrincipal(1);
    final File keytab1 = getServiceKeytabFile(1);
    final String princ2 = getServicePrincipal(2);
    final File keytab2 = getServiceKeytabFile(2);
    final String url1 = joinUserAuthentication(BASE_URL, princ1, keytab1);
    final String url2 = joinUserAuthentication(BASE_URL, princ2, keytab2);

    // Using the same UGI should result in two equivalent ConnectionInfo objects
    connections.add(ConnectionInfo.create(url1).normalize(ReadOnlyProps.EMPTY_PROPS, EMPTY_PROPERTIES));
    assertEquals(1, connections.size());
    // Sanity check
    verifyAllConnectionsAreKerberosBased(connections);

    // Logging in as the same user again should not duplicate connections
    connections.add(ConnectionInfo.create(url1).normalize(ReadOnlyProps.EMPTY_PROPS, EMPTY_PROPERTIES));
    assertEquals(1, connections.size());
    // Sanity check
    verifyAllConnectionsAreKerberosBased(connections);

    // Add a second one.
    connections.add(ConnectionInfo.create(url2).normalize(ReadOnlyProps.EMPTY_PROPS, EMPTY_PROPERTIES));
    assertEquals(2, connections.size());
    verifyAllConnectionsAreKerberosBased(connections);

    // Again, verify this user is not duplicated
    connections.add(ConnectionInfo.create(url2).normalize(ReadOnlyProps.EMPTY_PROPS, EMPTY_PROPERTIES));
    assertEquals(2, connections.size());
    verifyAllConnectionsAreKerberosBased(connections);

    // Because the UGI instances are unique, so are the connections
    connections.add(ConnectionInfo.create(url1).normalize(ReadOnlyProps.EMPTY_PROPS, EMPTY_PROPERTIES));
    assertEquals(3, connections.size());
    verifyAllConnectionsAreKerberosBased(connections);
}

From source file:com.ryan.ryanreader.fragments.CommentListingFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {

    final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();

    if (info.position <= 0)
        return false;

    final Action action = Action.values()[item.getItemId()];
    final RedditPreparedComment comment = (RedditPreparedComment) lv.getAdapter().getItem(info.position);

    switch (action) {

    case UPVOTE:/*www  . j a  v a  2 s. com*/
        comment.action(getSupportActivity(), RedditAPI.RedditAction.UPVOTE);
        break;

    case DOWNVOTE:
        comment.action(getSupportActivity(), RedditAPI.RedditAction.DOWNVOTE);
        break;

    case UNVOTE:
        comment.action(getSupportActivity(), RedditAPI.RedditAction.UNVOTE);
        break;

    case REPORT:

        new AlertDialog.Builder(getSupportActivity()).setTitle(R.string.action_report)
                .setMessage(R.string.action_report_sure)
                .setPositiveButton(R.string.action_report, new DialogInterface.OnClickListener() {
                    public void onClick(final DialogInterface dialog, final int which) {
                        comment.action(getSupportActivity(), RedditAPI.RedditAction.REPORT);
                        // TODO update the view to show the result
                    }
                }).setNegativeButton(R.string.dialog_cancel, null).show();

        break;

    case REPLY: {
        final Intent intent = new Intent(getSupportActivity(), CommentReplyActivity.class);
        intent.putExtra("parentIdAndType", comment.idAndType);
        startActivity(intent);
        break;
    }

    case EDIT: {
        final Intent intent = new Intent(getSupportActivity(), CommentEditActivity.class);
        intent.putExtra("commentIdAndType", comment.idAndType);
        intent.putExtra("commentText", comment.src.body);
        startActivity(intent);
        break;
    }

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

        if (linksInComment.isEmpty()) {
            General.quickToast(getSupportActivity(), 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(getSupportActivity());
            builder.setItems(linksArr, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    LinkHandler.onLinkClicked(getSupportActivity(), 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.src.author + " on Reddit");

        // TODO this currently just dumps the markdown
        mailer.putExtra(Intent.EXTRA_TEXT, StringEscapeUtils.unescapeHtml4(comment.src.body));
        startActivityForResult(Intent.createChooser(mailer, context.getString(R.string.action_share)), 1);

        break;

    case COPY:

        ClipboardManager manager = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
        // TODO this currently just dumps the markdown
        manager.setText(StringEscapeUtils.unescapeHtml4(comment.src.body));
        break;

    case COLLAPSE:
        if (comment.getBoundView() != null)
            handleCommentVisibilityToggle(comment.getBoundView());
        break;

    case USER_PROFILE:
        UserProfileDialog.newInstance(comment.src.author).show(getSupportActivity());
        break;

    case PROPERTIES:
        CommentPropertiesDialog.newInstance(comment.src).show(getSupportActivity());
        break;

    }

    return true;
}

From source file:org.opendaylight.controller.clustering.services_implementation.internal.ClusteringServicesIT.java

@Test
public void clusterContainerAndGlobalTest()
        throws CacheExistException, CacheConfigException, CacheListenerAddException, InterruptedException {
    String cache1 = "Cache1";
    String cache2 = "Cache2";
    // Lets test the case of caches with same name in different
    // containers (actually global an container case)
    String cache3 = "Cache2";

    HashSet<cacheMode> cacheModeSet = new HashSet<cacheMode>();
    cacheModeSet.add(cacheMode.NON_TRANSACTIONAL);
    ConcurrentMap cm11 = this.clusterDefaultServices.createCache(cache1, cacheModeSet);
    assertNotNull(cm11);//from  ww  w.  ja v  a 2s  . co  m

    assertTrue(this.clusterDefaultServices.existCache(cache1));
    assertEquals(cm11, this.clusterDefaultServices.getCache(cache1));

    ConcurrentMap cm12 = this.clusterDefaultServices.createCache(cache2, cacheModeSet);
    ConcurrentMap cm23 = this.clusterGlobalServices.createCache(cache3, cacheModeSet);

    // Now given cahe2 and cache3 have same name lets make sure
    // they don't return the same reference
    assertNotNull(this.clusterGlobalServices.getCache(cache2));
    // cm12 reference must be different than cm23
    assertTrue(cm12 != cm23);

    HashSet<String> cacheList = (HashSet<String>) this.clusterDefaultServices.getCacheList();
    assertEquals(2, cacheList.size());
    assertTrue(cacheList.contains(cache1));
    assertTrue(cacheList.contains(cache2));

    assertNotNull(this.clusterDefaultServices.getCacheProperties(cache1));

    {
        /***********************************/
        /* Testing cacheAware in Container */
        /***********************************/
        Dictionary<String, Object> props = new Hashtable<String, Object>();
        Set<String> propSet = new HashSet<String>();
        propSet.add(cache1);
        propSet.add(cache2);
        props.put("cachenames", propSet);
        CacheAware listener = new CacheAware();
        CacheAware listenerRepeated = new CacheAware();
        ServiceRegistration updateServiceReg = ServiceHelper.registerServiceWReg(ICacheUpdateAware.class,
                "default", listener, props);
        assertNotNull(updateServiceReg);

        // Register another service for the same caches, this
        // should not get any update because we don't allow to
        // override the existing unless before unregistered
        ServiceRegistration updateServiceRegRepeated = ServiceHelper
                .registerServiceWReg(ICacheUpdateAware.class, "default", listenerRepeated, props);
        assertNotNull(updateServiceRegRepeated);
        CountDownLatch res = null;
        List<Update> ups = null;
        Update up = null;
        Integer k1 = new Integer(10);
        Long k2 = new Long(100L);

        /***********************/
        /* CREATE NEW KEY CASE */
        /***********************/
        // Start monitoring the updates
        res = listener.restart(2);
        // modify the cache
        cm11.put(k1, "foo");
        // Wait
        res.await(100L, TimeUnit.SECONDS);
        // Analyze the updates
        ups = listener.getUpdates();
        assertTrue(ups.size() == 2);
        // Validate that first we get an update (yes even in case of a
        // new value added)
        up = ups.get(0);
        assertTrue(up.t.equals(UpdateType.CHANGED));
        assertTrue(up.key.equals(k1));
        assertTrue(up.value.equals("foo"));
        assertTrue(up.cacheName.equals(cache1));
        // Validate that we then get a create
        up = ups.get(1);
        assertTrue(up.t.equals(UpdateType.ADDED));
        assertTrue(up.key.equals(k1));
        assertNull(up.value);
        assertTrue(up.cacheName.equals(cache1));

        /*******************************/
        /* UPDATE AN EXISTING KEY CASE */
        /*******************************/
        // Start monitoring the updates
        res = listener.restart(1);
        // modify the cache
        cm11.put(k1, "baz");
        // Wait
        res.await(100L, TimeUnit.SECONDS);
        // Analyze the updates
        ups = listener.getUpdates();
        assertTrue(ups.size() == 1);
        // Validate we get an update with expect fields
        up = ups.get(0);
        assertTrue(up.t.equals(UpdateType.CHANGED));
        assertTrue(up.key.equals(k1));
        assertTrue(up.value.equals("baz"));
        assertTrue(up.cacheName.equals(cache1));

        /**********************************/
        /* RE-UPDATE AN EXISTING KEY CASE */
        /**********************************/
        // Start monitoring the updates
        res = listener.restart(1);
        // modify the cache
        cm11.put(k1, "baz");
        // Wait
        res.await(100L, TimeUnit.SECONDS);
        // Analyze the updates
        ups = listener.getUpdates();
        assertTrue(ups.size() == 1);
        // Validate we get an update with expect fields
        up = ups.get(0);
        assertTrue(up.t.equals(UpdateType.CHANGED));
        assertTrue(up.key.equals(k1));
        assertTrue(up.value.equals("baz"));
        assertTrue(up.cacheName.equals(cache1));

        /********************************/
        /* REMOVAL OF EXISTING KEY CASE */
        /********************************/
        // Start monitoring the updates
        res = listener.restart(1);
        // modify the cache
        cm11.remove(k1);
        // Wait
        res.await(100L, TimeUnit.SECONDS);
        // Analyze the updates
        ups = listener.getUpdates();
        assertTrue(ups.size() == 1);
        // Validate we get a delete with expected fields
        up = ups.get(0);
        assertTrue(up.t.equals(UpdateType.REMOVED));
        assertTrue(up.key.equals(k1));
        assertNull(up.value);
        assertTrue(up.cacheName.equals(cache1));

        /***********************/
        /* CREATE NEW KEY CASE */
        /***********************/
        // Start monitoring the updates
        res = listener.restart(2);
        // modify the cache
        cm12.put(k2, new Short((short) 15));
        // Wait
        res.await(100L, TimeUnit.SECONDS);
        // Analyze the updates
        ups = listener.getUpdates();
        assertTrue(ups.size() == 2);
        // Validate that first we get an update (yes even in case of a
        // new value added)
        up = ups.get(0);
        assertTrue(up.t.equals(UpdateType.CHANGED));
        assertTrue(up.key.equals(k2));
        assertTrue(up.value.equals(new Short((short) 15)));
        assertTrue(up.cacheName.equals(cache2));
        // Validate that we then get a create
        up = ups.get(1);
        assertTrue(up.t.equals(UpdateType.ADDED));
        assertTrue(up.key.equals(k2));
        assertNull(up.value);
        assertTrue(up.cacheName.equals(cache2));

        /*******************************/
        /* UPDATE AN EXISTING KEY CASE */
        /*******************************/
        // Start monitoring the updates
        res = listener.restart(1);
        // modify the cache
        cm12.put(k2, "BAZ");
        // Wait
        res.await(100L, TimeUnit.SECONDS);
        // Analyze the updates
        ups = listener.getUpdates();
        assertTrue(ups.size() == 1);
        // Validate we get an update with expect fields
        up = ups.get(0);
        assertTrue(up.t.equals(UpdateType.CHANGED));
        assertTrue(up.key.equals(k2));
        assertTrue(up.value.equals("BAZ"));
        assertTrue(up.cacheName.equals(cache2));

        /********************************/
        /* REMOVAL OF EXISTING KEY CASE */
        /********************************/
        // Start monitoring the updates
        res = listener.restart(1);
        // modify the cache
        cm12.remove(k2);
        // Wait
        res.await(100L, TimeUnit.SECONDS);
        // Analyze the updates
        ups = listener.getUpdates();
        assertTrue(ups.size() == 1);
        // Validate we get a delete with expected fields
        up = ups.get(0);
        assertTrue(up.t.equals(UpdateType.REMOVED));
        assertTrue(up.key.equals(k2));
        assertNull(up.value);
        assertTrue(up.cacheName.equals(cache2));

        /******************************************************************/
        /* NOW LETS REMOVE THE REGISTRATION AND MAKE SURE NO UPDATS COMES */
        /******************************************************************/
        updateServiceReg.unregister();
        // Start monitoring the updates, noone should come in
        res = listener.restart(1);

        /***********************/
        /* CREATE NEW KEY CASE */
        /***********************/
        // modify the cache
        cm11.put(k1, "foo");

        /*******************************/
        /* UPDATE AN EXISTING KEY CASE */
        /*******************************/
        // modify the cache
        cm11.put(k1, "baz");

        /********************************/
        /* REMOVAL OF EXISTING KEY CASE */
        /********************************/
        // modify the cache
        cm11.remove(k1);

        /***********************/
        /* CREATE NEW KEY CASE */
        /***********************/
        // modify the cache
        cm12.put(k2, new Short((short) 15));

        /*******************************/
        /* UPDATE AN EXISTING KEY CASE */
        /*******************************/
        // modify the cache
        cm12.put(k2, "BAZ");

        /********************************/
        /* REMOVAL OF EXISTING KEY CASE */
        /********************************/
        // modify the cache
        cm12.remove(k2);

        // Wait to make sure no updates came in, clearly this is
        // error prone as logic, but cannot find a better way than
        // this to make sure updates didn't get in
        res.await(1L, TimeUnit.SECONDS);
        // Analyze the updates
        ups = listener.getUpdates();
        assertTrue(ups.size() == 0);
    }

    {
        /***********************************/
        /* Testing cacheAware in Global */
        /***********************************/
        Dictionary<String, Object> props = new Hashtable<String, Object>();
        Set<String> propSet = new HashSet<String>();
        propSet.add(cache3);
        props.put("cachenames", propSet);
        CacheAware listener = new CacheAware();
        ServiceRegistration updateServiceReg = ServiceHelper.registerGlobalServiceWReg(ICacheUpdateAware.class,
                listener, props);
        assertNotNull(updateServiceReg);

        CountDownLatch res = null;
        List<Update> ups = null;
        Update up = null;
        Integer k1 = new Integer(10);

        /***********************/
        /* CREATE NEW KEY CASE */
        /***********************/
        // Start monitoring the updates
        res = listener.restart(2);
        // modify the cache
        cm23.put(k1, "foo");
        // Wait
        res.await(100L, TimeUnit.SECONDS);
        // Analyze the updates
        ups = listener.getUpdates();
        assertTrue(ups.size() == 2);
        // Validate that first we get an update (yes even in case of a
        // new value added)
        up = ups.get(0);
        assertTrue(up.t.equals(UpdateType.CHANGED));
        assertTrue(up.key.equals(k1));
        assertTrue(up.value.equals("foo"));
        assertTrue(up.cacheName.equals(cache3));
        // Validate that we then get a create
        up = ups.get(1);
        assertTrue(up.t.equals(UpdateType.ADDED));
        assertTrue(up.key.equals(k1));
        assertNull(up.value);
        assertTrue(up.cacheName.equals(cache3));

        /*******************************/
        /* UPDATE AN EXISTING KEY CASE */
        /*******************************/
        // Start monitoring the updates
        res = listener.restart(1);
        // modify the cache
        cm23.put(k1, "baz");
        // Wait
        res.await(100L, TimeUnit.SECONDS);
        // Analyze the updates
        ups = listener.getUpdates();
        assertTrue(ups.size() == 1);
        // Validate we get an update with expect fields
        up = ups.get(0);
        assertTrue(up.t.equals(UpdateType.CHANGED));
        assertTrue(up.key.equals(k1));
        assertTrue(up.value.equals("baz"));
        assertTrue(up.cacheName.equals(cache3));

        /********************************/
        /* REMOVAL OF EXISTING KEY CASE */
        /********************************/
        // Start monitoring the updates
        res = listener.restart(1);
        // modify the cache
        cm23.remove(k1);
        // Wait
        res.await(100L, TimeUnit.SECONDS);
        // Analyze the updates
        ups = listener.getUpdates();
        assertTrue(ups.size() == 1);
        // Validate we get a delete with expected fields
        up = ups.get(0);
        assertTrue(up.t.equals(UpdateType.REMOVED));
        assertTrue(up.key.equals(k1));
        assertNull(up.value);
        assertTrue(up.cacheName.equals(cache3));

        /******************************************************************/
        /* NOW LETS REMOVE THE REGISTRATION AND MAKE SURE NO UPDATS COMES */
        /******************************************************************/
        updateServiceReg.unregister();
        // Start monitoring the updates, noone should come in
        res = listener.restart(1);

        /***********************/
        /* CREATE NEW KEY CASE */
        /***********************/
        // modify the cache
        cm23.put(k1, "foo");

        /*******************************/
        /* UPDATE AN EXISTING KEY CASE */
        /*******************************/
        // modify the cache
        cm23.put(k1, "baz");

        /********************************/
        /* REMOVAL OF EXISTING KEY CASE */
        /********************************/
        // modify the cache
        cm23.remove(k1);

        // Wait to make sure no updates came in, clearly this is
        // error prone as logic, but cannot find a better way than
        // this to make sure updates didn't get in
        res.await(1L, TimeUnit.SECONDS);
        // Analyze the updates
        ups = listener.getUpdates();
        assertTrue(ups.size() == 0);
    }

    InetAddress addr = this.clusterDefaultServices.getMyAddress();
    assertNotNull(addr);

    List<InetAddress> addrList = this.clusterDefaultServices.getClusteredControllers();

    this.clusterDefaultServices.destroyCache(cache1);
    assertFalse(this.clusterDefaultServices.existCache(cache1));
}

From source file:org.apache.sysml.runtime.compress.estim.CompressedSizeEstimatorSample.java

/**
 * TODO remove, just for local debugging.
 * /*  www .j a v a  2  s  .  com*/
 * @param colIndexes column indexes
 * @return exact number of district values
 */
@SuppressWarnings("unused")
private int getExactNumDistinctValues(int[] colIndexes) {
    HashSet<DblArray> distinctVals = new HashSet<DblArray>();
    ReaderColumnSelection reader = (_data.isInSparseFormat() && CompressedMatrixBlock.TRANSPOSE_INPUT)
            ? new ReaderColumnSelectionSparse(_data, colIndexes, !CompressedMatrixBlock.MATERIALIZE_ZEROS)
            : new ReaderColumnSelectionDense(_data, colIndexes, !CompressedMatrixBlock.MATERIALIZE_ZEROS);
    DblArray val = null;
    while (null != (val = reader.nextRow()))
        distinctVals.add(val);
    return distinctVals.size();
}

From source file:org.lol.reddit.fragments.CommentListingFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {

    final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();

    if (info.position <= 0) {
        return false;
    }//from  w  w  w  . ja  va 2s.  co  m

    final Object selectedObject = lv.getAdapter().getItem(info.position);

    if (!(selectedObject instanceof RedditCommentListItem)
            || !((RedditCommentListItem) selectedObject).isComment()) {
        return false;
    }

    final Action action = Action.values()[item.getItemId()];
    final RedditPreparedComment comment = ((RedditCommentListItem) selectedObject).asComment();

    switch (action) {

    case UPVOTE:
        comment.action(getSupportActivity(), RedditAPI.RedditAction.UPVOTE);
        break;

    case DOWNVOTE:
        comment.action(getSupportActivity(), RedditAPI.RedditAction.DOWNVOTE);
        break;

    case UNVOTE:
        comment.action(getSupportActivity(), RedditAPI.RedditAction.UNVOTE);
        break;

    case SAVE:
        comment.action(getSupportActivity(), RedditAPI.RedditAction.SAVE);
        break;

    case UNSAVE:
        comment.action(getSupportActivity(), RedditAPI.RedditAction.UNSAVE);
        break;

    case REPORT:

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

        break;

    case REPLY: {
        final Intent intent = new Intent(getSupportActivity(), CommentReplyActivity.class);
        intent.putExtra("parentIdAndType", comment.idAndType);
        startActivity(intent);
        break;
    }

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

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

        if (linksInComment.isEmpty()) {
            General.quickToast(getSupportActivity(), 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(getSupportActivity());
            builder.setItems(linksArr, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    LinkHandler.onLinkClicked(getSupportActivity(), 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.src.author + " on Reddit");

        // TODO this currently just dumps the markdown
        mailer.putExtra(Intent.EXTRA_TEXT, StringEscapeUtils.unescapeHtml4(comment.src.body));
        startActivityForResult(
                Intent.createChooser(mailer, getSupportActivity().getString(R.string.action_share)), 1);

        break;

    case COPY:

        ClipboardManager manager = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
        // TODO this currently just dumps the markdown
        manager.setText(StringEscapeUtils.unescapeHtml4(comment.src.body));
        break;

    case COLLAPSE:
        if (comment.getBoundView() != null) {
            handleCommentVisibilityToggle(comment.getBoundView());
        } else {
            General.quickToast(getSupportActivity(), "Error: Comment is no longer visible.");
        }
        break;

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

    case PROPERTIES:
        CommentPropertiesDialog.newInstance(comment.src).show(getSupportActivity());
        break;

    case GO_TO_COMMENT: {
        PostCommentListingURL url = new PostCommentListingURL(null, comment.src.link_id, comment.idAlone, null,
                null, null);
        LinkHandler.onLinkClicked(getSupportActivity(), url.toString());
        break;
    }

    case CONTEXT: {
        PostCommentListingURL url = new PostCommentListingURL(null, comment.src.link_id, comment.idAlone, 3,
                null, null);
        LinkHandler.onLinkClicked(getSupportActivity(), url.toString());
        break;
    }
    }

    return true;
}

From source file:com.sec.ose.osi.sdk.protexsdk.discovery.AbstractDiscoveryController.java

public static int curIdentifiedFileCount(String projectName) {
    HashSet<String> fileSet = new HashSet<String>();
    UIResponseObserver observer = null;//w ww  .  j a v  a2  s .  c  om
    ArrayList<String> files = new ArrayList<String>();

    ProjectDiscoveryControllerMap.loadProjectDiscoveryController(projectName, observer);

    files = ProjectDiscoveryControllerMap
            .getDiscoveryController(projectName, IdentificationConstantValue.STRING_MATCH_TYPE)
            .getPendingFileList();
    for (String file : files) {
        fileSet.add(file);
    }

    files = ProjectDiscoveryControllerMap
            .getDiscoveryController(projectName, IdentificationConstantValue.STRING_MATCH_TYPE)
            .getIdentifiedFileList();
    for (String file : files) {
        fileSet.add(file);
    }

    files = ProjectDiscoveryControllerMap
            .getDiscoveryController(projectName, IdentificationConstantValue.CODE_MATCH_TYPE)
            .getPendingFileList();
    for (String file : files) {
        fileSet.add(file);
    }

    files = ProjectDiscoveryControllerMap
            .getDiscoveryController(projectName, IdentificationConstantValue.CODE_MATCH_TYPE)
            .getIdentifiedFileList();
    for (String file : files) {
        fileSet.add(file);
    }

    files = ProjectDiscoveryControllerMap
            .getDiscoveryController(projectName, IdentificationConstantValue.PATTERN_MATCH_TYPE)
            .getPendingFileList();
    for (String file : files) {
        fileSet.add(file);
    }

    files = ProjectDiscoveryControllerMap
            .getDiscoveryController(projectName, IdentificationConstantValue.PATTERN_MATCH_TYPE)
            .getIdentifiedFileList();
    for (String file : files) {
        fileSet.add(file);
    }

    return fileSet.size();
}

From source file:com.sec.ose.osi.sdk.protexsdk.discovery.AbstractDiscoveryController.java

public static int originPendingFileCount(String projectName) {

    HashSet<String> fileSet = new HashSet<String>();
    UIResponseObserver observer = null;//from  w w  w  .ja va2  s. co m
    ArrayList<String> files = new ArrayList<String>();

    ProjectDiscoveryControllerMap.loadProjectDiscoveryController(projectName, observer);

    files = ProjectDiscoveryControllerMap
            .getDiscoveryController(projectName, IdentificationConstantValue.STRING_MATCH_TYPE)
            .getPendingFileList();
    for (String file : files) {
        fileSet.add(file);
    }

    files = ProjectDiscoveryControllerMap
            .getDiscoveryController(projectName, IdentificationConstantValue.STRING_MATCH_TYPE)
            .getIdentifiedFileList();
    for (String file : files) {
        fileSet.add(file);
    }

    files = ProjectDiscoveryControllerMap
            .getDiscoveryController(projectName, IdentificationConstantValue.CODE_MATCH_TYPE)
            .getPendingFileList();
    for (String file : files) {
        fileSet.add(file);
    }

    files = ProjectDiscoveryControllerMap
            .getDiscoveryController(projectName, IdentificationConstantValue.CODE_MATCH_TYPE)
            .getIdentifiedFileList();
    for (String file : files) {
        fileSet.add(file);
    }

    files = ProjectDiscoveryControllerMap
            .getDiscoveryController(projectName, IdentificationConstantValue.PATTERN_MATCH_TYPE)
            .getPendingFileList();
    for (String file : files) {
        fileSet.add(file);
    }

    files = ProjectDiscoveryControllerMap
            .getDiscoveryController(projectName, IdentificationConstantValue.PATTERN_MATCH_TYPE)
            .getIdentifiedFileList();
    for (String file : files) {
        fileSet.add(file);
    }

    return fileSet.size();
}

From source file:ch.unil.genescore.pathway.GeneSetLibrary.java

License:asdf

public void computeApproxPathwayCorrelation() {

    DenseMatrix corMat = new DenseMatrix(geneSets_.size(), geneSets_.size());
    for (int i = 0; i < geneSets_.size(); i++) {
        GeneSet leftSet = geneSets_.get(i);
        double leftSize = leftSet.genes_.size();
        for (int j = 0; j < geneSets_.size(); j++) {
            GeneSet rightSet = geneSets_.get(j);
            double rightSize = rightSet.genes_.size();
            HashSet<Gene> unpackedMetaGenes = new HashSet<Gene>();
            HashSet<Gene> allRightGenes = new HashSet<Gene>();
            if (null != rightSet.getMetaGenes())
                for (MetaGene mg : rightSet.getMetaGenes()) {
                    unpackedMetaGenes.addAll(mg.getGenes());
                }//  w ww  .j av a  2s. c  o  m

            allRightGenes.addAll(unpackedMetaGenes);
            allRightGenes.addAll(rightSet.genes_);
            allRightGenes.removeAll(rightSet.getMetaGenes());

            HashSet<Gene> copiedLeftGenes = new HashSet<Gene>(leftSet.genes_);
            copiedLeftGenes.retainAll(allRightGenes);
            double count = copiedLeftGenes.size();
            if (null != leftSet.getMetaGenes())
                for (MetaGene mg : leftSet.getMetaGenes()) {
                    TreeSet<Gene> mgSetCopy = new TreeSet<Gene>(mg.getGenes());
                    mgSetCopy.retainAll(allRightGenes);
                    if (!mgSetCopy.isEmpty()) {
                        count++;
                    }
                }
            double corr = count / Math.sqrt(leftSize * rightSize);
            corMat.set(i, j, corr);
            //corMat.set(j, i, corr);
        }
    }
    pathwayCorMat_ = corMat;
}

From source file:org.apache.phoenix.jdbc.SecureUserConnectionsIT.java

@Test
public void testAlternatingDestructiveLogins() throws Exception {
    final HashSet<ConnectionInfo> connections = new HashSet<>();
    final String princ1 = getUserPrincipal(1);
    final File keytab1 = getUserKeytabFile(1);
    final String princ2 = getUserPrincipal(2);
    final File keytab2 = getUserKeytabFile(2);
    final String url1 = joinUserAuthentication(BASE_URL, princ1, keytab1);
    final String url2 = joinUserAuthentication(BASE_URL, princ2, keytab2);

    UserGroupInformation.loginUserFromKeytab(princ1, keytab1.getPath());
    // Using the same UGI should result in two equivalent ConnectionInfo objects
    connections.add(ConnectionInfo.create(url1).normalize(ReadOnlyProps.EMPTY_PROPS, EMPTY_PROPERTIES));
    assertEquals(1, connections.size());
    // Sanity check
    verifyAllConnectionsAreKerberosBased(connections);

    UserGroupInformation.loginUserFromKeytab(princ2, keytab2.getPath());
    connections.add(ConnectionInfo.create(url2).normalize(ReadOnlyProps.EMPTY_PROPS, EMPTY_PROPERTIES));
    assertEquals(2, connections.size());
    verifyAllConnectionsAreKerberosBased(connections);

    // Because the UGI instances are unique, so are the connections
    UserGroupInformation.loginUserFromKeytab(princ1, keytab1.getPath());
    connections.add(ConnectionInfo.create(url1).normalize(ReadOnlyProps.EMPTY_PROPS, EMPTY_PROPERTIES));
    assertEquals(3, connections.size());
    verifyAllConnectionsAreKerberosBased(connections);
}

From source file:org.apache.phoenix.jdbc.SecureUserConnectionsIT.java

@Test
public void testMultipleUniqueUGIInstancesAreDisjoint() throws Exception {
    final HashSet<ConnectionInfo> connections = new HashSet<>();
    final String princ1 = getUserPrincipal(1);
    final File keytab1 = getUserKeytabFile(1);

    UserGroupInformation ugi = UserGroupInformation.loginUserFromKeytabAndReturnUGI(princ1, keytab1.getPath());

    PrivilegedExceptionAction<Void> callable = new PrivilegedExceptionAction<Void>() {
        public Void run() throws Exception {
            String url = joinUserAuthentication(BASE_URL, princ1, keytab1);
            connections.add(ConnectionInfo.create(url).normalize(ReadOnlyProps.EMPTY_PROPS, EMPTY_PROPERTIES));
            return null;
        }/*  ww  w  . j  a v a  2 s. com*/
    };

    ugi.doAs(callable);
    assertEquals(1, connections.size());
    verifyAllConnectionsAreKerberosBased(connections);

    // A second, but equivalent, call from the same "real" user but a different UGI instance
    // is expected functionality (programmer error).
    UserGroupInformation ugiCopy = UserGroupInformation.loginUserFromKeytabAndReturnUGI(princ1,
            keytab1.getPath());
    ugiCopy.doAs(callable);
    assertEquals(2, connections.size());
    verifyAllConnectionsAreKerberosBased(connections);
}