List of usage examples for java.util HashSet add
public boolean add(E e)
From source file:gobblin.source.extractor.extract.QueryBasedSource.java
static Set<SourceEntity> getSourceEntitiesHelper(State state) { if (state.contains(ConfigurationKeys.SOURCE_ENTITIES)) { log.info("Using entity names in " + ConfigurationKeys.SOURCE_ENTITIES); HashSet<SourceEntity> res = new HashSet<>(); for (String sourceEntityName : state.getPropAsList(ConfigurationKeys.SOURCE_ENTITIES)) { res.add(SourceEntity.fromSourceEntityName(sourceEntityName)); }/*from w ww . j a v a 2 s. c o m*/ return res; } else if (state.contains(ConfigurationKeys.SOURCE_ENTITY) || state.contains(ConfigurationKeys.EXTRACT_TABLE_NAME_KEY)) { Optional<SourceEntity> sourceEntity = SourceEntity.fromState(state); // Guaranteed to be present log.info("Using entity name in " + sourceEntity.get()); return ImmutableSet.of(sourceEntity.get()); } throw new IllegalStateException(String.format("One of the following properties must be specified: %s, %s.", ConfigurationKeys.SOURCE_ENTITIES, ConfigurationKeys.SOURCE_ENTITY)); }
From source file:de.dfki.iui.mmds.core.emf.persistence.EmfPersistence.java
private static void collectObjectsWithoutResource(EObject eObject, HashSet<EObject> alreadyVisited, List<EObject> rootList, NonContainmentReferenceHandling refOption) { if (alreadyVisited.contains(eObject)) return;//from w w w .j ava2s.co m alreadyVisited.add(eObject); if ((eObject.eClass().getEPackage() instanceof EcorePackage)) return; if (eObject.eResource() == null) { if (eObject.eContainer() == null) { rootList.add(eObject); } else { collectObjectsWithoutResource(eObject.eContainer(), alreadyVisited, rootList, refOption); } } for (EReference eref : eObject.eClass().getEAllReferences()) { if (eref.isTransient()) { EAnnotation annotation = eref.getEAnnotation("http:///org/eclipse/emf/ecore/util/ExtendedMetaData"); if (annotation == null || !annotation.getDetails().containsKey("group")) { continue; } } final Object value = eObject.eGet(eref); if (value == null) { continue; } if (value instanceof List) { for (Object obj : (List<?>) value) { if (obj == null) { logger.error("There seems to be a unresolved reference. Please check the console output!"); } collectObjectsWithoutResource((EObject) obj, alreadyVisited, rootList, refOption); } } else { collectObjectsWithoutResource((EObject) value, alreadyVisited, rootList, refOption); } } }
From source file:com.velonuboso.made.core.common.Helper.java
/** * Modification by rhgarcia from the implementation of M. Jessup * at StackOverflow./*w w w . ja va 2s. co m*/ * http://stackoverflow.com/users/294738/m-jessup */ public static ArrayList<Class> topologicalOrder(ArrayList<Class> classes) throws Exception { Node[] allNodes = new Node[classes.size()]; HashMap<String, Node> nodes = new HashMap<String, Node>(); for (int i = 0; i < classes.size(); i++) { Class c = classes.get(i); Node n = new Node(c); allNodes[i] = n; nodes.put(c.getSimpleName(), n); } for (int i = 0; i < allNodes.length; i++) { Node n = allNodes[i]; Class c = n.getC(); Archetype a = (Archetype) c.getConstructors()[0].newInstance(); ArrayList<Class> dependencies = a.getDependencies(); for (int j = 0; j < dependencies.size(); j++) { Class dep = dependencies.get(j); Node nAux = nodes.get(dep.getSimpleName()); if (nAux != null) { nAux.addEdge(n); } } } //L <- Empty list that will contain the sorted elements ArrayList<Node> L = new ArrayList<Node>(); //S <- Set of all nodes with no incoming edges HashSet<Node> S = new HashSet<Node>(); for (Node n : allNodes) { if (n.inEdges.size() == 0) { S.add(n); } } //while S is non-empty do while (!S.isEmpty()) { //remove a node n from S Node n = S.iterator().next(); S.remove(n); //insert n into L L.add(n); //for each node m with an edge e from n to m do for (Iterator<Edge> it = n.outEdges.iterator(); it.hasNext();) { //remove edge e from the graph Edge e = it.next(); Node m = e.to; it.remove();//Remove edge from n m.inEdges.remove(e);//Remove edge from m //if m has no other incoming edges then insert m into S if (m.inEdges.isEmpty()) { S.add(m); } } } //Check to see if all edges are removed boolean cycle = false; for (Node n : allNodes) { if (!n.inEdges.isEmpty()) { cycle = true; break; } } if (cycle) { throw new Exception("Cycle present, topological sort not possible"); } System.out.println("Topological Sort: " + Arrays.toString(L.toArray())); ArrayList<Class> ret = new ArrayList<Class>(); for (Node n : L) { ret.add(n.getC()); } return ret; }
From source file:fr.inria.oak.paxquery.algebra.optimizer.rules.PushdownUtility.java
/** * <p>/*from ww w. j ava 2 s . c o m*/ * This method returns the columns that are referred to by a given predicate. * </p> * * <p> * Supported predicates: {@link SimplePredicate}, {@link ConjunctivePredicate} * </p> */ public static Set<Integer> getPredicateColumns(BasePredicate pred) { HashSet<Integer> predicateColumns = new HashSet<Integer>(); int[][] leftColumns = pred.getLeftColumns(); for (int i = 0; i < leftColumns.length; i++) { for (int j = 0; j < leftColumns[i].length; j++) { predicateColumns.add(leftColumns[i][j]); } } int[][] rightColumns = pred.getRightColumns(); if (rightColumns != null) { for (int i = 0; i < rightColumns.length; i++) { if (rightColumns[i] != null) { for (int j = 0; j < rightColumns[i].length; j++) { predicateColumns.add(rightColumns[i][j]); } } } } return predicateColumns; }
From source file:org.jboss.aerogear.unifiedpush.utils.installation.InstallationUtils.java
public static void setFromJsonPath(JsonPath jsonPath, Installation installation) { installation.setId(jsonPath.getString("id")); installation.setPlatform(jsonPath.getString("platform")); installation.setEnabled(jsonPath.getBoolean("enabled")); installation.setOperatingSystem(jsonPath.getString("operatingSystem")); installation.setOsVersion(jsonPath.getString("osVersion")); installation.setAlias(jsonPath.getString("alias")); installation.setDeviceType(jsonPath.getString("deviceType")); installation.setDeviceToken(jsonPath.getString("deviceToken")); HashSet<String> categories = new HashSet<String>(); List<String> jsonCategories = jsonPath.getList("categories"); if (jsonCategories != null) { for (String category : jsonCategories) { categories.add(category); }//w w w .j av a 2s . c o m } installation.setCategories(categories); }
From source file:org.raegdan.troca.Main.java
private static HashSet<String> parseCurrencies(String currencyArgument) { HashSet<String> result = new HashSet<>(); if (!currencyArgument.contains(",")) currencyArgument += ","; String[] currencies = currencyArgument.split("\\,"); for (String currency : currencies) result.add(currency); return result; }
From source file:edu.umd.cs.submitServer.servlets.RunMoss.java
static private void uploadSubmission(PrintWriter writer, SocketClient socketClient, String classAccount, byte[] bytes, boolean baselline, HashSet<String> extensions) { try {// w w w. j a va2 s .c o m HashSet<String> seen = new HashSet<>(); Map<String, List<String>> files = TextUtilities.scanTextFilesInZip(new ByteArrayInputStream(bytes)); for (Map.Entry<String, List<String>> e : files.entrySet()) { String name = e.getKey(); name = name.substring(name.lastIndexOf('/') + 1); int lastDot = name.lastIndexOf('.'); if (lastDot >= 0 && extensions.contains(name.substring(lastDot)) && seen.add(name)) { name = classAccount + "/" + name; writer.println(" Sending " + name); socketClient.uploadFile(name, e.getValue(), false); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.SelectListGenerator.java
private static List<Individual> removeIndividualsAlreadyInRange(List<Individual> individuals, List<ObjectPropertyStatement> stmts, String predicateUri, String objectUriBeingEdited) { log.debug(// w ww.ja v a 2 s . c o m "starting to check for duplicate range individuals in SelectListGenerator.removeIndividualsAlreadyInRange() ..."); HashSet<String> range = new HashSet<String>(); for (ObjectPropertyStatement ops : stmts) { if (ops.getPropertyURI().equals(predicateUri)) range.add(ops.getObjectURI()); } int removeCount = 0; ListIterator<Individual> it = individuals.listIterator(); while (it.hasNext()) { Individual ind = it.next(); if (range.contains(ind.getURI()) && !(ind.getURI().equals(objectUriBeingEdited))) { it.remove(); ++removeCount; } } log.debug("removed " + removeCount + " duplicate range individuals"); return individuals; }
From source file:Main.java
/** * Converts a given object to a form encoded map * @param objName Name of the object/*from ww w .j a va2s. co m*/ * @param obj The object to convert into a map * @param objectMap The object map to populate * @param processed List of objects hashCodes that are already parsed * @throws InvalidObjectException */ private static void objectToMap(String objName, Object obj, Map<String, Object> objectMap, HashSet<Integer> processed) throws InvalidObjectException { //null values need not to be processed if (obj == null) return; //wrapper types are autoboxed, so reference checking is not needed if (!isWrapperType(obj.getClass())) { //avoid infinite recursion if (processed.contains(obj.hashCode())) return; processed.add(obj.hashCode()); } //process arrays if (obj instanceof Collection<?>) { //process array if ((objName == null) || (objName.isEmpty())) throw new InvalidObjectException("Object name cannot be empty"); Collection<?> array = (Collection<?>) obj; //append all elements in the array into a string int index = 0; for (Object element : array) { //load key value pair String key = String.format("%s[%d]", objName, index++); loadKeyValuePairForEncoding(key, element, objectMap, processed); } } else if (obj instanceof Map) { //process map Map<?, ?> map = (Map<?, ?>) obj; //append all elements in the array into a string for (Map.Entry<?, ?> pair : map.entrySet()) { String attribName = pair.getKey().toString(); String key = attribName; if ((objName != null) && (!objName.isEmpty())) { key = String.format("%s[%s]", objName, attribName); } loadKeyValuePairForEncoding(key, pair.getValue(), objectMap, processed); } } else { //process objects // invoke getter methods Method[] methods = obj.getClass().getMethods(); for (Method method : methods) { //is a getter? if ((method.getParameterTypes().length != 0) || (!method.getName().startsWith("get"))) continue; //get json attribute name Annotation getterAnnotation = method.getAnnotation(JsonGetter.class); if (getterAnnotation == null) continue; //load key name String attribName = ((JsonGetter) getterAnnotation).value(); String key = attribName; if ((objName != null) && (!objName.isEmpty())) { key = String.format("%s[%s]", objName, attribName); } try { //load key value pair Object value = method.invoke(obj); loadKeyValuePairForEncoding(key, value, objectMap, processed); } catch (Exception ex) { } } // load fields Field[] fields = obj.getClass().getFields(); for (Field field : fields) { //load key name String attribName = field.getName(); String key = attribName; if ((objName != null) && (!objName.isEmpty())) { key = String.format("%s[%s]", objName, attribName); } try { //load key value pair Object value = field.get(obj); loadKeyValuePairForEncoding(key, value, objectMap, processed); } catch (Exception ex) { } } } }
From source file:gov.nih.nci.cabig.caaers.domain.DiseaseHistory.java
/** * Creates the disease history.//from ww w .ja va 2 s. com * * @param studyParticipantDiseaseHistory the study participant disease history * @return the disease history */ public static DiseaseHistory createDiseaseHistory( StudyParticipantDiseaseHistory studyParticipantDiseaseHistory) { if (studyParticipantDiseaseHistory != null) { DiseaseHistory saeReportDiseaseHistory = copyBasicProperties(studyParticipantDiseaseHistory); HashSet<String> set = new HashSet<String>(); for (StudyParticipantMetastaticDiseaseSite metastaticDiseaseSite : studyParticipantDiseaseHistory .getMetastaticDiseaseSites()) { if (StringUtils.isEmpty(metastaticDiseaseSite.getName())) continue; if (set.add(metastaticDiseaseSite.getName())) { saeReportDiseaseHistory.addMetastaticDiseaseSite( MetastaticDiseaseSite.createReportMetastaticDiseaseSite(metastaticDiseaseSite)); } } return saeReportDiseaseHistory; } return null; }