Example usage for java.util Set clear

List of usage examples for java.util Set clear

Introduction

In this page you can find the example usage for java.util Set clear.

Prototype

void clear();

Source Link

Document

Removes all of the elements from this set (optional operation).

Usage

From source file:org.apache.sling.jcr.repository.it.CommonTests.java

@Test
public void testOsgiResourceEvents() throws RepositoryException {
    final ResourceEventListener listener = new ResourceEventListener();
    final ServiceRegistration reg = listener.register(bundleContext, SlingConstants.TOPIC_RESOURCE_ADDED);
    final Session s = repository.loginAdministrative(null);
    final int nPaths = 2500 * TEST_SCALE;
    final int timeoutMsec = 2 * nPaths;
    final String prefix = uniqueName("testOsgiResourceEvents");

    // Create N nodes with a unique name under /
    // and verify that ResourceEventListener gets an event
    // for each of them
    try {/*from   ww  w.  jav  a2 s  .  co m*/
        for (int i = 0; i < nPaths; i++) {
            s.getRootNode().addNode(prefix + i);
        }
        s.save();

        log.info("Added {} nodes, checking what ResourceEventListener got...", nPaths);
        final long timeout = System.currentTimeMillis() + timeoutMsec;
        final Set<String> missing = new HashSet<String>();
        while (System.currentTimeMillis() < timeout) {
            missing.clear();
            final Set<String> paths = listener.getPaths();
            for (int i = 0; i < nPaths; i++) {
                final String path = "/" + prefix + i;
                if (!paths.contains(path)) {
                    missing.add(path);
                }
            }

            if (missing.isEmpty()) {
                break;
            }
        }

        if (!missing.isEmpty()) {
            final String missingStr = missing.size() > 10 ? missing.size() + " paths missing"
                    : missing.toString();
            fail("OSGi add resource events are missing for " + missing.size() + "/" + nPaths + " paths after "
                    + timeoutMsec + " msec: " + missingStr);
        }
    } finally {
        reg.unregister();
        s.logout();
    }

    log.info("Successfuly detected OSGi observation events for " + nPaths + " paths");
}

From source file:com.wbrenna.gtfsoffline.MainActivity.java

@Override
protected void onResume() {
    super.onResume();

    //we want to refresh the databases list
    Set<String> emptyString = new HashSet<String>();
    emptyString.clear();

    Set<String> initial_preferences = mPrefs.getStringSet(getString(R.string.pref_dbs), emptyString);

    //in case we're on a low-ram system and things aren't cached
    try {/*  ww w .  j av  a2  s  . co m*/
        if (!initial_preferences.equals(mDBListPrefsOld)) {

            mDBListPrefsOld = initial_preferences;
            //this is the list of currently checked databases
            mDBActive = null;
            //just to nullify the previous one.
            if (initial_preferences.size() != 0) {
                String[] tmpDBActive = initial_preferences.toArray(new String[initial_preferences.size()]);
                dbHelper.gatherFiles();
                mDBList = dbHelper.GetListofDB();
                List<String> workingDBList = new ArrayList<String>();

                for (int i = 0; i < tmpDBActive.length; i++) {
                    if (mDBList.contains(tmpDBActive[i])) {
                        workingDBList.add(tmpDBActive[i]);
                    }
                }
                if (workingDBList.size() == 0) {
                    mDBActive = null;
                } else {
                    mDBActive = workingDBList.toArray(new String[workingDBList.size()]);
                }
            }

            mSectionsPagerAdapter.notifyDataSetChanged();

            //totally kill the viewPager and all, and recreate!
            //mSectionsPagerAdapter = null;
            //getFragmentManager().beginTransaction().replace(containerViewId, fragment);
            //and create the appropriate tabs
            final ActionBar actionBar = getActionBar();

            /**mSectionsPagerAdapter = new SectionsPagerAdapter(
                  getSupportFragmentManager());
                    
            // Set up the ViewPager with the sections adapter.
            mViewPager = (ViewPager) findViewById(R.id.pager);
            mViewPager.setAdapter(mSectionsPagerAdapter);
                    
            mViewPager
                  .setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
             @Override
             public void onPageSelected(int position) {
                actionBar.setSelectedNavigationItem(position);
             }
                  });**/
            if (actionBar != null) {
                actionBar.removeAllTabs();
            }
            for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
                actionBar.addTab(
                        actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));

                //update the fragment contents
                /**if (i > 0 ) {
                   Fragment newFragment = new DBListFragment();
                   Bundle args = new Bundle();
                   args.putString(DBListFragment.DATABASE, mDBActive[i-1]);
                   newFragment.setArguments(args);
                           
                   getFragmentManager().beginTransaction().replace(i, newFragment);
                }**/
                if (i > 0) {
                    DBListFragment aFragment = (DBListFragment) getSupportFragmentManager()
                            .findFragmentByTag("android:switcher:" + R.id.pager + ":" + Integer.toString(i));
                    if (aFragment != null) {
                        getSupportFragmentManager().beginTransaction().remove(aFragment).commit();
                        mSectionsPagerAdapter.notifyDataSetChanged();
                        //if (aFragment.getView() != null) {
                        //aFragment.updateDisplay();
                        //}

                    }
                } else if (i == 0) {
                    FavSectionFragment aFavFragment = (FavSectionFragment) getSupportFragmentManager()
                            .findFragmentByTag("android:switcher:" + R.id.pager + ":" + Integer.toString(i));
                    if (aFavFragment != null) {
                        //getSupportFragmentManager().beginTransaction().remove(aFavFragment).commit();
                        //mSectionsPagerAdapter.notifyDataSetChanged();
                        //if (aFavFragment.getView() != null) {
                        //aFavFragment.updateDisplay();

                        //}
                        aFavFragment.updatePositions();

                    }
                }

            }
        }
    } finally {

        //restart location manager
        //mLocationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
        mLocationHelper.refresh(locationListener);
    }

}

