List of usage examples for java.util ArrayList contains
public boolean contains(Object o)
From source file:io.hops.metadata.StorageMap.java
/** * Adds or replaces storageinfo for the given sid *///from www .j a v a 2s .c o m public void updateStorage(final DatanodeStorageInfo storageInfo) throws IOException { // Allow lookup of storageId (String) <--> sid (int) String storageUuid = storageInfo.getStorageID(); storageInfo.setSid(getSetSId(storageUuid)); // Also write to the storages table (mapping DN-Sid-storagetype) final int sid = storageInfo.getSid(); final String datanodeUuid = storageInfo.getDatanodeDescriptor().getDatanodeUuid(); final int storageType = storageInfo.getStorageType().ordinal(); final String state = storageInfo.getState().toString(); // Get the list of storages we know to be on this DN ArrayList<Integer> sids = this.datanodeUuidToSids.get(datanodeUuid); if (sids == null) { // First time we see this DN sids = new ArrayList<Integer>(); this.datanodeUuidToSids.put(datanodeUuid, sids); } if (!sids.contains(sid)) { // We haven't seen this sid on this DN yet // Add in hashmap sids.add(sid); // Persist to database new HopsTransactionalRequestHandler(HDFSOperationType.UPDATE_SID_MAP) { @Override public void acquireLock(TransactionLocks locks) throws IOException { LockFactory lf = LockFactory.getInstance(); locks.add(lf.getVariableLock(Variable.Finder.StorageMap, LockType.READ_COMMITTED)); } @Override public Object performTask() throws StorageException, IOException { StorageDataAccess<Storage> da = (StorageDataAccess) HdfsStorageFactory .getDataAccess(StorageDataAccess.class); Storage h = da.findByPk(sid); if (h == null) { h = new Storage(sid, datanodeUuid, storageType, state); da.add(h); } return null; } }.handle(); } // Allow lookup of sid (int) -> DatanodeStorageInfo storageInfoMap.put(storageInfo.getSid(), storageInfo); }
From source file:com.novartis.opensource.yada.format.RESTResultDelimitedConverter.java
/** * Parses global harmony map for duplicate values, and removes key/value pairs that * are not present in local harmony map. * @return the parsed global harmony map * @since 6.1.0//from w w w.j a v a 2 s . co m */ @Override public Object getHarmonyMap() { JSONObject globMap = (JSONObject) this.harmonyMap; JSONObject local = new JSONObject(getYADAQueryResult().getYADAQueryParamValue(YADARequest.PS_HARMONYMAP)); ArrayList<Object> locVals = new ArrayList<>(); ArrayList<String> omit = new ArrayList<>(); for (Object k : local.keySet()) { locVals.add(local.get((String) k)); } for (Object globalKey : globMap.keySet()) { String gk = (String) globalKey; Object gv = globMap.get(gk); if (locVals.contains(gv) && !local.has(gk)) // the value is associated to a different key in the local map { omit.add(gk); } } for (String k : omit) { globMap.remove(k); } return globMap; }
From source file:edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.ExternalDataLookupOperator.java
@Override public VariablePropagationPolicy getVariablePropagationPolicy() { return new VariablePropagationPolicy() { @Override/*from w w w . j a va 2 s.c o m*/ public void propagateVariables(IOperatorSchema target, IOperatorSchema... sources) throws AlgebricksException { if (propagateInput) { ArrayList<LogicalVariable> usedVariables = new ArrayList<LogicalVariable>(); VariableUtilities.getUsedVariables(ExternalDataLookupOperator.this, usedVariables); int numOfSources = sources.length; for (int i = 0; i < numOfSources; i++) { for (LogicalVariable v : sources[i]) { if (!usedVariables.contains(v)) { target.addVariable(v); } } } } target.addVariable(variables.get(0)); } }; }
From source file:org.powertac.accounting.AccountingService.java
public void processTransaction(MarketTransaction tx, ArrayList<Object> messages) { MarketPosition mkt = tx.getBroker().findMarketPositionByTimeslot(tx.getTimeslotIndex()); if (!messages.contains(mkt)) messages.add(mkt);/*from w w w .j a v a 2s . c o m*/ }
From source file:com.hichinaschool.flashcards.anki.StudyOptionsActivity.java
/** Handles item selections */ @Override//from ww w.ja va 2s . c o m public boolean onOptionsItemSelected(MenuItem item) { Resources res = this.getResources(); switch (item.getItemId()) { case android.R.id.home: closeStudyOptions(); return true; case MENU_PREFERENCES: startActivityForResult(new Intent(this, Preferences.class), StudyOptionsFragment.PREFERENCES_UPDATE); if (AnkiDroidApp.SDK_VERSION > 4) { ActivityTransitionAnimation.slide(this, ActivityTransitionAnimation.FADE); } return true; case MENU_ROTATE: if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } else { this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } return true; case MENU_NIGHT: SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(this); if (preferences.getBoolean("invertedColors", false)) { preferences.edit().putBoolean("invertedColors", false).commit(); item.setIcon(R.drawable.ic_menu_night); } else { preferences.edit().putBoolean("invertedColors", true).commit(); item.setIcon(R.drawable.ic_menu_night_checked); } return true; case DeckPicker.MENU_CREATE_DYNAMIC_DECK: StyledDialog.Builder builder = new StyledDialog.Builder(StudyOptionsActivity.this); builder.setTitle(res.getString(R.string.new_deck)); mDialogEditText = new EditText(StudyOptionsActivity.this); ArrayList<String> names = AnkiDroidApp.getCol().getDecks().allNames(); int n = 1; String cramDeckName = "Cram 1"; while (names.contains(cramDeckName)) { n++; cramDeckName = "Cram " + n; } mDialogEditText.setText(cramDeckName); // mDialogEditText.setFilters(new InputFilter[] { mDeckNameFilter }); builder.setView(mDialogEditText, false, false); builder.setPositiveButton(res.getString(R.string.create), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { long id; Bundle initialConfig = new Bundle(); try { initialConfig.putString("searchSuffix", "'deck:" + AnkiDroidApp.getCol().getDecks().current().getString("name") + "'"); id = AnkiDroidApp.getCol().getDecks().newDyn(mDialogEditText.getText().toString()); AnkiDroidApp.getCol().getDecks().get(id); } catch (JSONException e) { throw new RuntimeException(e); } loadContent(false, initialConfig); } }); builder.setNegativeButton(res.getString(R.string.cancel), null); builder.create().show(); return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.clustercontrol.jobmanagement.factory.JobSessionJobImpl.java
public static void addForceCheck(String sessionId) { try {//w w w . j av a 2s .c o m _lock.writeLock(); ArrayList<String> cache = getForceCheckCache(); if (cache.contains(sessionId)) { return; } cache.add(sessionId); storeForceCheckCache(cache); } finally { _lock.writeUnlock(); } }
From source file:org.wso2.identity.integration.test.oauth2.OAuth2RoleClaimTestCase.java
@Test(groups = "wso2.is", description = "Check id_token after updating roles", dependsOnMethods = "testSendAuthorizedPost") public void testSendAuthorizedPostAfterRoleUpdate() throws Exception { remoteUSMServiceClient.updateRoleListOfUser(USERNAME, null, new String[] { OAUTH_ROLE }); HttpPost request = new HttpPost(OAuth2Constant.ACCESS_TOKEN_ENDPOINT); List<NameValuePair> urlParameters = new ArrayList<>(); urlParameters.add(new BasicNameValuePair("grant_type", OAuth2Constant.OAUTH2_GRANT_TYPE_RESOURCE_OWNER)); urlParameters//from ww w. j ava 2s . co m .add(new BasicNameValuePair("username", USERNAME + "@" + isServer.getContextTenant().getDomain())); urlParameters.add(new BasicNameValuePair("password", PASSWORD)); urlParameters.add(new BasicNameValuePair("scope", "openid")); request.setHeader("User-Agent", OAuth2Constant.USER_AGENT); request.setHeader("Authorization", "Basic " + Base64.encodeBase64String((consumerKey + ":" + consumerSecret).getBytes()).trim()); request.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8"); request.setEntity(new UrlEncodedFormEntity(urlParameters)); HttpResponse response = client.execute(request); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); Object obj = JSONValue.parse(rd); EntityUtils.consume(response.getEntity()); String encodedIdToken = ((JSONObject) obj).get("id_token").toString().split("\\.")[1]; Object idToken = JSONValue.parse(new String(Base64.decodeBase64(encodedIdToken))); Object roles = ((JSONObject) idToken).get(OIDC_ROLE_CLAIM_URI); ArrayList<String> roleList = new ArrayList<>(); for (int i = 0; i < ((JSONArray) roles).size(); i++) { roleList.add(((JSONArray) roles).get(i).toString()); } Assert.assertTrue(roleList.contains(OAUTH_ROLE), "Id token does not contain updated role claim"); }
From source file:fr.inria.atlanmod.neoemf.graph.blueprints.datastore.BlueprintsPersistenceBackendFactory.java
@Override protected SearcheableResourceEStore internalCreatePersistentEStore(PersistentResource resource, PersistenceBackend backend, Map<?, ?> options) throws InvalidDataStoreException { assert backend instanceof BlueprintsPersistenceBackend : "Trying to create a Graph-based EStore with an invalid backend"; @SuppressWarnings("unchecked") ArrayList<PersistentResourceOptions.StoreOption> storeOptions = (ArrayList<PersistentResourceOptions.StoreOption>) options .get(PersistentResourceOptions.STORE_OPTIONS); if (storeOptions == null || storeOptions.isEmpty() || storeOptions.contains(BlueprintsResourceOptions.EStoreGraphOption.DIRECT_WRITE)) { // Default store return new DirectWriteBlueprintsResourceEStoreImpl(resource, (BlueprintsPersistenceBackend) backend); } else {/* w w w .j a va 2s .c o m*/ if (storeOptions.contains(BlueprintsResourceOptions.EStoreGraphOption.AUTOCOMMIT)) { return new AutocommitBlueprintsResourceEStoreImpl(resource, (BlueprintsPersistenceBackend) backend); } else { throw new InvalidDataStoreException(); } } }
From source file:MSUmpire.PSMDataStructure.ProtID.java
public float GetAbundanceByTopCorrFragAcrossSample(ArrayList<String> ProPep, HashMap<String, ArrayList<String>> PepFrag) { float totalabundance = 0f; int count = 0; if (ProPep != null) { for (PepIonID pepIonID : PeptideID.values()) { if (ProPep.contains(pepIonID.GetKey())) { totalabundance += pepIonID .GetPepAbundanceByTopCorrFragAcrossSample(PepFrag.get(pepIonID.GetKey())); count++;//from w w w.ja v a 2s. co m } } } return totalabundance; }
From source file:edu.kit.scc.ldap.LdapClient.java
/** * Generates a non-conflicting user id number. * //from www. j a va 2 s . c o m * @return a new int uidNumber */ @Deprecated public int generateUserIdNumber() { int max = 99999; int min = 10000; Random rand = new Random(); ArrayList<String> existingUidNumbers = new ArrayList<String>(); List<PosixUser> users = ldapPosixUser.getAllUsers(); for (PosixUser user : users) { existingUidNumbers.add(user.getUidNumber()); } int randomInt = rand.nextInt((max - min) + 1) + min; while (existingUidNumbers.contains(String.valueOf(randomInt))) { randomInt = rand.nextInt((max - min) + 1) + min; } return randomInt; }