List of usage examples for java.lang String compareTo
public int compareTo(String anotherString)
From source file:eu.stratosphere.pact.test.pactPrograms.KMeansIterationITCase.java
@Override protected void postSubmit() throws Exception { Comparator<String> deltaComp = new Comparator<String>() { private final double DELTA = 0.1; @Override//from w w w. j a v a2 s.c om public int compare(String o1, String o2) { StringTokenizer st1 = new StringTokenizer(o1, "|"); StringTokenizer st2 = new StringTokenizer(o2, "|"); if (st1.countTokens() != st2.countTokens()) { return st1.countTokens() - st2.countTokens(); } // first token is ID String t1 = st1.nextToken(); String t2 = st2.nextToken(); if (!t1.equals(t2)) { return t1.compareTo(t2); } while (st1.hasMoreTokens()) { t1 = st1.nextToken(); t2 = st2.nextToken(); double d1 = Double.parseDouble(t1); double d2 = Double.parseDouble(t2); if (Math.abs(d1 - d2) > DELTA) { return d1 < d2 ? -1 : 1; } } return 0; } }; // Test results compareResultsByLinesInMemory(NEWCLUSTERCENTERS, resultPath, deltaComp); // clean up file getFilesystemProvider().delete(dataPath, true); getFilesystemProvider().delete(clusterPath, true); getFilesystemProvider().delete(resultPath, true); }
From source file:de.kp.ames.webdav.WebDAVClient.java
/** * Determines all level 1 resources of a certain webdav resource, * referred by the given uri; this is a method for a folder-like * listing// w w w . jav a 2 s .co m * * @return */ public JSONArray getResources() { /* * Sorter to sort WebDAV folder by name */ Map<String, JSONObject> collector = new TreeMap<String, JSONObject>(new Comparator<String>() { public int compare(String name1, String name2) { return name1.compareTo(name2); } }); try { DavMethod method = new PropFindMethod(uri, DavConstants.PROPFIND_ALL_PROP, DavConstants.DEPTH_1); client.executeMethod(method); MultiStatus multiStatus = method.getResponseBodyAsMultiStatus(); MultiStatusResponse[] responses = multiStatus.getResponses(); MultiStatusResponse response; /* * Determine base uri from uri */ String base_uri = null; int first_slash = uri.indexOf("/", 8); // after http:// if (uri.endsWith("/")) base_uri = uri.substring(first_slash); int status = 200; // http ok for (int i = 0; i < responses.length; i++) { response = responses[i]; String href = response.getHref(); /* * Ignore the current directory */ if (href.equals(base_uri)) continue; String name = href.substring(base_uri.length()); // remove the final / from the name for directories if (name.endsWith("/")) name = name.substring(0, name.length() - 1); // ============= properties ================================= DavPropertySet properties = response.getProperties(status); /* * creationdate */ String creationdate = null; DavProperty<?> creationDate = properties.get("creationdate"); if ((creationDate != null) && (creationDate.getValue() != null)) creationdate = creationDate.getValue().toString(); /* * lastModifiedDate */ String lastmodified = null; DavProperty<?> lastModifiedDate = properties.get("getlastmodified"); if ((lastModifiedDate != null) && (lastModifiedDate.getValue() != null)) { lastmodified = lastModifiedDate.getValue().toString(); } else { lastmodified = creationdate; } /* * contenttype */ String contenttype = "text/plain"; DavProperty<?> contentType = properties.get("getcontenttype"); if ((contentType != null) && (contentType.getValue() != null)) contenttype = contentType.getValue().toString(); /* * getcontentlength */ String contentlength = "0"; DavProperty<?> contentLength = properties.get("getcontentlength"); if ((contentLength != null) && (contentLength.getValue() != null)) contentlength = contentLength.getValue().toString(); /* * resource type */ String resourcetype = null; DavProperty<?> resourceType = properties.get("resourcetype"); if ((resourceType != null) && (resourceType.getValue() != null)) resourcetype = resourceType.getValue().toString(); // title //DavProperty title = properties.get("title"); // supportedlock //DavProperty supportedLock = properties.get("supportedlock"); // displayname //DavProperty displayName = properties.get("displayname"); /* * distinguish folder & file resource */ boolean isfolder = false; if ((resourcetype != null) && (resourcetype.indexOf("collection") != -1)) isfolder = true; /* * determine absolute url */ String resource_uri = uri + name; if (isfolder == true) resource_uri = resource_uri + "/"; // this is a tribute to plone webdav server // we ignore file-like resources with content length = 0 if ((isfolder == false) && (contentlength == "0")) continue; /* * Convert to JSON object */ JSONObject jResource = new JSONObject(); jResource.put("name", name); jResource.put("uri", resource_uri); jResource.put("creationDate", creationdate); jResource.put("lastModified", lastmodified); jResource.put("isFolder", isfolder); if (isfolder == false) { jResource.put("contentLength", contentlength); jResource.put("contentType", contenttype); } collector.put(name, jResource); } return new JSONArray(collector.values()); } catch (Exception e) { e.printStackTrace(); } finally { } return new JSONArray(); }
From source file:gemlite.core.internal.jmx.manage.RegionStat.java
@ManagedOperation @AggregateOperation//w ww. j a v a 2s .co m public List<HashMap<String, Object>> listRegionDetails() { List<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>(); CacheFactory.getAnyInstance().rootRegions(); Set<Region<?, ?>> set = CacheFactory.getAnyInstance().rootRegions(); if (set != null) { Iterator<Region<?, ?>> it = set.iterator(); while (it.hasNext()) { HashMap<String, Object> map = new HashMap<String, Object>(); list.add(map); Region<?, ?> r = it.next(); map.put(Regions.regionName.name(), r.getName()); map.put(Regions.size.name(), r.size()); boolean isP = PartitionRegionHelper.isPartitionedRegion(r); map.put(Regions.regionType.name(), isP ? "partitioned-region" : "replicated-region"); IMapperTool tool = DomainRegistry.getMapperTool(r.getName()); map.put(Regions.asyncqueue.name(), queuesMap.containsKey(r.getName()) ? queuesMap.get(r.getName()) : ""); if (tool == null) { LogUtil.getCoreLog().error("IMapperTool is null region : {}", r.getName()); continue; } map.put(Regions.keyClass.name(), tool.getKeyClass().getName()); map.put(Regions.valueClass.name(), tool.getValueClass().getName()); map.put(Regions.keyFields.name(), tool.getKeyFieldNames()); map.put(Regions.valueFields.name(), tool.getValueFieldNames()); } } //? Collections.sort(list, new Comparator<HashMap<String, Object>>() { public int compare(HashMap<String, Object> o1, HashMap<String, Object> o2) { String r1 = (String) o1.get(Regions.regionName.name()); String r2 = (String) o2.get(Regions.regionName.name()); return r1.compareTo(r2); } }); return list; }
From source file:com.krawler.esp.portalmsg.Mail.java
public static int GetMailMessages(Connection conn, String folderid, String loginid, String offset, String limit) throws ServiceException { int tCount = 0; String query = null;//from w w w .j a va 2 s. co m Object[] params = { null }; if (folderid.compareTo("0") == 0) { query = "Select count(post_id) from mailmessages inner join users on users.userid = mailmessages.poster_id where " + "folder = '0' and to_id = ?"; params[0] = loginid; } else if (folderid.compareTo("1") == 0) { query = "Select count(post_id) from mailmessages inner join users on users.userid = mailmessages.to_id where folder = '1' and " + "poster_id = ?"; params[0] = loginid; } else if (folderid.compareTo("4") == 0)// Starred Items { query = "Select count(post_id) from mailmessages where post_id IN (Select post_id from mailmessages inner join users on " + "users.userid = mailmessages.poster_id where folder = '0' and to_id = ? and flag = true union " + "Select post_id from mailmessages inner join users on users.userid = mailmessages.to_id where folder = '1' and " + "poster_id = ? and flag = true)"; params[0] = loginid; params[1] = loginid; } else { query = "Select count(post_id) from mailmessages where post_id IN (Select post_id from mailmessages inner join users on " + "users.userid = mailmessages.poster_id where folder = ? and to_id = ? union Select post_id from mailmessages inner join " + "users on users.userid = mailmessages.to_id where folder = ? and poster_id = ?)"; params[0] = folderid; params[1] = loginid; params[2] = folderid; params[3] = loginid; } DbResults rsc = DbUtil.executeQuery(conn, query, params); while (rsc.next()) { tCount = rsc.getInt(1); } return tCount; }
From source file:fr.sanofi.fcl4transmart.controllers.listeners.clinicalData.SelectClinicalRawFileListener.java
public boolean createTabFileFromSoft(File rawFile, File newFile) { Vector<String> columns = new Vector<String>(); Vector<HashMap<String, String>> lines = new Vector<HashMap<String, String>>(); try {//from w w w . ja v a2s .c o m BufferedReader br = new BufferedReader(new FileReader(rawFile)); String line; Pattern p1 = Pattern.compile(".SAMPLE = .*"); Pattern p2 = Pattern.compile("!Sample_characteristics_ch. = .*: .*"); while ((line = br.readLine()) != null) { if (line.compareTo("") != 0) { Matcher m1 = p1.matcher(line); Matcher m2 = p2.matcher(line); if (m1.matches()) { lines.add(new HashMap<String, String>()); if (!columns.contains("sample")) { columns.add("sample"); } lines.get(lines.size() - 1).put("sample", line.split(".SAMPLE = ", -1)[1]); } else if (m2.matches()) { String s = line.split("!Sample_characteristics_ch. = ", -1)[1]; String tag = s.split(": ", -1)[0]; if (!columns.contains(tag)) { columns.add(tag); } lines.get(lines.size() - 1).put(tag, s.split(": ", -1)[1]); } } } br.close(); } catch (Exception e) { selectRawFilesUI.setMessage("File error: " + e.getLocalizedMessage()); e.printStackTrace(); } if (columns.size() <= 1) { selectRawFilesUI.setMessage("Wrong soft format: no characteristics"); selectRawFilesUI.setIsLoading(false); return false; } FileWriter fw; try { fw = new FileWriter(newFile); BufferedWriter out = new BufferedWriter(fw); for (int i = 0; i < columns.size() - 1; i++) { out.write(columns.get(i) + "\t"); } out.write(columns.get(columns.size() - 1) + "\n"); for (HashMap<String, String> sample : lines) { for (int i = 0; i < columns.size() - 1; i++) { String value = sample.get(columns.get(i)); if (value == null) value = ""; out.write(value + "\t"); } String value = sample.get(columns.get(columns.size() - 1)); if (value == null) value = ""; out.write(value + "\n"); } out.close(); return true; } catch (IOException e) { // TODO Auto-generated catch block selectRawFilesUI.setMessage("File error: " + e.getLocalizedMessage()); selectRawFilesUI.setIsLoading(false); e.printStackTrace(); return false; } }
From source file:com.sfs.whichdoctor.dao.EmailDAOImpl.java
/** * If the EmailBean is primary ensure no other primary * entry exists for the ReferenceGUID./*from w ww. ja v a2 s .com*/ * * @param email the email * @param action the action * @throws WhichDoctorDaoException the which doctor dao exception */ private void updatePrimary(final EmailBean email, final String action) throws WhichDoctorDaoException { if (email.getPrimary()) { if (action.compareTo("delete") != 0) { /* Find old primary address and turn off flag */ this.getJdbcTemplateWriter().update(this.getSQL().getValue("email/updatePrimary"), new Object[] { false, email.getReferenceGUID(), email.getGUID(), true }); } } }
From source file:com.googlecode.flyway.core.migration.SchemaVersion.java
public int compareTo(SchemaVersion o) { if (o == null) { return 1; }//from w ww . jav a2s .c o m if (this == EMPTY) { return Integer.MIN_VALUE; } if (this == LATEST) { return Integer.MAX_VALUE; } if (o == EMPTY) { return Integer.MAX_VALUE; } if (o == LATEST) { return Integer.MIN_VALUE; } final String[] elements1 = getElements(); final String[] elements2 = o.getElements(); int smallestNumberOfElements = Math.min(elements1.length, elements2.length); for (int i = 0; i < smallestNumberOfElements; i++) { String element1 = elements1[i]; String element2 = elements2[i]; final int compared; if (StringUtils.isNumeric(element1) && StringUtils.isNumeric(element2)) { compared = Long.valueOf(element1).compareTo(Long.valueOf(element2)); } else { compared = element1.compareTo(element2); } if (compared != 0) { return compared; } } final int lengthDifference = elements1.length - elements2.length; if (lengthDifference > 0 && onlyTrailingZeroes(elements1, smallestNumberOfElements)) { return 0; } if (lengthDifference < 0 && onlyTrailingZeroes(elements2, smallestNumberOfElements)) { return 0; } return lengthDifference; }
From source file:com.khubla.simpleioc.classlibrary.ClassLibrary.java
@SuppressWarnings("unchecked") private boolean hasAnnotation(ClassNode classNode, Class<?> annotation) throws Exception { try {//from www . j av a 2 s .com /* * walk annotations */ final List<AnnotationNode> annotations = classNode.visibleAnnotations; if (null != annotations) { for (final AnnotationNode annotationNode : annotations) { /* * get the class name */ final String annotationClassName = annotationNode.desc.replaceAll("/", ".").substring(1, annotationNode.desc.length() - 1); /* * check */ if (annotationClassName.compareTo(annotation.getName()) == 0) { return true; } } } return false; } catch (final Exception e) { throw new Exception("Exception in hasAnnotation", e); } }
From source file:com.liferay.server.manager.internal.executor.PluginExecutor.java
protected List<File> getInstalledDirectories(final String context) throws Exception { List<File> installedDirs = new ArrayList<>(); String installedDirName = DeployManagerUtil.getInstalledDir(); File installedDir = new File(installedDirName, context); if (installedDir.exists()) { installedDirs.add(installedDir); } else {/*from ww w. ja v a 2 s. c om*/ File deployWarDir = new File(installedDirName, context + ".war"); installedDirs.add(deployWarDir); } if (ServerDetector.isTomcat()) { File tempDir = new File(SystemProperties.get(SystemProperties.TMP_DIR)); File[] tempContextDirs = tempDir.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { if (name.endsWith("-" + context)) { return true; } return false; } }); if (ArrayUtil.isNotEmpty(tempContextDirs)) { Arrays.sort(tempContextDirs, new Comparator<File>() { @Override public int compare(File file1, File file2) { String fileName1 = file1.getName(); String fileName2 = file2.getName(); return fileName1.compareTo(fileName2); } }); File tempContextDir = tempContextDirs[tempContextDirs.length - 1]; installedDirs.add(tempContextDir); } } return installedDirs; }
From source file:com.sfs.dao.FinancialTypeDAOImpl.java
/** * Load a collection of FinancialTypeBeans. * * @param type the type/*from w w w . ja v a 2 s .co m*/ * * @return the collection< financial type bean> * * @throws SFSDaoException the SFS dao exception */ @SuppressWarnings("unchecked") public final Collection<FinancialTypeBean> load(final String type) throws SFSDaoException { if (type == null) { throw new SFSDaoException("Error: type cannot be null"); } if (type.compareTo("") == 0) { throw new SFSDaoException("Error: type cannot be an empty string"); } Collection<FinancialTypeBean> listItems = new ArrayList<FinancialTypeBean>(); try { listItems = this.getJdbcTemplateReader().query(this.getSQL().getValue("financialType/load"), new Object[] { type }, new RowMapper() { public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException { return loadDetails(rs); } }); } catch (IncorrectResultSizeDataAccessException ie) { dataLogger.debug("No results found for this search: " + ie.getMessage()); } return listItems; }