List of usage examples for java.lang String compareTo
public int compareTo(String anotherString)
From source file:IrqaQuery.java
public static void pipeline(String basedir, String indexpath, String set, JSONObject lookup_sent) throws Exception { System.out.println(set + " started..."); String index = basedir + "/index_all" + indexpath + "/"; String stopwords = basedir + "/stopwords.txt"; IrqaQuery lp = new IrqaQuery(); String answer_filename = String.format(basedir + "/stats/data_for_analysis/newTACL/%s_raw_list.json", set); String file = String.format(basedir + "/stats/data_for_analysis/newTACL/WikiQASent-%s.txt", set); // String lookup_8kfn = basedir+"/data/wikilookup_8k.json"; String documents2_fn = basedir + "/data/documents2.json"; JSONParser parser = new JSONParser(); JSONArray answer_list = (JSONArray) parser.parse(new FileReader(answer_filename)); // Object obj2 = parser.parse(new FileReader(lookup_8kfn)); // JSONObject lookup_8k = (JSONObject) obj2; Object obj3 = parser.parse(new FileReader(documents2_fn)); JSONArray documents2 = (JSONArray) obj3; List<String> questions = new ArrayList<>(); BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file))); String outfilename = String.format(basedir + "/stats/data_for_analysis/newTACL/newsplit%s_%s.txt", indexpath, set);/* w ww . java 2 s .co m*/ BufferedWriter outfile = new BufferedWriter(new FileWriter(outfilename)); int numline = 0; ArrayList<ArrayList<String>> sentlistAll = new ArrayList<ArrayList<String>>(); ArrayList<ArrayList<String>> alistAll = new ArrayList<ArrayList<String>>(); try { String r; String cquestion = ""; ArrayList<String> sentlist = new ArrayList<>(); ArrayList<String> alist = new ArrayList<>(); while ((r = br.readLine()) != null) { numline++; String[] line = r.split("\t"); if (cquestion.compareTo(line[0]) != 0) { if (cquestion.compareTo("") != 0) { sentlistAll.add(sentlist); alistAll.add(alist); questions.add(cquestion); } sentlist = new ArrayList<>(); alist = new ArrayList<>(); sentlist.add(line[1]); alist.add(line[2]); cquestion = line[0]; } else { sentlist.add(line[1]); alist.add(line[2]); } } sentlistAll.add(sentlist); alistAll.add(alist); questions.add(cquestion); } finally { br.close(); } System.out.println(questions.size()); for (int i = 0; i < questions.size(); i++) { String query = questions.get(i); List<Document> docs = lp.query(index, stopwords, query, 5, "BM25"); // Object o = (Object) answer_list.get(0); JSONObject rl = (JSONObject) answer_list.get(i); String gold_pid = (String) rl.get("paragraph_id"); // String gold_q =(String) rl.get("question"); for (Document d : docs) { String docid = d.get("docid"); if (gold_pid.compareTo(docid) == 0) { // get sentences from gold (alistAll, sentlistAll) for (int j = 0; j < sentlistAll.get(i).size(); j++) { if (sentlistAll.get(i).get(j).length() < 1 || sentlistAll.get(i).get(j).compareTo(" ") == 0 || sentlistAll.get(i).get(j).compareTo(" ") == 0 || sentlistAll.get(i).get(j).compareTo("''") == 0 || sentlistAll.get(i).get(j).compareTo(" ") == 0) continue; String outstring = String.format("%s\t%s\t%s\n", query, sentlistAll.get(i).get(j), alistAll.get(i).get(j)); outfile.write(outstring); } } else { // get_sentence_from_lookup(); // lookup_sent.get(docid) // JSONArray sents = (JSONArray) lookup_sent.get("Timeline_of_classical_mechanics-Abstract"); JSONArray sents = (JSONArray) lookup_sent.get(docid); if (sents == null) { System.out.println("noway, " + docid + "\n"); } else { for (int kk = 0; kk < sents.size(); kk++) { if (sents.get(kk).toString().length() < 1 || sents.get(kk).toString().compareTo(" ") == 0 || sents.get(kk).toString().compareTo(" ") == 0 || sents.get(kk).toString().compareTo("''") == 0 || sents.get(kk).toString().compareTo(" ") == 0) continue; String outstring = String.format("%s\t%s\t%s\n", query, sents.get(kk).toString(), "0"); outfile.write(outstring); // System.out.printf("%s\t%s\t%s\n", query, sents.get(kk).toString(), "0"); // System.out.println(sents.get(kk)); } } } } } outfile.close(); // System.out.println(raw_list.size()); System.out.println(numline); }
From source file:Main.java
public static void appendLog(String text) { Log.d("LOGFILE", text); SimpleDateFormat sTime = new SimpleDateFormat("dd/MMM/yyyy - hh:mm:ss"); String timeFormat = sTime.format(new Date()); File sdCard = Environment.getExternalStorageDirectory(); File dir = new File(sdCard.getAbsolutePath() + "/Cura/Logs/"); dir.mkdirs();// ww w .j ava 2s .c om File logFile = new File(dir, "Cura_Logs_DEBUG.txt"); if (!logFile.exists()) { try { logFile.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } try { BufferedWriter buf = new BufferedWriter(new FileWriter(logFile, true)); if (text.compareTo("wipe") == 0) logFile.delete(); else { buf.append("[" + timeFormat + "] - "); buf.append(text); buf.newLine(); buf.close(); } } catch (IOException e) { e.printStackTrace(); } }
From source file:fr.paris.lutece.plugins.calendar.service.XMLUtils.java
/** * Calculate the style class to render the day * @param calendar A calendar object positionned on the day to render * @return A CSS style/* ww w .j a v a2s . co m*/ */ private static String getDayClass(Calendar calendar) { StringBuilder sbClass = new StringBuilder(Constants.STYLE_CLASS_SMALLMONTH_DAY); String strDate = Utils.getDate(calendar); String strToday = Utils.getDateToday(); if (Utils.isDayOff(calendar)) { sbClass.append(Constants.STYLE_CLASS_SUFFIX_OFF); } else if (strDate.compareTo(strToday) < 0) { sbClass.append(Constants.STYLE_CLASS_SUFFIX_OLD); } else if (strDate.equals(strToday)) { sbClass.append(Constants.STYLE_CLASS_SUFFIX_TODAY); } return sbClass.toString(); }
From source file:de.mpg.escidoc.util.Util.java
public static String getParamXml(final String option, final String lastModificationDate, final String ids, final String nameValue, final String typeValue) { List<String> idList = stringToList(ids); Document doc = new Document(); Element root = new Element("param"); root.setAttribute("last-modification-date", lastModificationDate); doc.addContent(root);/*from w ww . j av a 2s .c om*/ for (int index = 0; index < idList.size(); index++) { if (option.compareTo(OPTION_ADD_SELECTOR) == 0) { Element selector = new Element("selector"); selector.setAttribute("name", nameValue); selector.setAttribute("type", typeValue); selector.setText(idList.get(index)); root.addContent(selector); } else if (option.compareTo(OPTION_REMOVE_SELECTOR) == 0) { Element id = new Element("id"); id.setText(idList.get(index)); root.addContent(id); } else if (option.compareTo(OPTION_REVOKE_GRANT) == 0) { Element revocationRemark = new Element("revocation-remark"); revocationRemark.setText("Grant: " + idList.get(index) + " revoked."); root.addContent(revocationRemark); } else if (option.compareTo(OPTION_ACTIVATE_USER_GROUP) == 0) { break; } else { System.out.println("Falsche Option an getSelectorXml uebergeben!"); } } return xmlToString(doc); }
From source file:com.google.dart.java2dart.engine.MainAnalysisServer.java
private static void sortUnitMembersByName(CompilationUnit unit) { Collections.sort(unit.getDeclarations(), new Comparator<CompilationUnitMember>() { @Override/*from w w w .j av a 2 s . c o m*/ public int compare(CompilationUnitMember o1, CompilationUnitMember o2) { String name1 = ((ClassDeclaration) o1).getName().getName(); String name2 = ((ClassDeclaration) o2).getName().getName(); return name1.compareTo(name2); } }); }
From source file:com.krawler.common.timezone.Timezone.java
private static String getDSTSpecificTz(String tzid) { Calendar calTZ = Calendar.getInstance(TimeZone.getTimeZone(tzid)); TimeZone tz = calTZ.getTimeZone(); int miliseconds = tz.getOffset(calTZ.getTimeInMillis()); String time = ""; String signNum = "+"; if (miliseconds < 0) { miliseconds = miliseconds * (-1); signNum = "-"; }/*from w w w. j av a 2s .c o m*/ int seconds = miliseconds / 1000; String min = ""; // Calculating minutes if (seconds > 60) { min = String.valueOf(seconds / 60 % 60); if ((seconds / 60 % 60) < 10) { min = "0" + String.valueOf(seconds / 60 % 60); } if (min.compareTo("0") != 0 && min.compareTo("30") != 0) { // Checking whether the minimum unit of minutes is 30 mins. if (min.compareTo("45") == 0) { min = "30"; } else { min = "00"; } } } else { min = "00"; } String hours = ""; // Calculating hours if (seconds / 60 > 60) { hours = String.valueOf(seconds / 60 / 60); if ((seconds / 60 / 60) < 10) { hours = "0" + String.valueOf(seconds / 60 / 60); } } else { hours = "00"; } time = signNum + hours + ":" + min; return time; }
From source file:com.clustercontrol.accesscontrol.factory.RoleModifier.java
/** * ??<BR>//from w ww . j a va2 s .c o m * * @param roleInfo ?? * @param modifyUserId ID * @param isNew true:??false: * @throws RoleDuplicate * @throws RoleNotFound * @throws UnEditableRole * @throws HinemosUnknown */ public static void modifyRoleInfo(RoleInfo roleInfo, String modifyUserId, boolean isNew) throws RoleDuplicate, RoleNotFound, UnEditableRole, HinemosUnknown { if (roleInfo == null || modifyUserId == null || modifyUserId.compareTo("") == 0) { return; } m_log.debug("modifyRoleInfo() start (roleId = " + roleInfo.getRoleId() + ", modifyUserId = " + modifyUserId + ", isNew = " + isNew + ")"); try { long currentTimeMillis = HinemosTime.currentTimeMillis(); JpaTransactionManager jtm = new JpaTransactionManager(); if (isNew) { // ? // ?? jtm.checkEntityExists(RoleInfo.class, roleInfo.getRoleId()); // roleInfo.setCreateUserId(modifyUserId); roleInfo.setCreateDate(currentTimeMillis); // ????? SystemPrivilegeInfo systemPrivilegeInfo = QueryUtil.getSystemPrivilegePK( new SystemPrivilegeInfoPK(FunctionConstant.REPOSITORY, SystemPrivilegeMode.READ.name())); roleInfo.setSystemPrivilegeList(new ArrayList<SystemPrivilegeInfo>()); roleInfo.getSystemPrivilegeList().add(systemPrivilegeInfo); if (systemPrivilegeInfo.getRoleList() == null) { systemPrivilegeInfo.setRoleList(new ArrayList<RoleInfo>()); } systemPrivilegeInfo.getRoleList().add(roleInfo); roleInfo.setRoleType(RoleTypeConstant.USER_ROLE); roleInfo.setModifyUserId(modifyUserId); roleInfo.setModifyDate(currentTimeMillis); jtm.getEntityManager().persist(roleInfo); } else { // // ?? RoleInfo roleInfoEntity = QueryUtil.getRolePK(roleInfo.getRoleId()); // ???? if (!roleInfoEntity.getRoleType().equals(RoleTypeConstant.USER_ROLE)) { throw new UnEditableRole(); } // roleInfoEntity.setRoleName(roleInfo.getRoleName()); roleInfoEntity.setDescription(roleInfo.getDescription()); roleInfoEntity.setModifyUserId(modifyUserId); roleInfoEntity.setModifyDate(currentTimeMillis); } m_log.info("successful in modifying a role. (roleId = " + roleInfo.getRoleId() + ")"); } catch (RoleNotFound | UnEditableRole e) { throw e; } catch (EntityExistsException e) { m_log.info("modifyRoleInfo() failure to add a role. a role'id is duplicated. (roleId = " + roleInfo.getRoleId() + ")"); throw new RoleDuplicate(e.getMessage(), e); } catch (Exception e) { m_log.warn("modifyRoleInfo() failure to modify a role. (roleId = " + roleInfo.getRoleId() + ")", e); throw new HinemosUnknown("failure to modify a role. (roleId = " + roleInfo.getRoleId() + ")", e); } }
From source file:com.sfs.whichdoctor.formatter.RotationFormatter.java
public static String getField(final RotationBean rotation, final String field, final String format, final PreferencesBean preferences) { String value = ""; if (rotation == null || field == null) { return value; }//from w w w. ja v a 2 s .c o m if (field.compareTo("Tags") == 0) { value = OutputFormatter.toTagList(rotation.getTags()); } if (field.compareTo("GUID") == 0) { if (rotation.getGUID() > 0) { value = String.valueOf(rotation.getGUID()); } } if (field.compareTo("RotationId") == 0) { if (rotation.getId() > 0) { value = String.valueOf(rotation.getId()); } } if (field.compareTo("MIN") == 0) { if (rotation.getPerson() != null) { value = String.valueOf(rotation.getPerson().getPersonIdentifier()); } } if (field.compareTo("Title") == 0) { if (rotation.getPerson() != null) { PersonBean person = rotation.getPerson(); value = person.getTitle(); } } if (field.compareTo("Preferred Name") == 0) { if (rotation.getPerson() != null) { PersonBean person = rotation.getPerson(); value = person.getPreferredName(); } } if (field.compareTo("Last Name") == 0) { if (rotation.getPerson() != null) { PersonBean person = rotation.getPerson(); value = person.getLastName(); } } if (field.compareTo("Formatted Name") == 0) { if (rotation.getPerson() != null) { PersonBean person = rotation.getPerson(); value = OutputFormatter.toFormattedName(person); } } if (field.compareTo("Person") == 0) { if (rotation.getPerson() != null) { PersonBean person = rotation.getPerson(); value = OutputFormatter.toCasualName(person); } } if (StringUtils.equals(field, "First Organisation") && StringUtils.isNotBlank(rotation.getOrganisation1Name()) && !rotation.getInterruption()) { value = rotation.getOrganisation1Name(); if (StringUtils.isNotBlank(rotation.getOrganisation1Type())) { value += " (" + rotation.getOrganisation1Type() + ")"; } } if (StringUtils.equals(field, "Second Organisation") && StringUtils.isNotBlank(rotation.getOrganisation2Name())) { value = rotation.getOrganisation2Name(); if (StringUtils.isNotBlank(rotation.getOrganisation2Type())) { value += " (" + rotation.getOrganisation2Type() + ")"; } } if (field.compareTo("Address (mail merge)") == 0) { if (rotation.getPerson() != null) { PersonBean person = rotation.getPerson(); if (person.getAddress().size() > 0) { value = OutputFormatter.toAddress(person.getFirstAddress(), preferences); } } } if (field.compareTo("Type") == 0) { value = rotation.getRotationType(); } if (field.compareTo("Rotation Type") == 0) { value = rotation.getTrainingClass(); } if (field.compareTo("Interruption Reason") == 0) { value = rotation.getTrainingType(); if (rotation.getInterruption() && StringUtils.isNotBlank(rotation.getOrganisation1Name())) { value += " - " + rotation.getOrganisation1Name(); } } if (field.compareTo("Description") == 0) { value = rotation.getDescription(); } if (field.compareTo("Starting Date") == 0) { if (rotation.getStartDate() != null) { value = Formatter.conventionalDate(rotation.getStartDate()); } } if (field.compareTo("Completion Date") == 0) { if (rotation.getEndDate() != null) { value = Formatter.conventionalDate(rotation.getEndDate()); } } if (field.compareTo("Training Year") == 0) { if (rotation.getYear() > 0) { value = String.valueOf(rotation.getYear()); } } if (field.compareTo("Training Time") == 0) { value = String.valueOf(rotation.getTrainingTime() * 100) + "%"; } if (field.compareTo("Total Months") == 0) { value = String.valueOf(rotation.getTotalMonths()); } if (field.compareTo("Rotation Approved") == 0) { if (rotation.getAssessment() != null) { int i = 0; for (AssessmentBean assessment : rotation.getAssessment()) { if (value.compareTo("") != 0) { value += " / "; } value += assessment.getApproved(); if (assessment.getApprovedCondition().compareTo("") != 0) { value += " - " + assessment.getApprovedCondition(); } if (i < (rotation.getAssessment().size() - 1)) { value += " and "; } i++; } } } if (field.compareTo("Rotation Status") == 0) { if (rotation.getAssessment() != null) { int i = 0; for (AssessmentBean assessment : rotation.getAssessment()) { if (value.compareTo("") != 0) { value += " / "; } value += assessment.getStatus(); if (assessment.getStatusReason().compareTo("") != 0) { value += " - " + assessment.getStatusReason(); } if (i < (rotation.getAssessment().size() - 1)) { value += " and "; } i++; } } } if (field.compareTo("Supervisors") == 0) { StringBuilder supervisors = new StringBuilder(); if (rotation.getSupervisors() != null) { for (SupervisorBean supervisor : rotation.getSupervisors()) { if (supervisor.getPerson() != null) { if (supervisors.length() > 0) { supervisors.append(", "); } supervisors.append(OutputFormatter.toFormattedName(supervisor.getPerson())); if (StringUtils.isNotBlank(supervisor.getRelationshipType())) { supervisors.append(" - "); supervisors.append(supervisor.getRelationshipType()); } } } } value = supervisors.toString(); } if (field.compareTo("Created By") == 0) { value = rotation.getCreatedBy(); } if (field.compareTo("Date Created") == 0 && rotation.getCreatedDate() != null) { value = Formatter.conventionalDate(rotation.getCreatedDate()); } if (field.compareTo("Modified By") == 0) { value = rotation.getModifiedBy(); } if (field.compareTo("Date Modified") == 0 && rotation.getModifiedDate() != null) { value = Formatter.conventionalDate(rotation.getModifiedDate()); } if (value == null) { value = ""; } return value; }
From source file:ips1ap101.lib.core.util.STP.java
public static boolean esObjetoEnRango(Object objeto, Object minimo, Object maximo) { boolean es = true; TipoDatoParEnumeration tipo;/*w w w .ja v a 2 s. c o m*/ if (objeto == null) { return false; } else if (objeto instanceof String) { tipo = TipoDatoParEnumeration.ALFANUMERICO; } else if (objeto instanceof BigDecimal) { tipo = TipoDatoParEnumeration.NUMERICO; } else if (objeto instanceof Timestamp) { tipo = TipoDatoParEnumeration.FECHA_HORA; } else if (objeto instanceof Integer) { tipo = TipoDatoParEnumeration.ENTERO; } else if (objeto instanceof Long) { tipo = TipoDatoParEnumeration.ENTERO_GRANDE; } else if (objeto instanceof BigInteger) { tipo = TipoDatoParEnumeration.ENTERO_GRANDE; } else { return false; } switch (tipo) { case ALFANUMERICO: String val1 = (String) objeto; String min1 = (String) minimo; String max1 = (String) maximo; if (min1 != null && val1.compareTo(min1) < 0) { es = false; } if (max1 != null && val1.compareTo(max1) > 0) { es = false; } break; case NUMERICO: BigDecimal val2 = (BigDecimal) objeto; BigDecimal min2 = (BigDecimal) minimo; BigDecimal max2 = (BigDecimal) maximo; if (min2 != null && val2.compareTo(min2) < 0) { es = false; } if (max2 != null && val2.compareTo(max2) > 0) { es = false; } break; case FECHA_HORA: Timestamp val3 = (Timestamp) objeto; Timestamp min3 = (Timestamp) minimo; Timestamp max3 = (Timestamp) maximo; if (min3 != null && val3.compareTo(min3) < 0) { es = false; } if (max3 != null && val3.compareTo(max3) > 0) { es = false; } break; case ENTERO: Integer val4 = (Integer) objeto; Integer min4 = (Integer) minimo; Integer max4 = (Integer) maximo; if (min4 != null && val4.compareTo(min4) < 0) { es = false; } if (max4 != null && val4.compareTo(max4) > 0) { es = false; } break; case ENTERO_GRANDE: Long val5 = objeto instanceof BigInteger ? ((BigInteger) objeto).longValue() : (Long) objeto; Long min5 = (Long) minimo; Long max5 = (Long) maximo; if (min5 != null && val5.compareTo(min5) < 0) { es = false; } if (max5 != null && val5.compareTo(max5) > 0) { es = false; } break; } return es; }
From source file:com.aquatest.dbinterface.tools.DatabaseUpdater.java
/** * Invoke web service to retrieve the tables to be updated * /* w ww . j a va2 s .com*/ * @return vector of table names * @throws ClientProtocolException * @throws JSONException * @throws IOException */ // method declared static for Android optimisation private static Vector<String> getTables() throws JSONException, ClientProtocolException, IOException { // java compiler optimises this away if statement based on value of // MOCK_WEB_SERVICES i.e. similar to C compiler #ifdef blocks JSONObject tableResponse; if (DebugConstants.MOCK_WEB_SERVICES) { // mock web services tableResponse = MockAquaTestWebService.retrieveTables(); } else { // real production server tableResponse = AquaTestWebService.retrieveTables(); ; } if (tableResponse == null) return new Vector<String>(); Vector<String> tables = new Vector<String>(); int count = 0; String status = ""; JSONArray a = null; status = tableResponse.getString(STATUS_KEY); if (status.compareTo(STATUS_SUCCESS) == 0) { count = tableResponse.getInt(COUNT_KEY); if (count > 0) { a = tableResponse.getJSONArray(DATA_KEY); for (int i = 0; i < a.length(); i++) { tables.add((String) a.get(i)); } } } return tables; }