List of usage examples for java.util Set equals
boolean equals(Object o);
From source file:me.philio.ghost.ui.NavigationDrawerFragment.java
/** * Check to see if accounts have changed and fix any stale data/UI *//*from w w w. java 2 s. c o m*/ private void checkAccounts() { Account[] accounts = mAccountManager.getAccountsByType(getString(R.string.account_type)); List<Account> currentAcccounts = new ArrayList<>(Arrays.asList(accounts)); // If no accounts found bump to the splash screen if (currentAcccounts.size() == 0) { Intent intent = new Intent(getActivity(), SplashActivity.class); startActivity(intent); getActivity().finish(); return; } // Look for account changes Set<Account> existingSet = new HashSet<>(); existingSet.addAll(mAccounts); Set<Account> currentSet = new HashSet<>(); currentSet.addAll(currentAcccounts); if (!currentSet.equals(existingSet)) { mAccounts = currentAcccounts; if (!mAccounts.contains(mSelectedAccount)) { changeAccount(mAccounts.get(0)); } else { populateAccountItems(); } } }
From source file:org.apache.geode.internal.cache.DiskRegionAsyncRecoveryJUnitTest.java
/** * Test to make sure that we create missing krfs when we restart the system. */// w w w.j ava2 s . c o m @Test public void testKrfCreatedAfterRestart() throws InterruptedException, IOException { LocalRegion region = (LocalRegion) createRegion(); putEntries(region, 0, 5, "A"); putEntries(region, 0, 1, "B"); invalidateEntries(region, 1, 2); removeEntries(region, 2, 3); // this ensures we don't get a chance to create a krf // but instead recover from the crf backupDisk(); cache.close(); restoreDisk(); cache = createCache(); // no go ahead and recover region = (LocalRegion) createRegion(); putEntries(region, 5, 10, "A"); DiskStoreImpl store = (DiskStoreImpl) cache.findDiskStore(region.getAttributes().getDiskStoreName()); // Create a new oplog, to make sure we still create a krf for the old oplog. store.forceRoll(); putEntries(region, 10, 15, "A"); PersistentOplogSet set = store.getPersistentOplogSet(region.getDiskRegion()); String currentChild = set.getChild().getOplogFile().getName(); // Wait for the krfs to be created Set<String> crfs; Set<String> krfs; long end = System.nanoTime() + TimeUnit.SECONDS.toNanos(10); do { crfs = new HashSet<String>(); krfs = new HashSet<String>(); getCrfsAndKrfs(crfs, krfs); // Remove the current child because it does not have a krf crfs.remove(currentChild.split("\\.")[0]); } while (!crfs.equals(krfs) && System.nanoTime() < end); // Make sure all of the crfs have krfs assertEquals("KRFS were not created within 30 seconds", crfs, krfs); cache.close(); crfs = new HashSet<String>(); krfs = new HashSet<String>(); getCrfsAndKrfs(crfs, krfs); assertEquals("last krf was not created on cache close", crfs, krfs); }
From source file:com.inmobi.conduit.local.LocalStreamServiceTest.java
private void validateExpectedOutput(Set<String> results, Set<String> trashPaths, Map<String, String> checkPointPaths) { assert results.equals(expectedResults); assert trashPaths.equals(expectedTrashPaths); assert checkPointPaths.equals(expectedCheckPointPaths); }
From source file:com.opengamma.engine.view.ViewDefinition.java
@Override public boolean equals(final Object obj) { if (this == obj) { return true; }/*from w w w . j av a 2 s .c om*/ if (!(obj instanceof ViewDefinition)) { return false; } final ViewDefinition other = (ViewDefinition) obj; final boolean basicPropertiesEqual = ObjectUtils.equals(getName(), other.getName()) && ObjectUtils.equals(getPortfolioId(), other.getPortfolioId()) && ObjectUtils.equals(getResultModelDefinition(), other.getResultModelDefinition()) && ObjectUtils.equals(getMarketDataUser(), other.getMarketDataUser()) && ObjectUtils.equals(_minDeltaCalculationPeriod, other._minDeltaCalculationPeriod) && ObjectUtils.equals(_maxDeltaCalculationPeriod, other._maxDeltaCalculationPeriod) && ObjectUtils.equals(_minFullCalculationPeriod, other._minFullCalculationPeriod) && ObjectUtils.equals(_maxFullCalculationPeriod, other._maxFullCalculationPeriod) && ObjectUtils.equals(_dumpComputationCacheToDisk, other._dumpComputationCacheToDisk) && ObjectUtils.equals(getAllCalculationConfigurationNames(), other.getAllCalculationConfigurationNames()) && ObjectUtils.equals(_defaultCurrency, other._defaultCurrency); if (!basicPropertiesEqual) { return false; } final Set<ViewCalculationConfiguration> localConfigs = new HashSet<ViewCalculationConfiguration>( _calculationConfigurationsByName.values()); final Set<ViewCalculationConfiguration> otherConfigs = new HashSet<ViewCalculationConfiguration>( other.getAllCalculationConfigurations()); return localConfigs.equals(otherConfigs); }
From source file:org.topazproject.mulgara.resolver.CacheInvalidator.java
private Set<String> getKeysFromQuery(ModItem mi) { Set<String> keys = new HashSet<String>(); // get our session if (session == null) { session = newSession();/*from w w w. ja va 2 s. c om*/ if (session == null) return keys; logger.info("Created session"); } try { // do the query Map<String, Set<String>> res = getQueryResults(mi.query, session); // get previous results Map<String, Set<String>> prevRes = (mi.beforeMod != null) ? mi.beforeMod : Collections.EMPTY_MAP; if (logger.isTraceEnabled()) logger.trace("Previous query results: " + prevRes); // invalidate new or changed values for (String key : res.keySet()) { Set<String> vals = res.get(key); Set<String> ovals = prevRes.get(key); if (ovals == null || !ovals.equals(vals)) keys.add(key); } if (logger.isTraceEnabled()) logger.trace("New or updated keys: " + keys); // invalidate deleted values Set<String> remKeys = new HashSet<String>(prevRes.keySet()); remKeys.removeAll(res.keySet()); keys.addAll(remKeys); if (logger.isTraceEnabled()) logger.trace("Removed keys: " + remKeys); // update cache if anything changed if (!keys.isEmpty() && queryCache != null) queryCache.put(new net.sf.ehcache.Element(new QCacheKey(mi), res)); } catch (Exception e) { logger.error("Error executing query '" + mi.query + "'", e); } return keys; }
From source file:org.intermine.pathquery.LogicExpression.java
/** * Validates an expression for the given groups of codes, making sure each group is only * ANDed together. Returns either this or an alternative LogicExpression. * * @param variables a List of Collections of String variable names * @return a new LogicExpression/* ww w . ja va 2s . co m*/ */ public LogicExpression validateForGroups(List<? extends Collection<String>> variables) { // First, check whether the expression is already valid try { split(variables); return this; } catch (IllegalArgumentException e) { } // It is not valid, so alter it. Set<String> presentVariables = new HashSet<String>(); for (Collection<String> v : variables) { for (String var : v) { if (presentVariables.contains(var)) { throw new IllegalArgumentException("There is an overlap in variables"); } presentVariables.add(var); } } if (!presentVariables.equals(getVariableNames())) { throw new IllegalArgumentException("Variables in argument (" + presentVariables + ") do not match variables in expression (" + getVariableNames() + ")"); } List<String> subLogics = new ArrayList<String>(); for (Collection<String> group : variables) { if (group.containsAll(presentVariables)) { // In this case all constraints are lumped together, but cannot be or-ed. subLogics = new ArrayList<String>(Arrays.asList(StringUtils.join(group, " and "))); } else { LogicExpression copy = new LogicExpression(toString()); try { copy.removeAllVariablesExcept(group); subLogics.add("(" + copy + ")"); } catch (IllegalArgumentException e) { // Must have removed all variables } } } String retval = StringUtils.join(subLogics, " and "); return new LogicExpression(retval); }
From source file:org.duracloud.account.db.util.impl.DuracloudUserServiceImpl.java
private boolean doSetUserRights(Long acctId, Long userId, Set<Role> roles) { if (null == roles) { throw new IllegalArgumentException("Role may not be null"); }/*from w ww . j a v a 2s . c om*/ Set<Role> oldRoles = null; Set<Role> newRoles = new HashSet<Role>(); for (Role role : roles) { newRoles.addAll(role.getRoleHierarchy()); } DuracloudRightsRepo rightsRepo = repoMgr.getRightsRepo(); AccountRights rights = rightsRepo.findByAccountIdAndUserId(acctId, userId); if (rights != null) { oldRoles = rights.getRoles(); } else { log.info("New rights will be added for user {} on account {}", userId, acctId); } boolean updatedNeeded = !newRoles.equals(oldRoles); if (updatedNeeded) { saveRights(acctId, userId, newRoles, rights); } return updatedNeeded; }
From source file:gov.nasa.ensemble.core.jscience.csvxml.ProfileLoader.java
private void validateHeaderRow(Collection<String> csvHeaders) throws ProfileLoadingException { Set<String> actualCsvHeaders = new HashSet<String>(); Set<String> expectedHeadersFromXml = new HashSet<String>(); int i = 0;/*from w w w .j a v a 2 s. c o m*/ for (String header : csvHeaders) { if (i++ >= ONE_FOR_STARTTIME) { actualCsvHeaders.add(header.toLowerCase()); } } for (ProfileAndMetadata profileEtc : profileAndMetadataInXmlOrder) { expectedHeadersFromXml.add(profileEtc.getProfile().getId().toLowerCase()); } if (!actualCsvHeaders.equals(expectedHeadersFromXml)) { throw new ProfileLoadingException("XML declares column names as '" + expectedHeadersFromXml + "' but CSV headings are '" + actualCsvHeaders); } }
From source file:de.dfki.iui.mmds.scxml.engine.impl.SCXMLEngineImpl.java
/** * @param lastLeafs/* ww w . j av a2s. c om*/ * @return */ private void updateConfigHistory(Set<TransitionTarget> lastLeafs) { if (lastLeafs.equals(engine.getCurrentStatus().getStates())) // only update the history if there was a change in the // configuration return; int histSize = configHistory.size(); if (0 < histSize && histSize == CONFIG_HISTORY_SIZE) { configHistory.pollLast(); } if (configHistory.size() < CONFIG_HISTORY_SIZE) { Set<TransitionTarget> leafs = engine.getCurrentStatus().getStates(); Set<String> leafStateIds = new HashSet<String>(leafs.size()); for (TransitionTarget tt : leafs) { leafStateIds.add(tt.getId()); } configHistory.push(leafStateIds); } }
From source file:org.apache.sentry.provider.db.service.persistent.TestSentryStoreImportExport.java
private void verifyGroupRolesMap(Map<String, Set<String>> actualGroupRolesMap, Map<String, Set<String>> exceptedGroupRolesMap) { assertEquals(exceptedGroupRolesMap.keySet().size(), actualGroupRolesMap.keySet().size()); for (String groupName : actualGroupRolesMap.keySet()) { Set<String> exceptedRoles = exceptedGroupRolesMap.get(groupName); Set<String> actualRoles = actualGroupRolesMap.get(groupName); assertEquals(actualRoles.size(), exceptedRoles.size()); assertTrue(actualRoles.equals(exceptedRoles)); }//from w w w . j a v a 2 s. c o m }