List of usage examples for java.util HashSet contains
public boolean contains(Object o)
From source file:ch.ethz.epics.export.GoogleImageSitemap.java
public static String getImageSitemapEntry(XPort xport, CumulusTools ct, Log log, String globalId, Document doc, String lang) throws JDOMException, IOException { Element recordNode = getSingleNode(doc, "//epics:record"); String recName = recordNode.getAttributeValue("recordName", XPort.nsEpics); log.debug("- image sitemap building for internal id='" + recName + "'"); Document sitemap = new Document(); // urlset sitemap root Element urlset = new Element("urlset", nsSitemap); urlset.addNamespaceDeclaration(nsImageSitemap); sitemap.setRootElement(urlset);/*w w w . java 2 s.c o m*/ Element url = new Element("url", nsSitemap); urlset.addContent(url); // <loc> tag specifies the URL for an original image on your site Element c = new Element("loc", nsSitemap); String baseUrl = (String) xport.getParam("index.baseUrl"); c.setText(baseUrl + "images/" + globalId + ".jpg"); url.addContent(c); /** * The <priority> value specifies the importance of a particular image relative to * other images on the same site */ c = new Element("priority", nsSitemap); c.setText("0.5"); url.addContent(c); /** * The <lastmod> value identifies the time that the content at the URL was last modified. We recommend * you set this value to the most recent time that the image last changed. This information enables * crawlers to avoid recrawling content that has not changed. */ c = new Element("lastmod", nsSitemap); // uses e-pics record modification date Element recMod = getSingleNode(doc, "//epics:field[@epics:id='{af4b2e02-5f6a-11d2-8f20-0000c0e166dc}']"); String strDate = recMod.getChildTextNormalize("content", XPort.nsEpics); SimpleDateFormat df = ct.getDefaultDateFormat(); java.util.Date dtRecMod; try { dtRecMod = df.parse(strDate); SimpleDateFormat w3c = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); strDate = w3c.format(dtRecMod); c.setText(strDate); url.addContent(c); } catch (ParseException e1) { // cannot parse date: log warning, leave away lastmod log.warn("can't parse record modification date for " + globalId); } /** * The <changefreq> value indicates how frequently the content at a particular URL is likely to * change. We recommend you set this value to indicate how frequently the image changes. */ c = new Element("changefreq", nsSitemap); c.setText("monthly"); url.addContent(c); /** * The <expires> tag identifies the time that the content expires. The value of the <expires> tag * should be a timestamp in W3C DATETIME format. */ // e-pics: add 2 years to now c = new Element("expires", nsSitemap); SimpleDateFormat w3c = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); Calendar cNow = Calendar.getInstance(); cNow.add(Calendar.YEAR, 2); Date dt = cNow.getTime(); strDate = w3c.format(dt); c.setText(strDate); url.addContent(c); // image:image Element imageTag = new Element("image", nsImageSitemap); url.addContent(imageTag); // image:landing_page Element cLandingPage = new Element("landing_page", nsImageSitemap); imageTag.addContent(cLandingPage); /** * The <image:loc> tag identifies the URL where the user will be directed when clicking on the image * from Google search results. Please note that this value must be properly encoded. */ c = new Element("loc", nsImageSitemap); baseUrl = (String) xport.getParam("index.baseUrl"); c.setText(baseUrl + globalId + ".html"); cLandingPage.addContent(c); /** * The <image:language> tag identifies the language for each landing page defined by <image:landing_page> */ // e-pics: primarily german content c = new Element("language", nsImageSitemap); c.setText(lang); cLandingPage.addContent(c); /** * The <image:title> tag specifies the title of the image. There should be a maximum of one title * per landing page. */ Element e = getSingleNode(doc, "//epics:field[@epics:id='{af4b2e3d-5f6a-11d2-8f20-0000c0e166dc}']"); String title = e.getChildText("content", XPort.nsEpics); if (title != null && title.length() > 0) { c = new Element("title", nsImageSitemap); c.setText(title); cLandingPage.addContent(c); } /** * The <image:caption> tag's value provides context for an image. Please note that this value must be XMLencoded. * There should be a maximum of one caption per landing page. */ e = getSingleNode(doc, "//epics:field[@epics:id='{af4b2e34-5f6a-11d2-8f20-0000c0e166dc}']"); String caption = e.getChildText("content", XPort.nsEpics); if (caption != null && caption.length() > 0) { c = new Element("caption", nsImageSitemap); c.setText(caption); cLandingPage.addContent(c); } /** * The <image:category> tag's value specifies one or more groups, subjects or categories that * describe the image. Multiple categories should be included in separate category tags. * Comma-separated values within a single category tag will be considered one single category. */ //ArrayList<String> keywords = new ArrayList<String>(); HashSet<String> keywords = new HashSet<String>(); XPath xpath = XPath.newInstance("//epics:category"); xpath.addNamespace(XPort.nsEpics); List catNodes = xpath.selectNodes(doc); Iterator it = catNodes.iterator(); String locationName = ""; while (it.hasNext()) { e = (Element) it.next(); String catName = e.getTextNormalize(); log.debug("catName: " + catName); // KJ/20081203: use all keywords /* last keyword: String kw = catName.replaceAll(".* >? (.*)", "$1"); log.debug("got keyword: "+kw); if (kw != null && kw.length() > 0) { keywords.addAll(Arrays.asList(kw.split(", "))); } */ /* if (catName != null && catName.length() > 0) { keywords.addAll(Arrays.asList(catName.split("> "))); log.debug("got keywords: "+keywords); } */ // add keywords with duplicates removed if (catName != null && catName.length() > 0) { List<String> kw = Arrays.asList(catName.split(">")); for (String k : kw) { if (!keywords.contains(k) && k.trim().length() > 1) { log.debug("got keyword: " + k); keywords.add(k.trim()); } } } String nCatName = catName.replaceAll("\\s*>", ", "); if (nCatName != null && nCatName.length() > 0) { // KJ/20081203: don't add categories - use keywords instead //c = new Element("category", nsImageSitemap); //c.setText(nCatName); //cLandingPage.addContent(c); // E-Pics ETHBIB.Bildarchiv *spezial* if (catName.contains("Politische Geographie")) { log.debug("found location = " + catName); catName = catName.replaceAll(", Kanton > ", ", "); catName = catName.replaceAll(", Stadt > ", ", "); locationName = catName.replaceAll(".*?Politische Geographie\\s*>*(.*)", "$1"); log.debug("reduced location to = " + locationName); locationName = locationName.replaceAll("\\s*>", ","); log.debug("reduced location to = " + locationName); } } /* if (nCatName.contains("Sachkatalog")) { String kwlist = catName.replaceAll(".*?Sachkatalog\\s*>*(.*)", "$1"); if (kwlist != null && kwlist.length() > 0) { keywords.addAll(Arrays.asList(kwlist.split(", "))); } } */ } /** * The <image:keyword> tag contains a single keyword that describes an image. By properly tagging * images, you will help us to rank them in the Google Image Index. Please provide keywords that * are as specific and descriptive as possible. Broad keywords may or may not be used in indexing. * Keywords should be included in separate keyword tags, and comma-separated values within a single * keyword tag will be considered one single keyword. */ it = keywords.iterator(); while (it.hasNext()) { String kw = (String) it.next(); c = new Element("keyword", nsImageSitemap); c.setText(kw); cLandingPage.addContent(c); } /** * The <image:family_friendly> tag's value indicates whether the image only contains content that * is suitable for children. Acceptable values for this tag are yes and no. Please use reasonable * judgment when determining values for this tag. One way to define family-friendly is whether * the image could appear in a G-rated movie. */ c = new Element("family_friendly", nsImageSitemap); //TODO //e = (Element)xpath.selectSingleNode("//epics:field[@epics:id='{af4b2e34-5f6a-11d2-8f20-0000c0e166dc}']"); //String familyFriendly = e.getChildText("epics:content"); c.setText("yes"); imageTag.addContent(c); /** * The <image:geo_location> tag is used to specify a geographical location. This can be a string * the form of an address, city name, or latitude and longitude pair. Please note that this value * must be XML-encoded. */ c = new Element("geo_location", nsImageSitemap); if (locationName != null) { c.setText(locationName); imageTag.addContent(c); } /** * The <image:geo_location> tag is used to specify a geographical location. This can be a string * the form of an address, city name, or latitude and longitude pair. Please note that this value * must be XML-encoded. */ // E-Pics: Creative Commons Namensnennung, Non-commercial, no derivatives c = new Element("license", nsImageSitemap); c.setText("http://creativecommons.org/licenses/by-nc-nd/2.5/ch/"); imageTag.addContent(c); /** * The <image:quality> tag's value specifies the quality of the image relative to other images. * This information may be used to rank images from the same site relative to one another on * search result pages. Unlike <priority>, it is not used to prioritize images indexed by Google. */ // E-Pics: not used //c = new Element("quality", nsImageSitemap); //c.setText("1.0"); //imageTag.addContent(c); /** * The <image:publication_date> tag identifies the original publication date of the image in YYYY-MM-DD format. * The value of the <image:publication_date> tag should be a timestamp in W3C DATETIME format. */ // E-Pics: EXIF Date created -or- TODO: Date field c = new Element("publication_date", nsImageSitemap); Element pubDate = getSingleNode(doc, "//epics:field[@epics:id='{af4b2e51-5f6a-11d2-8f20-0000c0e166dc}']"); if (pubDate != null) { strDate = pubDate.getChildTextNormalize("content", XPort.nsEpics); } else { // try to get date field Element dateField = getSingleNode(doc, "//epics:field[@epics:id='{132267c2-4148-4b76-b851-88409d7d2799}']"); if (dateField != null) { strDate = dateField.getChildTextNormalize("content", XPort.nsEpics); if (strDate != null && strDate.length() > 0) { if (!strDate.contains(".") && !strDate.contains("/")) { // year only strDate = "01.01." + strDate; //+" 00:00:00 CET"; } else if (strDate.contains("/") && strDate.length() > 0) { // mm/YYYY String[] dateDetails = strDate.split("\\/"); if (dateDetails.length == 2) { strDate = "01." + dateDetails[0] + "." + dateDetails[1]; //strDate += " 00:00:00 CET"; } } else { //strDate = strDate+" 00:00:00 CET"; } log.debug("converted dateonly value = " + strDate); } } } if (strDate != null && strDate.length() > 0) { df = ct.getDefaultDateFormat(); java.util.Date dtPubDate; try { dtPubDate = df.parse(strDate); w3c = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); strDate = w3c.format(dtPubDate); c.setText(strDate); // KJ: 20090619 - Google does not like publication dates < 1970 // therefore they are removed from the sitemap //imageTag.addContent(c); } catch (ParseException e1) { // cannot parse date: log warning, leave away lastmod log.warn("can't parse publication date for " + globalId, e1); } } /** * The <image:size> tag specifies the size of the image in pixels. The images that you make * available to Google's crawlers should be the same size as the images that you display to * users on your site. */ // E-Pics: will need size of derivative image Element mediumImage = getSingleNode(doc, "//epics:field[@epics:fieldName='Image']"); String finalSize = mediumImage.getAttributeValue("size", XPort.nsEpics); if (finalSize != null) { c = new Element("size", nsImageSitemap); c.setText(finalSize); imageTag.addContent(c); } /** * The <image:watermarking> tag's value indicates whether watermarking exists on the image. The * only valid values of this tag are yes and no. If the value is yes, then you have the option * of specifying the percentage attribute: */ // E-Pics: maximum of 5% for creative commons license c = new Element("watermarking", nsImageSitemap); c.setText("yes"); c.setAttribute("percentage", "5"); imageTag.addContent(c); // write XML fragment into string StringWriter sw = new StringWriter(); Format xmlFormatDebug = Format.getPrettyFormat().setOmitDeclaration(true); xmlFormatDebug.setEncoding("UTF-8"); XMLOutputter xmlOutput = new XMLOutputter(xmlFormatDebug); Element sitemapRoot = sitemap.getRootElement(); xmlOutput.output((Element) sitemapRoot.getContent(0), sw); String part = sw.toString(); part = part.replaceAll(" xmlns=\"http://www.google.com/schemas/sitemap/0.9\"", ""); part = part.replaceAll(" xmlns\\:image=\"http://www.google.com/schemas/sitemap/0.9\"", ""); return part; }
From source file:me.datamining.cluster.STING.java
public List<AbstractSpatialGridPoint> findClusters() { findReleventNodes nodeFinder = new findReleventNodes(this.getRangeLow(), this.getRangeHi(), this.getConfidence()); tree_.searchStats(nodeFinder);/*from w w w . j ava 2 s . c o m*/ double factor = Math.sqrt(1 / (Math.PI * this.getDensity())); double distance = Math.max((double) this.getGridSizeInMeters(), factor); HashSet<AbstractSpatialGridPoint> clusterPoints = new HashSet<AbstractSpatialGridPoint>(); List<AbstractSpatialGridPoint> possiableNodes = nodeFinder.getResults(); ClusterNodeEvaluation evaluator = new ClusterNodeEvaluation(this.getRangeLow(), this.getRangeHi(), this.getConfidence()); log.debug("STING Relvent: " + nodeFinder.getResults().size()); log.debug("STING distance: " + distance); while (!possiableNodes.isEmpty()) { AbstractSpatialGridPoint pt = possiableNodes.remove(0); if (!clusterPoints.contains(pt)) { clusterPoints.add(pt); } List<AbstractSpatialGridPoint> check = null; if (distance != this.getGridSizeInMeters()) { check = tree_.find(new RangeSearch(pt.getVertex(), distance)); for (AbstractSpatialGridPoint n : check) { if (n.getData() instanceof STINGDataSample) { STINGDataSample sample = STINGDataSample.class.cast(n); if (!sample.isChecked()) { sample.setChecked(true); if (evaluator.isRelevent(sample.average(), sample.standardDeviation(), sample.getSampleNumber())) { possiableNodes.add(n); } } } } } } List<AbstractSpatialGridPoint> rtn = new ArrayList<AbstractSpatialGridPoint>(); for (AbstractSpatialGridPoint point : clusterPoints) { rtn.add(point); } return rtn; }
From source file:es.caib.seycon.ng.servei.AutoritzacioServiceImpl.java
private String[] autoritzacionsToString(Collection autoritzacioRols) { if (autoritzacioRols != null && autoritzacioRols.size() != 0) { /*// ww w. jav a 2 s . c o m * Collection autoVD = new HashSet(); // perqu no es repetixquen * for (Iterator it = autoritzacioRols.iterator(); it.hasNext();) { * AutoritzacioRol autoVO = (AutoritzacioRol) it.next(); * * // Afegim l'autoritzaci GENRICA (sense valor domini): * autoVD.add(autoVO.getAutoritzacio()); * * // Afegim els diferents VALORS DE DOMINI de l'autoritzaci * Collection vdom = autoVO.getValorDominiRolUsuari(); if (vdom != * null && vdom.size() != 0) { for (Iterator vit = vdom.iterator(); * vit.hasNext();) { ValorDomini vd = (ValorDomini) vit.next(); * autoVD.add(autoVO.getAutoritzacio() + "/" + vd.getValor()); } } } * return (String[]) autoVD.toArray(new String[0]); */ // Fem que si t domini ESTRELLETA, englobe els altres // valors de domini // La seva key ser el codi d'autoritzacio // amb HashSet de valor de domini HashMap autoVD = new HashMap(); // aqu posarem les autoritzacions finals: ArrayList autoritzacionsFiltrades = new ArrayList(); for (Iterator it = autoritzacioRols.iterator(); it.hasNext();) { AutoritzacioRol autoVO = (AutoritzacioRol) it.next(); // Key del HashMap String codiAutoritzacio = autoVO.getAutoritzacio(); // key: codi_autoritzacio, values: dominis // obtenim els dominis d'aquesta autoritzaci HashSet dominis = (HashSet) autoVD.get(codiAutoritzacio); // si s nova, li creem el set de dominis if (dominis == null) dominis = new HashSet(); // Afegim l'autoritzaci GENRICA (sense valor domini): dominis.add(autoVO.getAutoritzacio()); // Afegim els diferents VALORS DE DOMINI de l'autoritzaci Collection vdom = autoVO.getValorDominiRolUsuari(); if (vdom != null && vdom.size() != 0) { for (Iterator vit = vdom.iterator(); vit.hasNext();) { ValorDomini vd = (ValorDomini) vit.next(); dominis.add(autoVO.getAutoritzacio() + "/" //$NON-NLS-1$ + vd.getValor()); } } // Guardem els dominis actualitzats de l'autoritzaci: autoVD.put(codiAutoritzacio, dominis); } // Ara hem de netejar els dominis: si tenim ESTRELLETA // ens quedem noms en aquest domini i el genric for (Iterator it = autoVD.keySet().iterator(); it.hasNext();) { String autoActual = (String) it.next(); HashSet dominisAct = (HashSet) autoVD.get(autoActual); if (dominisAct.contains(autoActual + "/*")) {// VALOR DOMINI //$NON-NLS-1$ // ESTRELLETA autoritzacionsFiltrades.add(autoActual); // generic autoritzacionsFiltrades.add(autoActual + "/*"); // valor //$NON-NLS-1$ // ESTRELLETA } else { // Els afegim tots autoritzacionsFiltrades.addAll(dominisAct); } } // Haurem de recrrer return (String[]) autoritzacionsFiltrades.toArray(new String[0]); } else return new String[0]; }
From source file:hudson.matrix.MatrixProject.java
/** * Verifies that Axis names are valid and unique. *//* ww w. java 2 s . com*/ private void checkAxisNames(Iterable<Axis> newAxes) throws FormException { HashSet<String> axisNames = new HashSet<String>(); for (Axis a : newAxes) { FormValidation fv = a.getDescriptor().doCheckName(a.getName()); if (fv.kind != Kind.OK) { throw new FormException(Messages.MatrixProject_DuplicateAxisName(), fv, "axis.name"); } if (axisNames.contains(a.getName())) { throw new FormException(Messages.MatrixProject_DuplicateAxisName(), "axis.name"); } axisNames.add(a.getName()); } }
From source file:edu.ku.brc.specify.conversion.TableDataChecker.java
/** * @param tableName//from w w w . j a va 2s. c o m * @param skipNames * @return */ public List<Pair<String, String>> getColumnNamesWithData(final String tableName, final HashSet<String> skipNames) { List<Pair<String, String>> fieldsWithData = new Vector<Pair<String, String>>(); int numRows = BasicSQLUtils.getNumRecords(connection, tableName); if (numRows > 0) { try { Vector<Object[]> rows = BasicSQLUtils.query(connection, String.format( "SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE, COLUMN_DEFAULT FROM INFORMATION_SCHEMA.COLUMNS " + "WHERE table_name = '%s' AND table_schema = '%s'", tableName, connection.getCatalog())); for (Object[] cols : rows) { String fieldName = cols[0].toString(); if ((skipNames == null || !skipNames.contains(fieldName.toLowerCase()))) { if (cols[2].equals("YES")) { String sql = String.format("SELECT COUNT(*) FROM `%s` WHERE `%s` IS NOT NULL", tableName, fieldName); int cnt = BasicSQLUtils.getCountAsInt(connection, sql); if (cnt > 0) { sql = String.format( "SELECT DISTINCT c.caption, fst.TextForValue from usysmetacontrol c INNER JOIN usysmetaobject o on o.objectid = c.objectid " + "INNER JOIN usysmetafieldset fs on fs.fieldsetid = o.fieldsetid LEFT JOIN usysmetafieldsetsubtype fst on fst.fieldsetsubtypeid = c.fieldsetsubtypeid " + "WHERE fs.fieldsetname = '%s' and o.objectname = '%s' and (fst.TextForValue is null or (fst.TextForValue not in('TissueOrExtract', 'KaryoSlide', 'HistoSlideSeries', 'Image', 'Sound', 'SoundRecording', 'ImagePrint', 'Spectrogram', 'Container')))", tableName, fieldName); Pair<String, String> namePair = new Pair<String, String>(); Vector<Object[]> captions = BasicSQLUtils.query(connection, sql); if (captions.size() > 0) { namePair.second = (String) captions.get(0)[0]; } namePair.first = fieldName; fieldsWithData.add(namePair); } } } } } catch (Exception ex) { ex.printStackTrace(); } } return fieldsWithData; }
From source file:com.moz.fiji.schema.FormattedEntityId.java
/** {@inheritDoc} */ @Override//from w ww. j av a 2 s . c om public String toShellString() { if (mRowKeyFormat.getSalt().getSuppressKeyMaterialization()) { return String.format("hbase=hex:%s", ByteArrayFormatter.toHex(mHBaseRowKey)); } /** Set of characters which must be escaped */ HashSet<Character> escapeSet = Sets.newHashSet('"', '\\', '\''); ArrayList<String> componentStrings = Lists.newArrayList(); for (Object component : mComponentValues) { if (component == null) { componentStrings.add("null"); } else { String unescapedString = component.toString(); ArrayList<Character> escapedString = Lists.newArrayList(); for (char c : unescapedString.toCharArray()) { if (escapeSet.contains(c)) { escapedString.add('\\'); } escapedString.add(c); } if (getType(component) == ComponentType.STRING) { componentStrings.add(String.format("'%s'", StringUtils.join(escapedString, ""))); } else { componentStrings.add(component.toString()); } } } return "[" + StringUtils.join(componentStrings, ", ") + "]"; }
From source file:eionet.util.Util.java
/** * Finds all urls in a given string and replaces them with HTML anchors with target being a new window. * * @param in/*from w ww. j a va2s.c om*/ * - the text to scan in plain text. * @param newWindow * - whether to launch links in a new window. * @param cutLink * - can shorten the link text in the output HTML. * @return The modified text as HTML */ public static String processForLink(String in, boolean newWindow, int cutLink) { if (in == null || in.trim().length() == 0) { return in; } HashSet urlSchemes = new HashSet(); urlSchemes.add("http://"); urlSchemes.add("https://"); urlSchemes.add("ftp://"); urlSchemes.add("mailto://"); urlSchemes.add("ldap://"); urlSchemes.add("file://"); int beginIndex = -1; Iterator iter = urlSchemes.iterator(); while (iter.hasNext() && beginIndex < 0) { beginIndex = in.indexOf((String) iter.next()); } if (beginIndex < 0) { return in; } int endIndex = -1; String s = null; for (endIndex = in.length(); endIndex > beginIndex; endIndex--) { s = in.substring(beginIndex, endIndex); if (isURI(s)) { break; } } if (s == null) { return in; } HashSet endChars = new HashSet(); endChars.add(new Character('!')); endChars.add(new Character('\'')); endChars.add(new Character('(')); endChars.add(new Character(')')); endChars.add(new Character('.')); endChars.add(new Character(':')); endChars.add(new Character(';')); for (endIndex = endIndex - 1; endIndex > beginIndex; endIndex--) { char c = in.charAt(endIndex); if (!endChars.contains(new Character(c))) { break; } } StringBuffer buf = new StringBuffer(in.substring(0, beginIndex)); String link = in.substring(beginIndex, endIndex + 1); StringBuffer _buf = new StringBuffer("<a "); _buf.append("href=\""); _buf.append(link); _buf.append("\">"); if (cutLink < link.length()) { _buf.append(link.substring(0, cutLink)).append("..."); } else { _buf.append(link); } _buf.append("</a>"); buf.append(_buf.toString()); buf.append(in.substring(endIndex + 1)); return buf.toString(); }
From source file:com.tremolosecurity.unison.openshiftv3.OpenShiftTarget.java
private void syncGroups(User user, boolean addOnly, int approvalID, Workflow workflow, User fromServer, String token) throws Exception, IOException { HttpCon con = null;/* w ww . j a va 2 s.c o m*/ try { //first see if there are groups to add HashSet<String> fromServerGroups = new HashSet<String>(); fromServerGroups.addAll(fromServer.getGroups()); for (String groupName : user.getGroups()) { if (!fromServerGroups.contains(groupName)) { if (token == null) { token = this.getAuthToken(); } if (con == null) { con = this.createClient(); } this.addUserToGroup(token, con, user.getUserID(), groupName, approvalID, workflow); } } if (!addOnly) { //remove groups no longer present HashSet<String> fromUserGroups = new HashSet<String>(); fromUserGroups.addAll(user.getGroups()); for (String groupName : fromServer.getGroups()) { if (!fromUserGroups.contains(groupName)) { if (token == null) { token = this.getAuthToken(); } if (con == null) { con = this.createClient(); } this.removeUserFromGroup(token, con, user.getUserID(), groupName, approvalID, workflow); } } } } finally { if (con != null) { con.getBcm().shutdown(); con.getHttp().close(); } } }
From source file:dpfmanager.conformancechecker.tiff.implementation_checker.TiffImplementationChecker.java
public TiffValidationObject CreateValidationObject(TiffDocument tiffDoc) { this.tiffDoc = tiffDoc; TiffValidationObject tiffValidate = new TiffValidationObject(); usedOffsetsSizes = new Hashtable<>(); // Generic info tiffValidate.setSize(tiffDoc.getSize()); String endianess = "none"; if (tiffDoc.getEndianess() != null) endianess = tiffDoc.getEndianess().toString(); tiffValidate.setByteOrder(endianess); int numberimages = tiffDoc.getImageIfds().size(); tiffValidate.setNumberImages(numberimages); if (tiffDoc != null && tiffDoc.getIccProfile() != null) { tiffValidate.setIccProfileClass(tiffDoc.getIccProfile().getProfileClass() + ""); }//from www.j a va 2s. c o m // Header TiffHeader header = new TiffHeader(); header.setByteOrder(tiffDoc.getEndianess() != null ? tiffDoc.getEndianess().toString() : ""); header.setMagicNumber(tiffDoc.getMagicNumber() + ""); header.setOffset(tiffDoc.getFirstIFDOffset()); tiffValidate.setHeader(header); usedOffsetsSizes.put(0, 8); // IFDs IFD ifd = tiffDoc.getFirstIFD(); if (ifd != null) { usedOffsetsSizes.put(tiffDoc.getFirstIFDOffset(), 4); } List<TiffIfd> ifdsList = new ArrayList<TiffIfd>(); int n = 1; HashSet<Integer> usedOffsets = new HashSet<>(); usedOffsets.add(tiffDoc.getFirstIFDOffset()); boolean circularReference = false; while (ifd != null) { ifdsList.add(CreateIFDValidation(ifd, n++)); if (usedOffsets.contains(ifd.getNextOffset())) { circularReference = true; break; } else { usedOffsets.add(ifd.getNextOffset()); } if (ifd.getNextIFD() != null) { usedOffsetsSizes.put(ifd.getNextOffset(), 4); } ifd = ifd.getNextIFD(); } TiffIfds ifds = new TiffIfds(); ifds.setCircularReference(circularReference); ifds.setIfds(ifdsList); for (TiffIfd ifdNode : ifdsList) { ifdNode.setParent(ifds.getContext()); } tiffValidate.setIfds(ifds); return tiffValidate; }
From source file:com.polyvi.xface.extension.contact.XContactsExt.java
/** * hash???json./*from w w w. j a v a 2s. co m*/ * * @param requiredFields * ???? * @param contactMap * ?? Map * @param contactJson * ?? JSON ? */ private void hashMapToJson(HashSet<String> requiredFields, HashMap<String, Object> contactMap, JSONObject contactJson) { try { // DisplayName?Nickname?Note?Birthday for (String logicField : XContactAccessor.LOGIC_CONTACT_SINGLE_VALUE_FIELDS) { if (requiredFields.contains(logicField)) { Object fieldValue = contactMap.get(logicField); if (fieldValue != null) { contactJson.put(logicField, fieldValue); } } } // Addresses?Organization?Phone?Email?IMs?URLs?Photos for (String logicParentField : XContactAccessor.LOGIC_CONTACT_MULTIPLE_VALUE_FIELDS) { if (requiredFields.contains(logicParentField)) { String quantityField = mContactAccessor.generateQuantityFieldOf(logicParentField); int quantityValue = (Integer) contactMap.get(quantityField); if (quantityValue > 0) { JSONArray jsonArray = new JSONArray(); for (int i = 0; i < quantityValue; i++) { JSONObject childJson = new JSONObject(); List<String> subFields = mContactAccessor.getLogicContactSubFieldsOf(logicParentField); for (String subField : subFields) { String key = mContactAccessor.generateSubFieldKey(logicParentField, i, subField); childJson.put(subField, contactMap.get(key)); } jsonArray.put(childJson); } contactJson.put(logicParentField, jsonArray); } } } String logicParentField = XContactAccessor.LOGIC_FIELD_NAME; // Name if (requiredFields.contains(logicParentField)) { JSONObject fieldJSON = new JSONObject(); List<String> subFields = mContactAccessor.getLogicContactSubFieldsOf(logicParentField); for (String subField : subFields) { String key = mContactAccessor.generateSubFieldKey(logicParentField, 0, subField); fieldJSON.put(subField, contactMap.get(key)); } String key = mContactAccessor.generateSubFieldKey(logicParentField, 0, XContactAccessor.LOGIC_FIELD_NAME_FORMATTED); fieldJSON.put(XContactAccessor.LOGIC_FIELD_NAME_FORMATTED, contactMap.get(key)); contactJson.put(XContactAccessor.LOGIC_FIELD_NAME, fieldJSON); } } catch (JSONException e) { e.printStackTrace(); XLog.e(CLASS_NAME, e.getMessage(), e); } }