List of usage examples for java.util Set iterator
Iterator<E> iterator();
From source file:com.silverpeas.util.StringUtil.java
private static String reencode(byte[] data, Set<String> encodings, String declaredEncoding) throws UnsupportedEncodingException { if (!encodings.isEmpty()) { String encoding = encodings.iterator().next(); String value = new String(data, encoding); if (!checkEncoding(value)) { encodings.remove(encoding); return reencode(data, encodings, declaredEncoding); }/*from w w w . j a v a 2 s . co m*/ return encoding; } return declaredEncoding; }
From source file:Main.java
public static void cosineSimilarityCW() { Iterator<Integer> ids = CommentWordCount.keySet().iterator(); while (ids.hasNext()) { int com_id = ids.next(); Set<String> words1; words1 = CommentWordCount.get(com_id).keySet(); Iterator<Integer> com_iter = CommentWordCount.keySet().iterator(); while (com_iter.hasNext()) { int id = com_iter.next(); if (com_id < id) { Set<String> words2; words2 = CommentWordCount.get(id).keySet(); Vector<Integer> vecA = new Vector<Integer>(); Vector<Integer> vecB = new Vector<Integer>(); Iterator<String> w1 = words1.iterator(); Iterator<String> w2 = words2.iterator(); HashSet<String> imp = new HashSet<String>(); while (w1.hasNext()) { String s = w1.next(); imp.add(s);//from w w w.j av a 2s. c o m } while (w2.hasNext()) { String s = w2.next(); imp.add(s); } for (String s : imp) { if (CommentWordCount.get(com_id).containsKey(s)) { vecA.add(CommentWordCount.get(com_id).get(s)); } else vecA.add(0); if (CommentWordCount.get(id).containsKey(s)) { vecB.add(CommentWordCount.get(id).get(s)); } else vecB.add(0); } //System.out.println("Size : A"+vecA.size()+" Size: B"+vecB.size()+"maxLen:"+maxlength); double similarity; int product = 0; double sumA = 0; double sumB = 0; for (int i = 0; i < vecA.size(); i++) { product += vecA.elementAt(i) * vecB.elementAt(i); sumA += vecA.elementAt(i) * vecA.elementAt(i); sumB += vecB.elementAt(i) * vecB.elementAt(i); } sumA = Math.sqrt(sumA); sumB = Math.sqrt(sumB); similarity = product / (sumA * sumB); similarity = Math.acos(similarity) * 180 / Math.PI; //System.out.println("Result "+com_id+" "+id+" :"+similarity); if (similarity < 75) { //System.out.println("Result "+com_id+" "+id); if (Topic.containsKey(com_id)) { int val = Topic.get(com_id); val++; Topic.put(com_id, val); } else Topic.put(com_id, 1); if (Topic.containsKey(id)) { int val = Topic.get(id); val++; Topic.put(id, val); } else Topic.put(id, 1); } } } } }
From source file:com.impetus.kundera.metadata.MetadataUtils.java
private static void getEmbeddableType(EntityMetadata m, Map<String, Field> columnNameToFieldMap, Map<String, Field> superColumnNameToFieldMap, final KunderaMetadata kunderaMetadata) { Metamodel metaModel = kunderaMetadata.getApplicationMetadata().getMetamodel(m.getPersistenceUnit()); EntityType entityType = metaModel.entity(m.getEntityClazz()); Set attributes = entityType.getAttributes(); Iterator<Attribute> iter = attributes.iterator(); while (iter.hasNext()) { Attribute attribute = iter.next(); if (((MetamodelImpl) metaModel).isEmbeddable(((AbstractAttribute) attribute).getBindableJavaType())) { superColumnNameToFieldMap.put(((AbstractAttribute) attribute).getJPAColumnName(), (Field) attribute.getJavaMember()); if (columnNameToFieldMap != null) { getAttributeOfEmbedddable(columnNameToFieldMap, metaModel, attribute); }//from w ww. ja v a2 s .c o m } else { if (columnNameToFieldMap != null) { columnNameToFieldMap.put(((AbstractAttribute) attribute).getJPAColumnName(), (Field) attribute.getJavaMember()); } } } }
From source file:com.impetus.kundera.metadata.MetadataUtils.java
public static void onJPAColumnMapping(final EntityType entityType, EntityMetadata entityMetadata) { Set<Attribute> attributes = entityType.getAttributes(); Iterator<Attribute> iter = attributes.iterator(); while (iter.hasNext()) { Attribute attribute = iter.next(); // jpa column mapping is for non id columns only. if (!entityMetadata.getIdAttribute().equals(attribute)) { entityMetadata.addJPAColumnMapping(((AbstractAttribute) attribute).getJPAColumnName(), attribute.getName()); }/*w ww . j a va2 s . c o m*/ } entityMetadata.setEntityType(entityType); }
From source file:com.delicious.deliciousfeeds4J.DeliciousUtil.java
public static UrlInfo deserializeUrlInfoFromJson(String json) throws Exception { logger.debug("Trying to deserialize JSON to UrlInfos..."); logger.trace("Deserializing JSON: " + json); //Check if empty or null if (json == null || json.isEmpty()) { logger.debug("Nothing to deserialize. JSON-string was empty!"); return null; }//ww w. j a v a 2 s. co m //Actually deserialize final Set<UrlInfo> urlInfos = ((Set<UrlInfo>) objectMapper.readValue(json, new TypeReference<Set<UrlInfo>>() { })); if (urlInfos == null || urlInfos.isEmpty()) { logger.debug("No UrlInfos found. Collection was empty."); return null; } return urlInfos.iterator().next(); }
From source file:com.granule.json.utils.XML.java
private static void convertJSONObject(Document doc, Element parent, JSONObject jObject, String tagName) { Set attributes = jObject.keySet(); Iterator attrsItr = attributes.iterator(); Element element = doc.createElement(removeProblemCharacters(tagName)); if (parent != null) { parent.appendChild(element);/*ww w .j a v a2s. c om*/ } else { doc.appendChild(element); } while (attrsItr.hasNext()) { String attr = (String) attrsItr.next(); Object obj = jObject.opt(attr); if (obj instanceof Number) { element.setAttribute(attr, obj.toString()); } else if (obj instanceof Boolean) { element.setAttribute(attr, obj.toString()); } else if (obj instanceof String) { element.setAttribute(attr, escapeEntityCharacters(obj.toString())); } else if (obj == null) { element.setAttribute(attr, ""); } else if (obj instanceof JSONObject) { convertJSONObject(doc, element, (JSONObject) obj, attr); } else if (obj instanceof JSONArray) { convertJSONArray(doc, element, (JSONArray) obj, attr); } } }
From source file:io.apicurio.hub.api.codegen.OpenApi2Thorntail.java
/** * Converts a set of strings into an array literal format. * @param values//from w w w. j a v a2 s . c o m */ private static String toStringArrayLiteral(Set<String> values) { StringBuilder builder = new StringBuilder(); if (values.size() == 1) { builder.append("\""); builder.append(values.iterator().next().replace("\"", "\\\"")); builder.append("\""); } else { builder.append("{"); boolean first = true; for (String value : values) { if (!first) { builder.append(", "); } builder.append("\""); builder.append(value.replace("\"", "\\\"")); builder.append("\""); first = false; } builder.append("}"); } return builder.toString(); }
From source file:api.resources.Laptop.java
public static Laptop newInstance(Map<String, Object> params) throws APIException { Laptop laptop = new Laptop(); Set<String> keys = params.keySet(); Iterator<String> iterator = keys.iterator(); while (iterator.hasNext()) { String key = iterator.next(); if (key.equals("title")) laptop.setId((String) params.get(key)); if (key.equals("nid")) laptop.setNid((String) params.get(key)); if (key.equals("location") && params.get(key) != null) laptop.setLocation((HashMap) params.get(key)); Object param = (Object) hashValueToParam(params.get(key)); if (param == null || param.equals("")) continue; if (key.equals("field_how_did_you_learn")) laptop.setHowDidYouLearn((String) param); if (key.equals("field_current_manager")) laptop.setCurrentManager((String) getUIDParam(param)); if (key.equals("field_model")) laptop.setModel((String) param); if (key.equals("field_cpu")) laptop.setCpu(((Integer) param).intValue()); if (key.equals("field_cpu_type")) laptop.setCpuType((String) param); if (key.equals("field_memory")) laptop.setMemory(((Integer) param).intValue()); if (key.equals("field_hard_drive integer")) laptop.setHardDrive(((Integer) param).intValue()); if (key.equals("field_current_os")) laptop.setCurrentOS((String) param); if (key.equals("field_destination")) laptop.setDestination((String) param); if (key.equals("field_501c3_recipient")) laptop.setA501c3Recip((String) param); if (key.equals("field_laptop_domain")) laptop.setLaptopDomain((String) param); if (key.equals("field_status")) laptop.setStatus((String) param); if (key.equals("field_dev_type")) laptop.setDevType((String) param); if (key.equals("field_library_notification")) laptop.setLibraryNotification((String) param); if (key.equals("field_checkedout_location")) laptop.setCheckedoutLocation((String) param); if (key.equals("field_notes")) laptop.setNotes((String) param); // field_laptop_serial_number if (key.equals("field_laptop_serial_number")) laptop.setSerialNumber((String) param); if (key.equals("field_date_received")) { try { laptop.setDateReceived(stringToDate((String) param)); } catch (Exception e) { log.error("It had a problem with the date received", e); }/* w ww .jav a2 s . c o m*/ } if (key.equals("field_date_delivered")) { try { laptop.setDateDelivered(stringToDate((String) param)); } catch (Exception e) { log.error("It had a problem with the date delivered", e); } } if (key.equals("field_available_day")) { try { laptop.setAvailableDay(stringToDate((String) param)); } catch (Exception e) { log.error("It had a problem with the available day", e); } } if (key.equals("field_date_recycled")) { try { laptop.setDateRecycled(stringToDate((String) param)); } catch (Exception e) { log.error("It had a problem with the date recycled", e); } } } return laptop; }
From source file:it.geosolutions.geoserver.jms.impl.handlers.catalog.CatalogUtils.java
public static Set<StyleInfo> localizeStyles(final Set<StyleInfo> stileSet, final Catalog catalog) { if (stileSet == null || catalog == null) throw new NullArgumentException("Arguments may never be null"); final Set<StyleInfo> localStileSet = new HashSet<StyleInfo>(); final Iterator<StyleInfo> deserStyleSetIterator = stileSet.iterator(); while (deserStyleSetIterator.hasNext()) { final StyleInfo deserStyle = deserStyleSetIterator.next(); final StyleInfo localStyle = localizeStyle(deserStyle, catalog); if (localStyle != null) { localStileSet.add(localStyle); }/*from www. jav a 2 s . com*/ } return localStileSet; }
From source file:fedora.server.security.servletfilters.CacheElement.java
private static final void auditNamedValues(String m, Map namedValues) { if (LOG.isDebugEnabled()) { assert namedValues != null; for (Iterator outer = namedValues.keySet().iterator(); outer.hasNext();) { Object name = outer.next(); assert name instanceof String : "not a string, name==" + name; StringBuffer sb = new StringBuffer(m + name + "=="); Object temp = namedValues.get(name); assert temp instanceof String || temp instanceof Set : "neither string nor set, temp==" + temp; if (temp instanceof String) { sb.append(temp.toString()); } else if (temp instanceof Set) { Set values = (Set) temp; sb.append("(" + values.size() + ") {"); String punct = ""; for (Iterator it = values.iterator(); it.hasNext();) { temp = it.next();/*w w w .j a v a2 s . c om*/ if (!(temp instanceof String)) { LOG.error(m + "set member not string, ==" + temp); } else { String value = (String) temp; sb.append(punct + value); punct = ","; } } sb.append("}"); } LOG.debug(sb.toString()); } } }