From source file:net.solarnetwork.central.dras.dao.ibatis.test.IbatisEventDaoTest.java

@Test
public void resolveUsers() {
    // assign TEST_USER_ID to event indirectly, via participant group
    assignParticipantGroupMember();/* w w w  . j a  v a2 s.co  m*/

    setupTestUser(-8888L, "test.user.2");
    setupTestUser(-8887L, "test.user.3");

    // assign another user, via participant
    setupTestLocation(-7777L, "Another Location");
    setupTestParticipant(-8886L, -8888L, -7777L);
    Set<Long> memberIds = new HashSet<Long>(1);
    memberIds.add(-8886L);
    eventDao.assignParticipantMembers(lastEventId, memberIds, TEST_EFFECTIVE_ID);

    // assign another user, directly
    memberIds.clear();
    memberIds.add(-8887L);
    eventDao.assignUserMembers(lastEventId, memberIds, TEST_EFFECTIVE_ID);

    // now we should get our 3 users back
    Set<Member> results = eventDao.resolveUserMembers(lastEventId, null);
    assertNotNull(results);
    assertEquals(3, results.size());
    assertTrue(results.contains(new User(TEST_USER_ID)));
    assertTrue(results.contains(new User(-8888L)));
    assertTrue(results.contains(new User(-8887L)));
}

From source file:org.apache.solr.client.solrj.TestLBHttpSolrServer.java

public void testSimple() throws Exception {
    String[] s = new String[solr.length];
    for (int i = 0; i < solr.length; i++) {
        s[i] = solr[i].getUrl();/*from  w  ww .ja va2 s .  com*/
    }
    LBHttpSolrServer lbHttpSolrServer = new LBHttpSolrServer(httpClient, s);
    lbHttpSolrServer.setAliveCheckInterval(500);
    SolrQuery solrQuery = new SolrQuery("*:*");
    Set<String> names = new HashSet<String>();
    QueryResponse resp = null;
    for (String value : s) {
        resp = lbHttpSolrServer.query(solrQuery);
        assertEquals(10, resp.getResults().getNumFound());
        names.add(resp.getResults().get(0).getFieldValue("name").toString());
    }
    assertEquals(3, names.size());

    // Kill a server and test again
    solr[1].jetty.stop();
    solr[1].jetty = null;
    names.clear();
    for (String value : s) {
        resp = lbHttpSolrServer.query(solrQuery);
        assertEquals(10, resp.getResults().getNumFound());
        names.add(resp.getResults().get(0).getFieldValue("name").toString());
    }
    assertEquals(2, names.size());
    assertFalse(names.contains("solr1"));

    // Start the killed server once again
    solr[1].startJetty();
    // Wait for the alive check to complete
    Thread.sleep(1200);
    names.clear();
    for (String value : s) {
        resp = lbHttpSolrServer.query(solrQuery);
        assertEquals(10, resp.getResults().getNumFound());
        names.add(resp.getResults().get(0).getFieldValue("name").toString());
    }
    assertEquals(3, names.size());
}

From source file:org.apache.cocoon.forms.util.WidgetFinder.java

