List of usage examples for java.util Set iterator
Iterator<E> iterator();
From source file:fr.landel.utils.commons.CollectionUtils2.java
/** * To array an iterable (take the type of the first element, otherwise use * the default 'toArray(new T[0])'). Returns {@code null} if the iterable is * empty./*from ww w .ja v a 2s .c om*/ * * @param iterable * The input iterable (required) * @param type * the type of objects (optional, if null take the type of the * first element) * @param <T> * The type of object in collection * @return The array */ @SuppressWarnings("unchecked") public static <T> T[] toArray(final Iterable<T> iterable, final Class<T> type) { if (!IterableUtils.isEmpty(iterable)) { final Iterator<T> iterator = iterable.iterator(); final List<T> list = new ArrayList<>(); final Set<Class<T>> classes = new HashSet<>(); while (iterator.hasNext()) { final T obj = iterator.next(); list.add(obj); if (obj != null) { classes.add(ClassUtils.getClass(obj)); } } final Class<?> typeClass; if (type != null) { typeClass = type; } else if (classes.size() == 1) { typeClass = classes.iterator().next(); } else { typeClass = Object.class; } return list.toArray((T[]) Array.newInstance(typeClass, list.size())); } else if (iterable != null && type != null) { return (T[]) Array.newInstance(type, 0); } return null; }
From source file:es.alrocar.jpe.writer.GeoJSONWriter.java
public String write(ArrayList<JTSFeature> features) throws JSONException, BaseException { String result = null;/*from w w w. j a v a2 s. com*/ JSONObject featureCollection = new JSONObject(); featureCollection.put("type", "featureCollection"); JSONArray featuresJSON = new JSONArray(); JSONObject featureJSON; JSONObject point; JSONObject properties; JSONArray coords; for (JTSFeature feature : features) { featureJSON = new JSONObject(); point = new JSONObject(); properties = new JSONObject(); coords = new JSONArray(); featureJSON.put("type", "Feature"); point.put("type", "Point"); coords.add(feature.getGeometry().getGeometry().getCoordinate().x); coords.add(feature.getGeometry().getGeometry().getCoordinate().y); point.put("coordinates", coords); Set keys = feature.getAttributes().keySet(); Iterator it = keys.iterator(); String key; while (it.hasNext()) { key = it.next().toString(); properties.put(key, feature.getAttribute(key).value); } featureJSON.put("geometry", point); featureJSON.put("properties", properties); featuresJSON.add(featureJSON); } featureCollection.put("features", featuresJSON); result = featureCollection.toString(); return result; }
From source file:uk.ac.ebi.emma.validator.GeneValidator.java
/** * Required for Validator implementation. * @param target target object to be validated * @param errors errors object//from w ww .j ava 2 s . c o m */ @Override public void validate(Object target, Errors errors) { Gene gene = (Gene) target; // Centimorgan, if supplied, must be an integer. if (gene.getCentimorgan() != null) { Integer centimorgan = Utils.tryParseInt(gene.getCentimorgan()); if (centimorgan == null) { errors.rejectValue("centimorgan", null, "Please enter an integer."); } } if ((gene.getName() != null) && (gene.getName().trim().length() == 0)) { errors.rejectValue("name", null, "Please provide a name."); } Utils.validateMaxFieldLengths(gene, "genes", errors); // Validate that GeneSynonym string data doesn't exceed maximum varchar lengths. if (gene.getSynonyms() != null) { Set<GeneSynonym> geneSynonyms = gene.getSynonyms(); Iterator<GeneSynonym> synGenesIterator = geneSynonyms.iterator(); int i = 0; while (synGenesIterator.hasNext()) { GeneSynonym geneSynonym = (GeneSynonym) synGenesIterator.next(); errors.pushNestedPath("synonyms[" + Integer.toString(i) + "]"); Utils.validateMaxFieldLengths(geneSynonym, "syn_genes", errors); errors.popNestedPath(); i++; } } }
From source file:models.db.ProjectDevices.java
@Override public List<String> getTagPermissions() { Set<ProjectTags> tags = this.getProjectTags(); Iterator<ProjectTags> itrTags = tags.iterator(); Set<String> stringTag = new HashSet<String>(); while (itrTags.hasNext()) { ProjectTags pt = itrTags.next(); stringTag.add(pt.getName());//from w ww . j av a 2 s .co m } return new ArrayList<String>(stringTag); }
From source file:edu.byu.wso2.apim.extensions.ContextPropertyDump.java
public boolean mediate(MessageContext synapseContext) { SynapseLog synLog = getLog(synapseContext); if (synLog.isTraceOrDebugEnabled()) { synLog.traceOrDebug("Start : ContextPropertyDump mediator"); if (synLog.isTraceTraceEnabled()) { synLog.traceTrace("Message : " + synapseContext.getEnvelope()); }/*from www . ja v a 2 s . c o m*/ } Set<String> propertyKeys = synapseContext.getPropertyKeySet(); //switch to foreach for (Iterator keys = propertyKeys.iterator(); keys.hasNext();) { String key = (String) keys.next(); Object value = synapseContext.getProperty(key); if (value != null) { synLog.traceOrDebug(key + " : " + value); } else { synLog.traceOrDebug(key + " : null"); } } if (synLog.isTraceOrDebugEnabled()) { synLog.traceOrDebug("End : ContextPropertyDump mediator"); } return true; }
From source file:edu.lafayette.metadb.web.controlledvocab.ShowVocab.java
/** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */// ww w. jav a2 s . co m protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub String vocabName = request.getParameter("vocab-name"); //MetaDbHelper.note("Vocab Name in Servlet: "+vocabName); PrintWriter out = new PrintWriter(new OutputStreamWriter(response.getOutputStream(), "UTF8"), true); response.setCharacterEncoding("utf-8"); request.setCharacterEncoding("utf-8"); JSONArray vocab = new JSONArray(); try { Set<String> vocabList = ControlledVocabDAO.getControlledVocab(vocabName); Iterator<String> itr = vocabList.iterator(); String[] term = request.getParameterValues("term"); boolean autocomplete = term != null && !(term[0].equals("")); while (itr.hasNext()) { String entry = itr.next(); if (autocomplete) { //MetaDbHelper.note("Entry: "+entry+", query: "+term[0]); if (entry.toLowerCase().startsWith(term[0].toLowerCase())) vocab.put(entry); } else vocab.put(entry); } out.print(vocab); } catch (Exception e) { MetaDbHelper.logEvent(e); } out.flush(); }
From source file:com.fileanalyzer.util.LineStatisticCalculator.java
public void genParamAndValues(final StringBuilder sql, final Map<String, Object> params) { if (params == null) return;//w w w. j a v a 2 s . c o m Set<String> keySet = params.keySet(); Iterator<String> iterator = keySet.iterator(); StringBuilder strParams = new StringBuilder("("), values = new StringBuilder(" VALUES("); for (int i = 0; iterator.hasNext(); ++i) { String key = iterator.next(); strParams.append(key); if (params.get(key) instanceof String) { values.append("'").append(params.get(key)).append("'"); } else if (params.get(key) instanceof Date) values.append("'") .append(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.ms").format((Date) params.get(key))) .append("'"); else values.append(params.get(key)); if (i < params.size() - 1) { strParams.append(","); values.append(","); } } sql.append(strParams.append(")").append(values.append(");\n"))); }
From source file:edu.umn.se.trap.rule.businessrule.GrantAuthorizationRule.java
/** * @param grants, formUser//from w w w .j a v a2s . c o m * @throws TrapException */ protected void checkGrantAuthorization(Set<FormGrant> grants, FormUser formUser) throws TrapException { Iterator<FormGrant> grantIter = grants.iterator(); String user = formUser.getUserName(); while (grantIter.hasNext()) { FormGrant grant = grantIter.next(); boolean authorizedFlag = false; String[] authorized = grant.getAuthorizedPayees(); for (int i = 0; i < authorized.length; i++) { if (StringUtils.equalsIgnoreCase(user, authorized[i])) { authorizedFlag = true; } } if (authorizedFlag != true) { throw new TrapException(TrapErrors.USER_NOT_AUTORIZED); } } }
From source file:com.puppycrawl.tools.checkstyle.checks.usage.AbstractUsageCheck.java
/** * Applies this check to a set of nodes. * @param aNodes the nodes to check./*from www . ja v a2 s . co m*/ */ public void applyTo(Set aNodes) { final Iterator it = aNodes.iterator(); while (it.hasNext()) { final DetailAST nameAST = (DetailAST) it.next(); if (getReferenceCount(nameAST) == 1) { log(nameAST.getLineNo(), nameAST.getColumnNo(), getErrorKey(), nameAST.getText()); } } }
From source file:net.greenrivers.hibernate.manytomany.CreateTest.java
@Test public void testHappy() { HibernateTemplate hibernateTemplate = (HibernateTemplate) SpringContextHolder.ctx .getBean("hibernateTemplate"); DetachedCriteria findCategory = DetachedCriteria.forClass(Category.class); findCategory.add(Restrictions.eq("name", "Category-1")); List categories = hibernateTemplate.findByCriteria(findCategory); Category cat1 = (Category) categories.get(0); assertNotNull(cat1);//from ww w .j a va 2s. c o m DetachedCriteria findLicense = DetachedCriteria.forClass(License.class); findLicense.add(Restrictions.eq("name", "License-2")); List licenses = hibernateTemplate.findByCriteria(findLicense); License lic2 = (License) licenses.get(0); assertNotNull(lic2); Certified cert1 = new Certified(); cert1.setCategory(cat1); cert1.setLicense(lic2); cert1.setIsDefault(Boolean.TRUE); hibernateTemplate.save(cert1); DetachedCriteria findCategoryT = DetachedCriteria.forClass(Category.class); findCategoryT.add(Restrictions.eq("name", "Category-1")); List getcategories = hibernateTemplate.findByCriteria(findCategoryT); Category getcat1 = (Category) getcategories.get(0); assertNotNull(getcat1); Set lins = getcat1.getLicenses(); Iterator linsIter = lins.iterator(); while (linsIter.hasNext()) { License lin = (License) linsIter.next(); System.out.println(lin); } DetachedCriteria findCertified = DetachedCriteria.forClass(Certified.class); findCertified.createAlias("category", "c"); findCertified.createAlias("license", "l"); findCertified.add(Restrictions.eq("c.name", "Category-1")); findCertified.add(Restrictions.eq("l.name", "License-2")); List getcertifies = hibernateTemplate.findByCriteria(findCertified); Certified getcert1 = (Certified) getcertifies.get(0); assertNotNull(getcert1); }