List of usage examples for java.util HashSet iterator
public Iterator<E> iterator()
From source file:edu.ksu.cs.a4vm.bse.NewGroup.java
@Override public void onResume() { super.onResume(); //display/* ww w . ja va 2 s .c o m*/ Util.setFields(SharedPrefUtil.getValue(getApplicationContext(), Constant.PREFS_GROUP_INFO, key), fields); ranchName.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) { if (ranchName.getText().toString().trim().length() >= 0) { ranchName.setBackground( ContextCompat.getDrawable(getApplicationContext(), R.drawable.focus_color)); validateRanch = false; } else { validateRanch = true; ranchName.setBackground( ContextCompat.getDrawable(getApplicationContext(), R.drawable.highlight)); Toast.makeText(getApplicationContext(), "Ranch name cannot be empty", Toast.LENGTH_SHORT) .show(); } } } }); rancherName.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) { if (rancherName.getText().toString().trim().length() >= 0) { validatelRancher = false; rancherName.setBackground( ContextCompat.getDrawable(getApplicationContext(), R.drawable.focus_color)); } else { validatelRancher = true; rancherName.setBackground( ContextCompat.getDrawable(getApplicationContext(), R.drawable.highlight)); Toast.makeText(getApplicationContext(), "Rancher name cannot be empty", Toast.LENGTH_SHORT) .show(); } } } }); address1.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) { if (address1.getText().toString().trim().length() >= 0) { address1.setBackground( ContextCompat.getDrawable(getApplicationContext(), R.drawable.focus_color)); validateAddr1 = false; } else { validateAddr1 = true; address1.setBackground( ContextCompat.getDrawable(getApplicationContext(), R.drawable.highlight)); Toast.makeText(getApplicationContext(), "Address1 cannot be empty", Toast.LENGTH_SHORT) .show(); } } } }); city.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) { if (city.getText().toString().trim().length() >= 0) { city.setBackground( ContextCompat.getDrawable(getApplicationContext(), R.drawable.focus_color)); validateCity = false; } else { validateCity = true; city.setBackground( ContextCompat.getDrawable(getApplicationContext(), R.drawable.highlight)); Toast.makeText(getApplicationContext(), "city cannot be empty", Toast.LENGTH_SHORT).show(); } } } }); state.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) { try { int text = Integer.valueOf(state.getText().toString()); float text1 = Float.valueOf(state.getText().toString()); state.setBackground( ContextCompat.getDrawable(getApplicationContext(), R.drawable.highlight)); validateState = true; } catch (NumberFormatException ne) { if (state.getText().toString().trim().length() == 0 || state.getText().toString().trim().length() == 2) { state.setBackground( ContextCompat.getDrawable(getApplicationContext(), R.drawable.focus_color)); validateState = false; } else { validateState = true; state.setBackground( ContextCompat.getDrawable(getApplicationContext(), R.drawable.highlight)); Toast.makeText(getApplicationContext(), "State not valid", Toast.LENGTH_SHORT).show(); } } } } } ); zip.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { try { if (zip.getText().toString().trim().length() == 5 && Integer.valueOf(zip.getText().toString().trim()) > 0) { zip.setBackground( ContextCompat.getDrawable(getApplicationContext(), R.drawable.focus_color)); validateZip = false; } else if (zip.getText().toString().trim().length() == 0) { zip.setBackground( ContextCompat.getDrawable(getApplicationContext(), R.drawable.focus_color)); validateZip = false; } else { zip.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.highlight)); validateZip = true; Toast.makeText(getApplicationContext(), "Zip must be a 5 digit number", Toast.LENGTH_SHORT) .show(); } } catch (NumberFormatException ne) { validateZip = true; zip.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.highlight)); Toast.makeText(getApplicationContext(), "Zip must be a 5 digit number", Toast.LENGTH_SHORT) .show(); } } } ); phone.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) { if (phone.getText().toString().trim().length() == 10) { String phn = phone.getText().toString().trim(); Pattern pattern = Pattern.compile("^[0-9]+$"); Matcher matcher = pattern.matcher(phn); if (matcher.find()) { phone.setBackground( ContextCompat.getDrawable(getApplicationContext(), R.drawable.focus_color)); validatePhone = false; } else { validatePhone = true; phone.setBackground( ContextCompat.getDrawable(getApplicationContext(), R.drawable.highlight)); Toast.makeText(getApplicationContext(), "invalid phone", Toast.LENGTH_SHORT).show(); } } else if (phone.getText().toString().trim().length() == 0) { phone.setBackground( ContextCompat.getDrawable(getApplicationContext(), R.drawable.focus_color)); validatePhone = false; } else { validatePhone = true; phone.setBackground( ContextCompat.getDrawable(getApplicationContext(), R.drawable.highlight)); Toast.makeText(getApplicationContext(), "invalid phone", Toast.LENGTH_SHORT).show(); } } } }); email.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (Util.isEmailValid(email.getText().toString().trim())) { email.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.focus_color)); validateEmail = false; } else { validateEmail = true; email.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.highlight)); Toast.makeText(getApplicationContext(), "Invalid Email", Toast.LENGTH_SHORT).show(); } } } ); btn.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { if (!validateRanch && !validatelRancher && !validateAddr1 && !validateCity && !validateState && !validatePhone && !validateZip && !validateEmail) { if (ranchName.getText().toString().trim().length() > 0 || rancherName.getText().toString().trim().length() > 0 /*&& email.getText().toString().trim().length()>0 && address1.getText().toString().trim().length()>0 && city.getText().toString().trim().length()>0 && state.getText().toString().trim().length()>0 && zip.getText().toString().trim().length()>0 && zip.getText().toString().trim().length()>0 && phone.getText().toString().trim().length()>0*/) { HashSet<String> data = new LinkedHashSet<String>(); data.add(ranchName.getHint().toString().trim() + "=" + ranchName.getText().toString().trim().replace(",", ";")); data.add(rancherName.getHint().toString().trim() + "=" + rancherName.getText().toString().trim().replace(",", ";")); data.add(email.getHint().toString().trim() + "=" + email.getText().toString().trim().replace(",", ";")); data.add(address1.getHint().toString().trim() + "=" + address1.getText().toString().trim().replace(",", ";")); data.add(address2.getHint().toString().trim() + "=" + address2.getText().toString().trim().replace(",", ";")); data.add(city.getHint().toString().trim() + "=" + city.getText().toString().trim().replace(",", ";")); data.add(state.getHint().toString().trim() + "=" + state.getText().toString().trim().replace(",", ";")); data.add(zip.getHint().toString().trim() + "=" + zip.getText().toString().trim().replace(",", ";")); data.add(phone.getHint().toString().trim() + "=" + phone.getText().toString().trim().replace(",", ";")); //capture timestamp Date cDate = new Date(); String fDate = new SimpleDateFormat("dd-MM-yyyy hh.mm.ss").format(cDate); data.add("TimeStamp=" + fDate); //persist ranchInfo final HashSet<String> keySet = (HashSet<String>) SharedPrefUtil .getValue(getApplicationContext(), Constant.PREFS_GROUP_INFO, Constant.KEY_GROUP); /* creating a copy of keySet because if sets retrieved from a shared pref file is modified, it could lead to unexpected behavior. */ Set<String> tmpkeySet = null; if (keySet != null && key != null) { Iterator<String> it = keySet.iterator(); tmpkeySet = new HashSet<String>(); while (it.hasNext()) { tmpkeySet.add(it.next()); } tmpkeySet.add(key); } else if (key != null) { tmpkeySet = new HashSet<String>(); tmpkeySet.add(key); } if (tmpkeySet != null && key != null) { SharedPrefUtil.saveGroup(getApplicationContext(), Constant.PREFS_GROUP_INFO, Constant.KEY_GROUP, tmpkeySet); SharedPrefUtil.saveGroup(getApplicationContext(), Constant.PREFS_GROUP_INFO, key, data); //saving morph config for group HashSet<String> grpMorphConfig = (HashSet<String>) SharedPrefUtil .getValue(getApplicationContext(), Constant.PREFS_GRP_MORPH_CONFIG, key); if (grpMorphConfig == null) { HashSet<String> currMorphConfig = (HashSet<String>) SharedPrefUtil.getValue( getApplicationContext(), Constant.PREFS_FILE_MORPH_INFO, Constant.KEY_MORPHOLOGY); SharedPrefUtil.saveGroup(getApplicationContext(), Constant.PREFS_GRP_MORPH_CONFIG, key, currMorphConfig); Toast.makeText(getApplicationContext(), "Saved configuration!", Toast.LENGTH_LONG) .show(); } Toast.makeText(getApplicationContext(), "Saved group!", Toast.LENGTH_LONG).show(); Intent goPrev = new Intent(getApplicationContext(), Collections.class); startActivity(goPrev); } else { Toast.makeText(getApplicationContext(), "Oops! Unable to save due to internal error", Toast.LENGTH_LONG).show(); } } else { Intent goPrev = new Intent(getApplicationContext(), Collections.class); startActivity(goPrev); } } else { Toast.makeText(getApplicationContext(), "Fix fields marked in red before saving!", Toast.LENGTH_SHORT).show(); } } }); }
From source file:org.deegree.ogcwebservices.wms.RemoteWMService.java
/** * performs a GetMap request against the remote service. The result contains the map decoded in the desired format * as a byte array.// ww w . j av a 2s . com * * @param request * GetMap request * @return the requested map-image * @throws OGCWebServiceException * if the url in the request is <code>null</code> */ protected Object handleGetMap(GetMap request) throws OGCWebServiceException { URL url = null; if (request.getVersion().equals("1.0.0")) { url = addresses.get(MAP_NAME); } else { url = addresses.get(GETMAP_NAME); } try { Envelope requestBBOX = request.getBoundingBox(); HashSet<CoordinateSystem> crss = getSupportedCoordinateSystems(request); CoordinateSystem requestCRS = CRSFactory.create(request.getSrs()); requestBBOX = createEnvelope(requestBBOX.getMin(), requestBBOX.getMax(), requestCRS); if (!crss.contains(requestCRS)) { Iterator<CoordinateSystem> iterator = crss.iterator(); CoordinateSystem dataCRS = iterator.hasNext() ? iterator.next() : null; if (dataCRS != null) { GeoTransformer transformer = new GeoTransformer(dataCRS); GeoTransformer transformBack = new GeoTransformer(requestCRS); Envelope dataBBOX = transformer.transform(requestBBOX, requestCRS, true); int origWidth = request.getWidth(); int origHeight = request.getHeight(); double scale = calcScale(origWidth, origHeight, requestBBOX, requestCRS, DEFAULT_PIXEL_SIZE); double newScale = calcScale(origWidth, origHeight, dataBBOX, dataCRS, DEFAULT_PIXEL_SIZE); double ratio = scale / newScale; if (ratio < 1) { ratio = newScale / scale; } LOG.logDebug("Requesting transformed bounding box " + dataBBOX + " in srs " + dataCRS.getIdentifier()); request.setBoundingBox(dataBBOX); request.setSrs(dataCRS.getIdentifier()); request.setWidth((int) (origWidth * ratio)); request.setHeight((int) (origHeight * ratio)); Object o = handleGetMap(request); if (o instanceof BufferedImage) { return transformBack.transform((BufferedImage) o, dataBBOX, requestBBOX, origWidth, origHeight, 16, 3, null); } return o; } } } catch (UnknownCRSException e) { LOG.logError(e.getLocalizedMessage(), e); } catch (CRSTransformationException e) { LOG.logError("An error occurred while transforming bounding boxes (this should not happen)", e); } String us = constructRequestURL(request.getRequestParameter(), validateHTTPGetBaseURL(url.toExternalForm())); LOG.logDebug("remote wms getmap", us); if (capabilities.getVersion().compareTo("1.0.0") <= 0) { us = StringTools.replace(us, "TRANSPARENCY", "TRANSPARENT", false); us = StringTools.replace(us, "GetMap", "map", false); us = StringTools.replace(us, "image/", "", false); } Object result = null; try { HttpClient client = new HttpClient(); enableProxyUsage(client, new URL(us)); int timeout = 25000; if (properties != null && properties.getProperty("timeout") != null) { timeout = Integer.parseInt(properties.getProperty("timeout")); } LOG.logDebug("timeout is:", timeout); client.getHttpConnectionManager().getParams().setSoTimeout(timeout); GetMethod get = new GetMethod(us); client.executeMethod(get); InputStream is = get.getResponseBodyAsStream(); Header header = get.getResponseHeader("Content-type"); String contentType = header.getValue(); String[] tmp = StringTools.toArray(contentType, ";", true); for (int i = 0; i < tmp.length; i++) { if (tmp[i].indexOf("image") > -1) { contentType = tmp[i]; break; } contentType = tmp[0]; } if (MimeTypeMapper.isImageType(contentType) && MimeTypeMapper.isKnownImageType(contentType)) { MemoryCacheSeekableStream mcss = new MemoryCacheSeekableStream(is); RenderedOp rop = JAI.create("stream", mcss); result = rop.getAsBufferedImage(); mcss.close(); } else { // extract remote (error) message if the response // contains a known mime type String res = ""; if (MimeTypeMapper.isKnownMimeType(contentType)) { res = "Remote-WMS message: " + getInputStreamContent(is); } else { res = Messages.getMessage("REMOTEWMS_GETMAP_INVALID_RESULT", contentType, us); } throw new OGCWebServiceException("RemoteWMS:handleGetMap", res); } } catch (HttpException e) { LOG.logError(e.getMessage(), e); String msg = Messages.getMessage("REMOTEWMS_GETMAP_GENERAL_ERROR", capabilities.getServiceIdentification().getTitle(), us); throw new OGCWebServiceException("RemoteWMS:handleGetMap", msg); } catch (IOException e) { LOG.logError(e.getMessage(), e); String msg = Messages.getMessage("REMOTEWMS_GETMAP_GENERAL_ERROR", capabilities.getServiceIdentification().getTitle(), us); throw new OGCWebServiceException("RemoteWMS:handleGetMap", msg); } // catch ( Exception e ) { // LOG.logError( e.getMessage(), e ); // String msg = Messages.getMessage( "REMOTEWMS_GETMAP_GENERAL_ERROR", // capabilities.getServiceIdentification().getTitle(), us ); // throw new OGCWebServiceException( "RemoteWMS:handleGetMap", msg ); // } return result; }
From source file:net.refractions.udig.catalog.internal.CatalogImpl.java
/** * Performs a search on this catalog based on the specified inputs. The pattern uses the * following conventions: use " " to surround a phase use + to represent 'AND' use - to * represent 'OR' use ! to represent 'NOT' use ( ) to designate scope The bbox provided shall be * in Lat - Long, or null if the search is not to be contained within a specified area. * /* w w w .j av a 2 s .com*/ * @see net.refractions.udig.catalog.ICatalog#search(java.lang.String, * com.vividsolutions.jts.geom.Envelope) * @param pattern * @param bbox used for an intersection test * @return */ public synchronized List<IResolve> search(String pattern, Envelope bbox, IProgressMonitor monitor2) { IProgressMonitor monitor = monitor2; if (monitor == null) monitor = new NullProgressMonitor(); if ((pattern == null || "".equals(pattern.trim())) //$NON-NLS-1$ && (bbox == null || bbox.isNull())) { return new LinkedList<IResolve>(); } AST ast = null; if (pattern != null && !"".equals(pattern.trim())) //$NON-NLS-1$ ast = ASTFactory.parse(pattern); // TODO check cuncurrency issues here List<IResolve> result = new LinkedList<IResolve>(); HashSet<IService> tmp = new HashSet<IService>(); tmp.addAll(this.services); try { monitor.beginTask(Messages.CatalogImpl_finding, tmp.size() * 10); Iterator<IService> services = tmp.iterator(); if (services != null) { while (services.hasNext()) { IService service = services.next(); if (check(service, ast)) { result.add(service); } Iterator<? extends IGeoResource> resources; SubProgressMonitor submonitor = new SubProgressMonitor(monitor, 10); try { List<? extends IGeoResource> t = service.resources(submonitor); resources = t == null ? null : t.iterator(); while (resources != null && resources.hasNext()) { IGeoResource resource = resources.next(); if (check(resource, ast, bbox)) { result.add(resource); } } } catch (IOException e) { CatalogPlugin.log(null, e); } finally { submonitor.done(); } } } return result; } finally { monitor.done(); } }
From source file:org.apache.hadoop.hive.ql.parse.CommonSubtreeDetect.java
private void removeCommonPart(HashSet<List<Object>> commonList) { HashSet<List<Object>> commonl = new HashSet<List<Object>>(); Iterator<List<Object>> listIter = commonList.iterator(); while (listIter.hasNext()) { List<Object> l = listIter.next(); Iterator<List<Object>> tmpIter = commonList.iterator(); while (tmpIter.hasNext()) { List<Object> tmpl = tmpIter.next(); if (!l.equals(tmpl) && l.containsAll(tmpl)) { commonl.add(tmpl);/*from w w w.j a v a2 s . c om*/ } } //remove list that don't include operator boolean visitedOp = false; for (int i = 0; i < l.size(); i++) { if (l.get(i) instanceof Operator<?>) { visitedOp = true; break; } } if (visitedOp == false) { listIter.remove(); continue; } } //merge common sub optree for (List<Object> list : commonl) { commonList.remove(list); } }
From source file:org.lexgrid.valuesets.impl.LexEVSValueSetDefinitionServicesImpl.java
@Override public AbsoluteCodingSchemeVersionReferenceList getCodingSchemesInValueSetDefinition(URI valueSetDefinitionURI) throws LBException { getLogger().logMethod(new Object[] { valueSetDefinitionURI }); AbsoluteCodingSchemeVersionReferenceList csList = new AbsoluteCodingSchemeVersionReferenceList(); // Get value set definition object for supplied uri. ValueSetDefinition vd = this.getValueSetDefinitionService() .getValueSetDefinitionByUri(valueSetDefinitionURI); // Get a list of all the coding schemes in the domain HashSet<String> vdURIs = getServiceHelper().getCodingSchemeURIs(vd); // For each URI, locate the version(s) available in the service itself. Iterator<String> uriIter = vdURIs.iterator(); while (uriIter.hasNext()) { String csURI = uriIter.next(); AbsoluteCodingSchemeVersionReferenceList csVersions = getServiceHelper() .getAbsoluteCodingSchemeVersionReference(csURI); if (csVersions.getAbsoluteCodingSchemeVersionReferenceCount() == 0) { AbsoluteCodingSchemeVersionReference acvr = new AbsoluteCodingSchemeVersionReference(); acvr.setCodingSchemeURN(csURI); csList.addAbsoluteCodingSchemeVersionReference(acvr); } else {/*from ww w . j a va 2 s. com*/ csList.addAbsoluteCodingSchemeVersionReference( csVersions.getAbsoluteCodingSchemeVersionReference(0)); } } return csList; }
From source file:org.lockss.devtools.plugindef.EditableDefinablePlugin.java
public void setPluginConfigDescrs(HashSet descrs) { logger.info("Setting the plugin configuration parameters"); if (logger.isDebug()) { logger.debug("Setting the plugin configuration parameters in detail"); Iterator iter = descrs.iterator(); for (int ix = 1; iter.hasNext(); ++ix) { logger.debug("Plugin configuration parameter " + ix + ": " + ((ConfigParamDescr) iter.next()).toDetailedString()); }/*from w w w. j a v a 2 s. co m*/ } List descrlist = ListUtil.fromArray(descrs.toArray()); definitionMap.putCollection(DefinablePlugin.KEY_PLUGIN_CONFIG_PROPS, descrlist); }
From source file:org.gcaldaemon.core.file.OnlineFileListener.java
private final long saveDir(byte[] iCalBytes, int fileIndex) throws Exception { // Mac OS X Leopard (one calendar = multiple iCal files) // Get original/old iCalendar files File dir = iCalFiles[fileIndex]; HashSet oldFiles = new HashSet(); oldFiles.addAll(Arrays.asList(dir.list())); // Get component array Calendar container = ICalUtilities.parseCalendar(iCalBytes); ComponentList list = container.getComponents(); Component[] array = new Component[list.size()]; list.toArray(array);/*from ww w .j ava 2s . c o m*/ // Save component String fileName; for (int i = 0; i < array.length; i++) { fileName = saveComponent(dir, array[i], fileIndex); oldFiles.remove(fileName); } // Remove deleted events Iterator removedNames = oldFiles.iterator(); File file; while (removedNames.hasNext()) { fileName = (String) removedNames.next(); if (!fileName.endsWith(".ics")) { continue; } try { file = new File(dir, fileName); file.delete(); if (log.isDebugEnabled()) { log.debug("File deleted (" + file.getCanonicalPath().replace('\\', '/') + ")."); } } catch (Exception ignored) { } } // Return the last modified file's timestamp return lastModified(dir); }
From source file:dao.SearchDaoDb.java
/** * addTags - adds the tags entered by users in search text * @param searchText - searchText //from w ww. ja v a 2 s . c o m * @throws BaseDaoException If we have a problem interpreting the data or the data is missing * or incorrect */ public void addTags(String searchText) { if (RegexStrUtil.isNull(searchText)) { throw new BaseDaoException("params are null"); } List tagList = RegexStrUtil.getWords(searchText); if (tagList == null) { throw new BaseDaoException("tags are null"); } Connection conn = null; List searchResult = null; try { conn = ds.getConnection(); searchResult = searchInTagsQuery.run(conn, searchText); } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e1) { throw new BaseDaoException("error in conn.close(), searchInTagsQuery() ", e1); } throw new BaseDaoException("error in result, searchInTagsQuery()", e); } try { if (conn != null) { conn.close(); } } catch (Exception e) { throw new BaseDaoException("error in conn.close(), searchInTagsQuery() ", e); } /** * none found, add all tags in the DB */ if (searchResult == null) { for (int i = 0; i < tagList.size(); i++) { try { //Object params[] = {(Object)(String)tagList.get(i)}; addTagQuery.run((String) tagList.get(i)); } catch (Exception e) { throw new BaseDaoException("error in" + addTagQuery.getSql(), e); } } } if (searchResult != null) { /** * get the tags that are found in the DB and increment the hits */ for (int i = 0; i < searchResult.size(); i++) { try { incrementTagHitsQuery .run((String) ((Yourkeywords) searchResult.get(i)).getValue(DbConstants.ENTRYID)); } catch (Exception e) { throw new BaseDaoException("error in incrementTagHitsQuery tag= " + ((Yourkeywords) searchResult.get(i)).getValue(DbConstants.ENTRYID), e); } } /* get the tags that don't exist in the database */ HashSet foundList = new HashSet(); for (int i = 0; i < searchResult.size(); i++) { if (searchResult.get(i) != null) { foundList.add(((Yourkeywords) searchResult.get(i)).getValue(DbConstants.TAG)); } } /** * get the tags and add the tags that are not found in the searchResult */ HashSet tagSet = new HashSet(tagList); boolean f = tagSet.removeAll(foundList); if (tagSet != null) { Iterator it1 = tagSet.iterator(); while (it1.hasNext()) { try { addTagQuery.run((String) it1.next()); } catch (Exception e) { throw new BaseDaoException("error in" + addTagQuery.getSql(), e); } } } } }
From source file:edu.psu.citeseerx.updates.IndexUpdateManager.java
/** * Builds a list of author normalizations to create more flexible * author search./*from ww w . jav a 2s . co m*/ * @param names * @return */ private static List<String> buildAuthorNorms(List<String> names) { HashSet<String> norms = new HashSet<String>(); for (String name : names) { name = name.replaceAll("[^\\p{L} ]", ""); StringTokenizer st = new StringTokenizer(name); String[] tokens = new String[st.countTokens()]; int counter = 0; while (st.hasMoreTokens()) { tokens[counter] = st.nextToken(); counter++; } norms.add(joinStringArray(tokens)); if (tokens.length > 2) { String[] n1 = new String[tokens.length]; for (int i = 0; i < tokens.length; i++) { if (i < tokens.length - 1) { n1[i] = Character.toString(tokens[i].charAt(0)); } else { n1[i] = tokens[i]; } } String[] n2 = new String[tokens.length]; for (int i = 0; i < tokens.length; i++) { if (i > 0 && i < tokens.length - 1) { n2[i] = Character.toString(tokens[i].charAt(0)); } else { n2[i] = tokens[i]; } } norms.add(joinStringArray(n1)); norms.add(joinStringArray(n2)); } if (tokens.length > 1) { String[] n3 = new String[2]; n3[0] = tokens[0]; n3[1] = tokens[tokens.length - 1]; String[] n4 = new String[2]; n4[0] = Character.toString(tokens[0].charAt(0)); n4[1] = tokens[tokens.length - 1]; norms.add(joinStringArray(n3)); norms.add(joinStringArray(n4)); } } ArrayList<String> normList = new ArrayList<String>(); for (Iterator<String> it = norms.iterator(); it.hasNext();) { normList.add(it.next()); } return normList; }
From source file:org.apache.axis.encoding.SerializationContextImpl.java
/** * The serialize method uses hrefs to reference all non-primitive * values. These values are stored and serialized by calling * outputMultiRefs after the serialize method completes. */// www .j ava 2 s . c o m public void outputMultiRefs() throws IOException { if (!doMultiRefs || (multiRefValues == null) || soapConstants == SOAPConstants.SOAP12_CONSTANTS) return; outputMultiRefsFlag = true; AttributesImpl attrs = new AttributesImpl(); attrs.addAttribute("","","","",""); String encodingURI = soapConstants.getEncodingURI(); // explicitly state that this attribute is not a root String prefix = getPrefixForURI(encodingURI); String root = prefix + ":root"; attrs.addAttribute(encodingURI, Constants.ATTR_ROOT, root, "CDATA", "0"); // Make sure we put the encodingStyle on each multiref element we // output. String encodingStyle; if (msgContext != null) { encodingStyle = msgContext.getEncodingStyle(); } else { encodingStyle = soapConstants.getEncodingURI(); } String encStyle = getPrefixForURI(soapConstants.getEnvelopeURI()) + ':' + Constants.ATTR_ENCODING_STYLE; attrs.addAttribute(soapConstants.getEnvelopeURI(), Constants.ATTR_ENCODING_STYLE, encStyle, "CDATA", encodingStyle); // Make a copy of the keySet because it could be updated // during processing HashSet keys = new HashSet(); keys.addAll(multiRefValues.keySet()); Iterator i = keys.iterator(); while (i.hasNext()) { while (i.hasNext()) { Object val = i.next(); MultiRefItem mri = (MultiRefItem) multiRefValues.get(val); attrs.setAttribute(0, "", Constants.ATTR_ID, "id", "CDATA", mri.id); forceSer = mri.value; // Now serialize the value. // The sendType parameter is defaulted for interop purposes. // Some of the remote services do not know how to // ascertain the type in these circumstances (though Axis does). serialize(multirefQName, attrs, mri.value, mri.xmlType, true, Boolean.TRUE); // mri.sendType } // Done processing the iterated values. During the serialization // of the values, we may have run into new nested values. These // were placed in the secondLevelObjects map, which we will now // process by changing the iterator to locate these values. if (secondLevelObjects != null) { i = secondLevelObjects.iterator(); secondLevelObjects = null; } } // Reset maps and flags forceSer = null; outputMultiRefsFlag = false; multiRefValues = null; multiRefIndex = -1; secondLevelObjects = null; }