/**
 * Called when a repeater clear event is received from a monitored repeater.
 * @param repeater The repeated that generated the event.
 *//*from  ww  w .ja v  a  2s. c  om*/
protected void refreshForClear(Repeater repeater) {
    Set widgets = (Set) this.repeaterWidgets.get(repeater);
    for (Iterator iter = widgets.iterator(); iter.hasNext();) {
        Widget widget = (Widget) iter.next();
        if (widget instanceof Repeater) {
            if (this.repeaterPaths != null)
                this.repeaterPaths.remove(widget);
            this.repeaterWidgets.remove(widget);
        }
    }
    widgets.clear();
}

From source file:org.openmrs.module.drughistory.api.RegimenServiceTest.java

/**
 * @verifies only return regimens matching drugs in the snapshot
 * @see RegimenService#getRegimensFromSnapshot(org.openmrs.module.drughistory.DrugSnapshot)
 *///from  ww  w. j  av  a  2s .c o  m
@Test
public void getRegimensFromSnapshot_shouldOnlyReturnRegimensMatchingDrugsInTheSnapshot() throws Exception {
    Set<Concept> drugs = new HashSet<Concept>();
    drugs.add(Context.getConceptService().getConcept(3));
    drugs.add(Context.getConceptService().getConcept(88));
    drugs.add(Context.getConceptService().getConcept(792));

    Context.getService(RegimenService.class).saveRegimen(
            new Regimen("A", "A Desc", Regimen.LINE_FIRST, Regimen.AGE_ADULT, new HashSet<Concept>(drugs)));

    drugs.clear();
    drugs.add(Context.getConceptService().getConcept(11));
    drugs.add(Context.getConceptService().getConcept(12));
    drugs.add(Context.getConceptService().getConcept(13));

    Context.getService(RegimenService.class).saveRegimen(
            new Regimen("B", "B Desc", Regimen.LINE_FIRST, Regimen.AGE_ADULT, new HashSet<Concept>(drugs)));

    drugs.clear();
    drugs.add(Context.getConceptService().getConcept(3));
    drugs.add(Context.getConceptService().getConcept(88));
    drugs.add(Context.getConceptService().getConcept(13));

    Context.getService(RegimenService.class).saveRegimen(
            new Regimen("C", "C Desc", Regimen.LINE_FIRST, Regimen.AGE_ADULT, new HashSet<Concept>(drugs)));

    DrugSnapshot ds = new DrugSnapshot();
    ds.setConcepts(new HashSet<Concept>(drugs));

    List<Regimen> actual = Context.getService(RegimenService.class).getRegimensFromSnapshot(ds);

    assertNotNull(actual);
    assertEquals(1, actual.size());
    assertEquals("C", actual.get(0).getName());
}

From source file:no.abmu.finances.utils.FinanceImporter.java

private Post getNewPost(Session session) throws HibernateException {

    String code = excelParser.getPostCode();
    PostType postType = getPostType(session);
    PostPeriod period = getPeriod(session);

    PostFinderSpecification finderSpecification = new PostFinderSpecification(code);
    Criteria criteria = finderSpecification.createCriteria(session);

    List<Post> list = criteria.list();

    Post retPost = null;//from w  ww. j a v a2s  .  com
    if (list.size() == 0) {
        retPost = createNewPost();
        retPost.setPostType(postType);
        retPost.setPeriod(period);
        session.save(retPost);
        logger.info("NEW POST: " + retPost);
        validatorLogging(retPost);
    } else if (list.size() == 1) {
        retPost = list.get(0);
        String postValueType = excelParser.getPostValueType();
        if (!postValueType.equals(retPost.getClass().getName())) {
            logger.error("");
            logger.error(
                    "      XXXXXXXXXXXXXXXXXX OLD NOT SAME AS DEFINITION IN NEW SCHEMA  XXXXXXXXXXXXXXXXXXXX");
            logger.error("");
        }
        Set validators = retPost.getValidators();
        logger.info("Number of validators befor clearing existing validators: '" + validators.size() + "'");
        validators.clear();
        addNewValidators(retPost);
        retPost.setPeriod(period);
        session.save(retPost);
        logger.info("OLD POST: " + retPost);
        validatorLogging(retPost);
    } else {
        retPost = list.get(0);
        logger.warn("");
        logger.warn(" ZZZZZZZ More than on post number of posts: " + list.size() + "'");
        logger.warn("");
        for (Post tmpPost : list) {
            logger.info("OLD POSTS: " + tmpPost.toString());
            validatorLogging(tmpPost);
        }
    }

    return retPost;
}

From source file:org.apache.syncope.core.util.ContentExporter.java

