List of usage examples for java.util HashSet addAll
boolean addAll(Collection<? extends E> c);
From source file:org.apache.hadoop.yarn.server.resourcemanager.recovery.TestRMStateStore.java
void testRMAppStateStore(RMStateStoreHelper stateStoreHelper) throws Exception { long submitTime = System.currentTimeMillis(); Configuration conf = new YarnConfiguration(); RMStateStore store = stateStoreHelper.getRMStateStore(); TestDispatcher dispatcher = new TestDispatcher(); store.setRMDispatcher(dispatcher);/*from ww w . ja v a 2s . c o m*/ AMRMTokenSecretManager appTokenMgr = new AMRMTokenSecretManager(conf); ClientToAMTokenSecretManagerInRM clientToAMTokenMgr = new ClientToAMTokenSecretManagerInRM(); ApplicationAttemptId attemptId1 = ConverterUtils .toApplicationAttemptId("appattempt_1352994193343_0001_000001"); ApplicationId appId1 = attemptId1.getApplicationId(); storeApp(store, appId1, submitTime); // create application token and client token key for attempt1 Token<AMRMTokenIdentifier> appAttemptToken1 = generateAMRMToken(attemptId1, appTokenMgr); HashSet<Token<?>> attemptTokenSet1 = new HashSet<Token<?>>(); attemptTokenSet1.add(appAttemptToken1); SecretKey clientTokenKey1 = clientToAMTokenMgr.createMasterKey(attemptId1); ContainerId containerId1 = storeAttempt(store, attemptId1, "container_1352994193343_0001_01_000001", appAttemptToken1, clientTokenKey1, dispatcher); String appAttemptIdStr2 = "appattempt_1352994193343_0001_000002"; ApplicationAttemptId attemptId2 = ConverterUtils.toApplicationAttemptId(appAttemptIdStr2); // create application token and client token key for attempt2 Token<AMRMTokenIdentifier> appAttemptToken2 = generateAMRMToken(attemptId2, appTokenMgr); HashSet<Token<?>> attemptTokenSet2 = new HashSet<Token<?>>(); attemptTokenSet2.add(appAttemptToken2); SecretKey clientTokenKey2 = clientToAMTokenMgr.createMasterKey(attemptId2); ContainerId containerId2 = storeAttempt(store, attemptId2, "container_1352994193343_0001_02_000001", appAttemptToken2, clientTokenKey2, dispatcher); ApplicationAttemptId attemptIdRemoved = ConverterUtils .toApplicationAttemptId("appattempt_1352994193343_0002_000001"); ApplicationId appIdRemoved = attemptIdRemoved.getApplicationId(); storeApp(store, appIdRemoved, submitTime); storeAttempt(store, attemptIdRemoved, "container_1352994193343_0002_01_000001", null, null, dispatcher); RMApp mockRemovedApp = mock(RMApp.class); HashMap<ApplicationAttemptId, RMAppAttempt> attempts = new HashMap<ApplicationAttemptId, RMAppAttempt>(); ApplicationSubmissionContext context = new ApplicationSubmissionContextPBImpl(); context.setApplicationId(appIdRemoved); when(mockRemovedApp.getSubmitTime()).thenReturn(submitTime); when(mockRemovedApp.getApplicationSubmissionContext()).thenReturn(context); when(mockRemovedApp.getAppAttempts()).thenReturn(attempts); RMAppAttempt mockRemovedAttempt = mock(RMAppAttempt.class); when(mockRemovedAttempt.getAppAttemptId()).thenReturn(attemptIdRemoved); attempts.put(attemptIdRemoved, mockRemovedAttempt); store.removeApplication(mockRemovedApp); // let things settle down Thread.sleep(1000); store.close(); // load state store = stateStoreHelper.getRMStateStore(); RMState state = store.loadState(); Map<ApplicationId, ApplicationState> rmAppState = state.getApplicationState(); ApplicationState appState = rmAppState.get(appId1); // app is loaded assertNotNull(appState); // app is loaded correctly assertEquals(submitTime, appState.getSubmitTime()); // submission context is loaded correctly assertEquals(appId1, appState.getApplicationSubmissionContext().getApplicationId()); ApplicationAttemptState attemptState = appState.getAttempt(attemptId1); // attempt1 is loaded correctly assertNotNull(attemptState); assertEquals(attemptId1, attemptState.getAttemptId()); // attempt1 container is loaded correctly assertEquals(containerId1, attemptState.getMasterContainer().getId()); // attempt1 applicationToken is loaded correctly HashSet<Token<?>> savedTokens = new HashSet<Token<?>>(); savedTokens.addAll(attemptState.getAppAttemptCredentials().getAllTokens()); assertEquals(attemptTokenSet1, savedTokens); // attempt1 client token master key is loaded correctly assertArrayEquals(clientTokenKey1.getEncoded(), attemptState.getAppAttemptCredentials().getSecretKey(RMStateStore.AM_CLIENT_TOKEN_MASTER_KEY_NAME)); attemptState = appState.getAttempt(attemptId2); // attempt2 is loaded correctly assertNotNull(attemptState); assertEquals(attemptId2, attemptState.getAttemptId()); // attempt2 container is loaded correctly assertEquals(containerId2, attemptState.getMasterContainer().getId()); // attempt2 applicationToken is loaded correctly savedTokens.clear(); savedTokens.addAll(attemptState.getAppAttemptCredentials().getAllTokens()); assertEquals(attemptTokenSet2, savedTokens); // attempt2 client token master key is loaded correctly assertArrayEquals(clientTokenKey2.getEncoded(), attemptState.getAppAttemptCredentials().getSecretKey(RMStateStore.AM_CLIENT_TOKEN_MASTER_KEY_NAME)); // assert store is in expected state after everything is cleaned assertTrue(stateStoreHelper.isFinalStateValid()); store.close(); }
From source file:och.comp.db.base.BaseDb.java
protected void createTables() { HashMap<Class<?>, HashSet<Class<?>>> waiters = new HashMap<>(); //fill waiters for (Class<?> type : mappers) { if (!BaseMapperWithTables.class.isAssignableFrom(type)) continue; if (type.equals(BaseMapperWithTables.class)) continue; HashSet<Class<?>> waitFor = new HashSet<>(); CreateTablesAfter waitForAnn = type.getAnnotation(CreateTablesAfter.class); if (waitForAnn != null) { waitFor.addAll(list(waitForAnn.value())); }/* w w w. j a va 2s . co m*/ waiters.put(type, waitFor); } //do creates int mappersToCreate = 0; ArrayList<String> mappersWithErrors = new ArrayList<>(); while (waiters.size() > 0) { //create HashSet<Class<?>> created = new HashSet<>(); for (Entry<Class<?>, HashSet<Class<?>>> entry : waiters.entrySet()) { if (entry.getValue().size() == 0) { Class<?> type = entry.getKey(); created.add(type); try (SqlSession session = sessionFactory.openSession()) { Object mapper = session.getMapper(type); if (mapper instanceof BaseMapperWithTables) { SQLDialect dialectType = type.getAnnotation(SQLDialect.class); String mapperDialect = dialectType == null ? null : dialectType.value(); if (mapperDialect == null) mapperDialect = DB_DEFAULT; if (dialect.equals(mapperDialect)) { mappersToCreate++; ((BaseMapperWithTables) mapper).createTables(); } } } catch (Exception e) { if (props.getBoolVal(db_debug_LogSql)) { log.error("can't createTables: " + e); } mappersWithErrors.add(type.getName()); } } } if (created.size() == 0) throw new IllegalStateException("no mapper to create. all mappers is waitnig: " + waiters); //clean for (Class<?> type : created) { waiters.remove(type); for (Entry<Class<?>, HashSet<Class<?>>> entry : waiters.entrySet()) { entry.getValue().remove(type); } } } //check results if (!isEmpty(mappersWithErrors)) log.info("can't create tables for " + mappersWithErrors); isNewTables = mappersToCreate > 0 && isEmpty(mappersWithErrors); }
From source file:de.iteratec.iteraplan.general.PropertiesTest.java
/** * tests all .properties files in de/iteratec/iteraplan/presentation/resources for duplicate keys. * /*from ww w.j av a 2 s . c o m*/ */ @Test public void testDuplicateKeys() { HashSet<String> errorMessages = new HashSet<String>(); for (LanguageFile lf : languageFiles) { errorMessages.addAll(checkFileForDuplicateKeys(lf.getPath())); if (!errorMessages.isEmpty()) { fail(StringUtils.join(errorMessages, "\n")); } } }
From source file:com.data2semantics.yasgui.mgwtlinker.linker.PermutationMapLinker.java
private Set<String> getFontFiles() { HashSet<String> set = new HashSet<String>(); set.add("../fonts/fonts.css?" + StaticConfig.VERSION); set.addAll(getExternalFilesFromDir("fonts", "", "eot", "svg", "ttf", "woff"));//don't append version string here return set;/*ww w .j av a 2 s .c om*/ }
From source file:info.magnolia.ui.framework.task.LocalTaskDispatcherManager.java
private Set<String> getAllRecipients(final Task task) { HashSet<String> users = new HashSet<String>(); log.debug("Found actorId [{}]", task.getActorId()); if (StringUtils.isNotBlank(task.getActorId())) { users.add(task.getActorId());// w ww . j a v a2 s. c om } if (task.getActorIds() != null) { log.debug("Found actorIds {}", task.getActorIds()); users.addAll(task.getActorIds()); } log.debug("Found groups {}", task.getGroupIds()); if (task.getGroupIds() != null) { for (String group : task.getGroupIds()) { Collection<String> usersOfGroupTransitive = securitySupport.get().getUserManager() .getUsersWithGroup(group, true); users.addAll(usersOfGroupTransitive); } } return users; }
From source file:org.apache.jcs.auxiliary.lateral.LateralCacheNoWaitFacade.java
public Set getGroupKeys(String group) { HashSet allKeys = new HashSet(); for (int i = 0; i < noWaits.length; i++) { AuxiliaryCache aux = noWaits[i]; if (aux != null) { try { allKeys.addAll(aux.getGroupKeys(group)); } catch (IOException e) { // ignore }/*from w w w. j a v a2 s . c o m*/ } } return allKeys; }
From source file:org.apache.jcs.auxiliary.remote.RemoteCacheNoWaitFacade.java
/** * Gets the set of keys of objects currently in the group. * <p>/* w w w . j a va 2 s . c o m*/ * @param group * @return * @throws IOException */ public Set getGroupKeys(String group) throws IOException { HashSet allKeys = new HashSet(); for (int i = 0; i < noWaits.length; i++) { AuxiliaryCache aux = noWaits[i]; if (aux != null) { allKeys.addAll(aux.getGroupKeys(group)); } } return allKeys; }
From source file:edu.cornell.mannlib.vitro.webapp.controller.edit.ObjectPropertyStatementRetryController.java
public void doPost(HttpServletRequest request, HttpServletResponse response) { if (!isAuthorizedToDisplayPage(request, response, SimplePermission.DO_BACK_END_EDITING.ACTION)) { return;//from w w w. ja v a 2s. c o m } VitroRequest vreq = new VitroRequest(request); //create an EditProcessObject for this and put it in the session EditProcessObject epo = super.createEpo(request); epo.setBeanClass(PropertyInstanceIface.class); Class[] classarray = { PropertyInstanceIface.class }; try { epo.setInsertMethod(PropertyInstanceDao.class.getMethod("insertProp", classarray)); epo.setUpdateMethod(epo.getInsertMethod()); } catch (NoSuchMethodException nsme) { log.error("Unable to find " + PropertyInstanceDao.class.getName() + ".insertProp(" + PropertyInstanceIface.class.getName() + ")"); } try { epo.setDeleteMethod(PropertyInstanceDao.class.getMethod("deletePropertyInstance", classarray)); } catch (NoSuchMethodException nsme) { log.error("Unable to find " + PropertyInstanceDao.class.getName() + ".deletePropertyInstance(" + PropertyInstanceIface.class.getName() + ")"); } String action = "insert"; PropertyInstanceDao piDao = vreq.getUnfilteredWebappDaoFactory().getPropertyInstanceDao(); epo.setDataAccessObject(piDao); ObjectPropertyDao pDao = vreq.getUnfilteredWebappDaoFactory().getObjectPropertyDao(); IndividualDao eDao = vreq.getUnfilteredWebappDaoFactory().getIndividualDao(); VClassDao vcDao = vreq.getUnfilteredWebappDaoFactory().getVClassDao(); PropertyInstance objectForEditing = null; if (!epo.getUseRecycledBean()) { objectForEditing = new PropertyInstance(); populateBeanFromParams(objectForEditing, vreq); if (vreq.getParameter(MULTIPLEXED_PARAMETER_NAME) != null) { action = "update"; } epo.setOriginalBean(objectForEditing); } else { objectForEditing = (PropertyInstance) epo.getNewBean(); } //set up any listeners // List changeListenerList = new LinkedList(); // changeListenerList.add(new SearchReindexer()); // epo.setChangeListenerList(changeListenerList); FormObject foo = new FormObject(); ObjectProperty p = pDao.getObjectPropertyByURI(objectForEditing.getPropertyURI()); if (p != null) { foo.getValues().put("Prop", p.getDomainPublic()); } else { foo.getValues().put("Prop", "The property must be specified."); } HashMap optionMap = new HashMap(); String domainEntityName = ""; String rangeEntityName = ""; Individual domainEntity = eDao.getIndividualByURI(objectForEditing.getSubjectEntURI()); List domainOptionList = new LinkedList(); Individual subjectInd = eDao.getIndividualByURI(objectForEditing.getSubjectEntURI()); if (subjectInd != null) { Option subjOpt = new Option(subjectInd.getURI(), subjectInd.getName()); } domainOptionList.add(new Option(domainEntity.getURI(), domainEntity.getName(), true)); optionMap.put("SubjectEntURI", domainOptionList); // TODO : handle list of VClasses List<VClass> possibleClasses = vcDao.getVClassesForProperty(domainEntity.getVClassURI(), objectForEditing.getPropertyURI()); Iterator<VClass> possIt = possibleClasses.iterator(); HashSet<Individual> possIndSet = new HashSet<Individual>(); while (possIt.hasNext()) { VClass possClass = possIt.next(); List<Individual> possibleIndividuals = eDao.getIndividualsByVClass(possClass); possIndSet.addAll(possibleIndividuals); } List<Individual> indList = new LinkedList(); indList.addAll(possIndSet); sortForPickList(indList, vreq); List objectEntOptionList = new LinkedList(); Iterator<Individual> indIt = indList.iterator(); while (indIt.hasNext()) { Individual objInd = indIt.next(); Option objIndOpt = new Option(objInd.getURI(), objInd.getName()); if (objectForEditing.getObjectEntURI() != null && objectForEditing.getObjectEntURI().equals(objInd.getURI())) { objIndOpt.setSelected(true); } objectEntOptionList.add(objIndOpt); } if (objectEntOptionList.size() == 0) { objectEntOptionList .add(new Option("", "There are no individuals yet defined that could fill this role.")); } optionMap.put("ObjectEntURI", objectEntOptionList); foo.setOptionLists(optionMap); epo.setFormObject(foo); FormUtils.populateFormFromBean(objectForEditing, action, foo); RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP); request.setAttribute("bodyJsp", "/templates/edit/formBasic.jsp"); request.setAttribute("formJsp", "/templates/edit/specific/ents2ents_retry_domainSide.jsp"); request.setAttribute("scripts", "/templates/edit/formBasic.js"); request.setAttribute("title", "Object Property Instance Editing Form"); request.setAttribute("_action", action); request.setAttribute("unqualifiedClassName", "ObjectPropertyStatement"); setRequestAttributes(request, epo); try { rd.forward(request, response); } catch (Exception e) { log.error("ObjectPropertyStatementRetryController could not forward to view."); log.error(e.getMessage()); log.error(e.getStackTrace()); } }
From source file:org.jumpmind.db.model.ForeignKey.java
/** * Compares this foreign key to the given one while ignoring the case of * identifiers./* w w w .ja v a 2 s . c o m*/ * * @param otherFk * The other foreign key * @return <code>true</code> if this foreign key is equal (ignoring case) to * the given one */ @SuppressWarnings("unchecked") public boolean equalsIgnoreCase(ForeignKey otherFk) { boolean checkName = isCheckName(otherFk); if ((!checkName || name.equalsIgnoreCase(otherFk.name)) && foreignTableName.equalsIgnoreCase(otherFk.foreignTableName)) { HashSet<Reference> otherRefs = new HashSet<Reference>(); otherRefs.addAll(otherFk.references); for (Iterator<?> it = references.iterator(); it.hasNext();) { Reference curLocalRef = (Reference) it.next(); boolean found = false; for (Iterator<?> otherIt = otherRefs.iterator(); otherIt.hasNext();) { Reference curOtherRef = (Reference) otherIt.next(); if (curLocalRef.equalsIgnoreCase(curOtherRef)) { otherIt.remove(); found = true; break; } } if (!found) { return false; } } return otherRefs.isEmpty(); } else { return false; } }
From source file:org.apache.ddlutils.model.ForeignKey.java
/** * Compares this foreign key to the given one while ignoring the case of identifiers. * /*from w ww . ja va2 s .c om*/ * @param otherFk The other foreign key * @return <code>true</code> if this foreign key is equal (ignoring case) to the given one */ public boolean equalsIgnoreCase(ForeignKey otherFk) { boolean checkName = (_name != null) && (_name.length() > 0) && (otherFk._name != null) && (otherFk._name.length() > 0); if ((!checkName || _name.equalsIgnoreCase(otherFk._name)) && _foreignTableName.equalsIgnoreCase(otherFk._foreignTableName)) { HashSet otherRefs = new HashSet(); otherRefs.addAll(otherFk._references); for (Iterator it = _references.iterator(); it.hasNext();) { Reference curLocalRef = (Reference) it.next(); boolean found = false; for (Iterator otherIt = otherRefs.iterator(); otherIt.hasNext();) { Reference curOtherRef = (Reference) otherIt.next(); if (curLocalRef.equalsIgnoreCase(curOtherRef)) { otherIt.remove(); found = true; break; } } if (!found) { return false; } } return otherRefs.isEmpty(); } else { return false; } }