private List<String> sortByForeignKeys(final Connection conn, final Set<String> tableNames)
        throws SQLException {

    Set<MultiParentNode<String>> roots = new HashSet<MultiParentNode<String>>();

    final DatabaseMetaData meta = conn.getMetaData();

    final Map<String, MultiParentNode<String>> exploited = new TreeMap<String, MultiParentNode<String>>(
            String.CASE_INSENSITIVE_ORDER);

    final Set<String> pkTableNames = new HashSet<String>();

    for (String tableName : tableNames) {
        MultiParentNode<String> node = exploited.get(tableName);
        if (node == null) {
            node = new MultiParentNode<String>(tableName);
            roots.add(node);/*from w w w  . j  av a  2 s .  c om*/
            exploited.put(tableName, node);
        }

        pkTableNames.clear();

        ResultSet rs = null;
        try {
            rs = meta.getImportedKeys(conn.getCatalog(), dbSchema, tableName);

            // this is to avoid repetition
            while (rs.next()) {
                pkTableNames.add(rs.getString("PKTABLE_NAME"));
            }
        } finally {
            if (rs != null) {
                try {
                    rs.close();
                } catch (SQLException e) {
                    LOG.error("While closing tables result set", e);
                }
            }
        }

        for (String pkTableName : pkTableNames) {
            if (!tableName.equalsIgnoreCase(pkTableName)) {
                MultiParentNode<String> pkNode = exploited.get(pkTableName);
                if (pkNode == null) {
                    pkNode = new MultiParentNode<String>(pkTableName);
                    roots.add(pkNode);
                    exploited.put(pkTableName, pkNode);
                }

                pkNode.addChild(node);

                if (roots.contains(node)) {
                    roots.remove(node);
                }
            }
        }
    }

    final List<String> sortedTableNames = new ArrayList<String>(tableNames.size());
    MultiParentNodeOp.traverseTree(roots, sortedTableNames);

    // remove from sortedTableNames any table possibly added during lookup 
    // but matching some item in this.tablePrefixesToBeExcluded
    sortedTableNames.retainAll(tableNames);

    LOG.debug("Tables after retainAll {}", sortedTableNames);

    Collections.reverse(sortedTableNames);

    return sortedTableNames;
}

From source file:org.apache.solr.client.solrj.TestLBHttpSolrClient.java

public void testSimple() throws Exception {
    String[] s = new String[solr.length];
    for (int i = 0; i < solr.length; i++) {
        s[i] = solr[i].getUrl();/*from w ww.  jav a  2 s . co  m*/
    }
    LBHttpSolrClient client = getLBHttpSolrClient(httpClient, s);
    client.setAliveCheckInterval(500);
    SolrQuery solrQuery = new SolrQuery("*:*");
    Set<String> names = new HashSet<>();
    QueryResponse resp = null;
    for (String value : s) {
        resp = client.query(solrQuery);
        assertEquals(10, resp.getResults().getNumFound());
        names.add(resp.getResults().get(0).getFieldValue("name").toString());
    }
    assertEquals(3, names.size());

    // Kill a server and test again
    solr[1].jetty.stop();
    solr[1].jetty = null;
    names.clear();
    for (String value : s) {
        resp = client.query(solrQuery);
        assertEquals(10, resp.getResults().getNumFound());
        names.add(resp.getResults().get(0).getFieldValue("name").toString());
    }
    assertEquals(2, names.size());
    assertFalse(names.contains("solr1"));

    // Start the killed server once again
    solr[1].startJetty();
    // Wait for the alive check to complete
    Thread.sleep(1200);
    names.clear();
    for (String value : s) {
        resp = client.query(solrQuery);
        assertEquals(10, resp.getResults().getNumFound());
        names.add(resp.getResults().get(0).getFieldValue("name").toString());
    }
    assertEquals(3, names.size());
}

From source file:ome.security.basic.CurrentDetails.java

/**
 * Returns the current cleanups and resets the {@link Set}. Instances can
 * most likely only be closed once, so it doesn't make sense to keep them
 * around. The first caller of this method is responsible for closing all of
 * them./*from w  ww . j  a  v a2 s  .  c o m*/
 */
public Set<RegisterServiceCleanupMessage> emptyCleanups() {
    Set<RegisterServiceCleanupMessage> set = current().getServiceCleanups();
    if (current().getServiceCleanups() == null) {
        return Collections.emptySet();
    } else {
        Set<RegisterServiceCleanupMessage> copy = new HashSet<RegisterServiceCleanupMessage>(set);
        set.clear();
        return copy;
    }
}