List of usage examples for java.lang Double toString
public String toString()
From source file:org.dkpro.similarity.experiments.sts2013baseline.util.Evaluator.java
private static void computePearsonCorrelation(Mode mode, Dataset dataset) throws IOException { File expScoresFile = new File( OUTPUT_DIR + "/" + mode.toString().toLowerCase() + "/" + dataset.toString() + ".csv"); String gsScoresFilePath = GOLDSTANDARD_DIR + "/" + mode.toString().toLowerCase() + "/" + "STS.gs." + dataset.toString() + ".txt"; PathMatchingResourcePatternResolver r = new PathMatchingResourcePatternResolver(); Resource res = r.getResource(gsScoresFilePath); File gsScoresFile = res.getFile(); List<Double> expScores = new ArrayList<Double>(); List<Double> gsScores = new ArrayList<Double>(); List<String> expLines = FileUtils.readLines(expScoresFile); List<String> gsLines = FileUtils.readLines(gsScoresFile); for (int i = 0; i < expLines.size(); i++) { expScores.add(Double.parseDouble(expLines.get(i))); gsScores.add(Double.parseDouble(gsLines.get(i))); }//from w ww . j ava2 s .com double[] expArray = ArrayUtils.toPrimitive(expScores.toArray(new Double[expScores.size()])); double[] gsArray = ArrayUtils.toPrimitive(gsScores.toArray(new Double[gsScores.size()])); PearsonsCorrelation pearson = new PearsonsCorrelation(); Double correl = pearson.correlation(expArray, gsArray); FileUtils.writeStringToFile( new File(OUTPUT_DIR + "/" + mode.toString().toLowerCase() + "/" + dataset.toString() + ".txt"), correl.toString()); }
From source file:com.mariogrip.octodroid.util.java
public static String toMBGB(double bytes) { //Checks if the app has contact with the server. if (!mainActivity.server_status) { return "-/-"; }/* w w w .j a va 2 s . co m*/ String returnData; Double fileSizeInKB = bytes / 1024; Double fileSizeInMB = fileSizeInKB / 1024; Double fileSizeInKBformat = roundDown5(fileSizeInKB); Double fileSizeInMBformat = roundDown5(fileSizeInMB); if (fileSizeInMB >= 1) { returnData = fileSizeInMBformat.toString() + "MB"; } else { returnData = fileSizeInKBformat.toString() + "KB"; } return returnData; }
From source file:com.github.jessemull.microflex.util.BigIntegerUtil.java
/** * Safely converts a number to a BigInteger. Loss of precision may occur. Throws * an arithmetic exception upon overflow. * @param Object object to parse/* w w w . j a v a2s . com*/ * @return parsed object * @throws ArithmeticException on overflow */ public static BigInteger toBigInteger(Object obj) { /* Switch on class and convert to BigInteger */ String type = obj.getClass().getSimpleName(); BigInteger parsed; switch (type) { case "Byte": Byte by = (Byte) obj; parsed = new BigInteger(by.toString()); break; case "Short": Short sh = (Short) obj; parsed = new BigInteger(sh.toString()); break; case "Integer": Integer in = (Integer) obj; parsed = new BigInteger(in.toString()); break; case "Long": Long lo = (Long) obj; parsed = new BigInteger(lo.toString()); break; case "Float": Float fl = (Float) obj; parsed = new BigInteger(fl.toString()); break; case "BigInteger": parsed = (BigInteger) obj; break; case "BigDecimal": parsed = ((BigDecimal) obj).toBigInteger(); break; case "Double": Double db = (Double) obj; parsed = new BigInteger(db.toString()); break; default: throw new IllegalArgumentException( "Invalid type: " + type + "\nData values " + "must extend the abstract Number class."); } return parsed; }
From source file:com.github.jessemull.microflex.util.BigIntegerUtil.java
/** * Safely converts a number to a BigInteger. Loss of precision may occur. Throws * an arithmetic exception upon overflow. * @param Number object to parse/*from w w w. ja va 2 s. c o m*/ * @return parsed object * @throws ArithmeticException on overflow */ public static BigInteger toBigInteger(Number number) { /* Switch on class and convert to BigInteger */ String type = number.getClass().getSimpleName(); BigInteger parsed; switch (type) { case "Byte": Byte by = (Byte) number; parsed = new BigInteger(by.toString()); break; case "Short": Short sh = (Short) number; parsed = new BigInteger(sh.toString()); break; case "Integer": Integer in = (Integer) number; parsed = new BigInteger(in.toString()); break; case "Long": Long lo = (Long) number; parsed = new BigInteger(lo.toString()); break; case "Float": Float fl = (Float) number; parsed = new BigInteger(fl.toString()); break; case "BigInteger": parsed = (BigInteger) number; break; case "BigDecimal": parsed = ((BigDecimal) number).toBigInteger(); break; case "Double": Double db = (Double) number; parsed = new BigInteger(db.toString()); break; default: throw new IllegalArgumentException( "Invalid type: " + type + "\nData values " + "must extend the abstract Number class."); } return parsed; }
From source file:org.dkpro.similarity.experiments.sts2013.util.Evaluator.java
@SuppressWarnings("unchecked") private static void computePearsonCorrelation(Mode mode, Dataset dataset) throws IOException { File expScoresFile = new File( OUTPUT_DIR + "/" + mode.toString().toLowerCase() + "/" + dataset.toString() + ".csv"); String gsScoresFilePath = GOLDSTANDARD_DIR + "/" + mode.toString().toLowerCase() + "/" + "STS.gs." + dataset.toString() + ".txt"; PathMatchingResourcePatternResolver r = new PathMatchingResourcePatternResolver(); Resource res = r.getResource(gsScoresFilePath); File gsScoresFile = res.getFile(); List<Double> expScores = new ArrayList<Double>(); List<Double> gsScores = new ArrayList<Double>(); List<String> expLines = FileUtils.readLines(expScoresFile); List<String> gsLines = FileUtils.readLines(gsScoresFile); for (int i = 0; i < expLines.size(); i++) { expScores.add(Double.parseDouble(expLines.get(i))); gsScores.add(Double.parseDouble(gsLines.get(i))); }//w ww. java2s . c o m double[] expArray = ArrayUtils.toPrimitive(expScores.toArray(new Double[expScores.size()])); double[] gsArray = ArrayUtils.toPrimitive(gsScores.toArray(new Double[gsScores.size()])); PearsonsCorrelation pearson = new PearsonsCorrelation(); Double correl = pearson.correlation(expArray, gsArray); FileUtils.writeStringToFile( new File(OUTPUT_DIR + "/" + mode.toString().toLowerCase() + "/" + dataset.toString() + ".txt"), correl.toString()); }
From source file:de.tudarmstadt.ukp.similarity.experiments.coling2012.util.Features2Arff.java
@SuppressWarnings("unchecked") private static String toArffString(Dataset dataset, Collection<File> csvFiles) throws IOException { // Create the Arff header StringBuilder arff = new StringBuilder(); arff.append("@relation temp-relation" + LF); arff.append(LF);//from www . j ava 2 s. c o m // Init data object Map<Integer, List<String>> data = new HashMap<Integer, List<String>>(); for (File file : csvFiles) { String feature = file.getParentFile().getName() + "/" + file.getName().substring(0, file.getName().length() - 4); // feature = feature.replaceAll(",", ""); // Add the attribute to the Arff header arff.append("@attribute " + feature + " numeric" + LF); // Read data List<String> lines = FileUtils.readLines(file); for (int doc = 1; doc <= lines.size(); doc++) { String line = lines.get(doc - 1); if (line.length() > 0) // Ignore empty lines { Double value = Double.parseDouble(line); // There's just the score on the line, nothing else. // Get doc object in data list List<String> docObj; if (data.containsKey(doc)) docObj = data.get(doc); else docObj = new ArrayList<String>(); // Put data docObj.add(value.toString()); data.put(doc, docObj); } } } // Read gold standard List<String> lines = ColingUtils.readGoldstandard(dataset); // Get a list of all classes (as they differ from dataset to dataset Set<String> allClasses = new HashSet<String>(); for (String line : lines) { allClasses.add(line); } // Add gold attribute to attribute list in header arff.append("@attribute gold { " + StringUtils.join(allClasses, ", ") + " }" + LF); // Add gold similarity score for (int doc = 1; doc <= lines.size(); doc++) { String value = lines.get(doc - 1); List<String> docObj = data.get(doc); docObj.add(value); data.put(doc, docObj); } // Finalize header arff.append(LF); arff.append("@data" + LF); // Write data for (int i = 1; i <= data.keySet().size(); i++) { String dataItem = StringUtils.join(data.get(i), ","); arff.append(dataItem + LF); } return arff.toString(); }
From source file:net.sourceforge.fenixedu.applicationTier.Servico.student.AddStudentToFinalDegreeWorkStudentGroup.java
@Atomic public static Boolean run(String groupOID, String username) throws FenixServiceException { check(RolePredicates.STUDENT_PREDICATE); FinalDegreeWorkGroup group = FenixFramework.getDomainObject(groupOID); Registration registration = findSomeRegistration(username); if (group == null || registration == null || group.getGroupStudentsSet() == null || CollectionUtils.find(group.getGroupStudentsSet(), new PREDICATE_FIND_GROUP_STUDENT_BY_STUDENT(registration)) != null) { return false; }/* ww w . j av a 2 s .c om*/ Scheduleing scheduleing = group.getExecutionDegree().getScheduling(); if (scheduleing == null || scheduleing.getMaximumNumberOfStudents() == null) { throw new MaximumNumberOfStudentsUndefinedException(); } else if (scheduleing.getMinimumCompletedCreditsFirstCycle() == null) { throw new MinimumCompletedCreditsFirstCycleUndefinedException(); } else if (scheduleing.getMinimumCompletedCreditsSecondCycle() == null) { throw new MinimumCompletedCreditsSecondCycleUndefinedException(); // } else if (scheduleing.getMinimumNumberOfCompletedCourses() == // null) { // throw new MinimumNumberOfCompletedCoursesUndefinedException(); } else if (scheduleing.getMaximumNumberOfStudents().intValue() <= group.getGroupStudentsSet().size()) { throw new MaximumNumberOfStudentsReachedException(scheduleing.getMaximumNumberOfStudents().toString()); } else { final Integer maximumCurricularYearToCountCompletedCourses = scheduleing .getMaximumCurricularYearToCountCompletedCourses(); final Integer minimumCompletedCurricularYear = scheduleing.getMinimumCompletedCurricularYear(); // final Integer minimumNumberOfCompletedCourses = // scheduleing.getMinimumNumberOfCompletedCourses(); final Integer minimumCompletedCreditsFirstCycle = scheduleing.getMinimumCompletedCreditsFirstCycle(); final Integer minimumCompletedCreditsSecondCycle = scheduleing.getMinimumCompletedCreditsSecondCycle(); final StudentCurricularPlan studentCurricularPlan = registration.getActiveStudentCurricularPlan(); final DegreeCurricularPlan degreeCurricularPlan = studentCurricularPlan.getDegreeCurricularPlan(); final Collection<CurricularCourseScope> degreesActiveCurricularCourseScopes = degreeCurricularPlan .getActiveCurricularCourseScopes(); final StringBuilder notCompletedCurricularCourses = new StringBuilder(); final Set<CurricularCourse> notCompletedCurricularCoursesForMinimumCurricularYear = new HashSet<CurricularCourse>(); final Set<CurricularCourse> completedCurricularCourses = new HashSet<CurricularCourse>(); // int numberCompletedCurricularCourses = 0; for (final CurricularCourseScope curricularCourseScope : degreesActiveCurricularCourseScopes) { final CurricularCourse curricularCourse = curricularCourseScope.getCurricularCourse(); final boolean isCurricularCourseApproved = studentCurricularPlan .isCurricularCourseApproved(curricularCourse); final CurricularSemester curricularSemester = curricularCourseScope.getCurricularSemester(); final CurricularYear curricularYear = curricularSemester.getCurricularYear(); if (minimumCompletedCurricularYear != null && curricularYear.getYear() <= minimumCompletedCurricularYear) { if (!isCurricularCourseApproved) { notCompletedCurricularCoursesForMinimumCurricularYear.add(curricularCourse); } } if (maximumCurricularYearToCountCompletedCourses == null || curricularYear.getYear() .intValue() <= maximumCurricularYearToCountCompletedCourses.intValue()) { if (isCurricularCourseApproved) { completedCurricularCourses.add(curricularCourseScope.getCurricularCourse()); // numberCompletedCurricularCourses++; } else { if (notCompletedCurricularCourses.length() > 0) { notCompletedCurricularCourses.append(", "); } notCompletedCurricularCourses.append(curricularCourseScope.getCurricularCourse().getName()); } } } if (!notCompletedCurricularCoursesForMinimumCurricularYear.isEmpty()) { final StringBuilder stringBuilder = new StringBuilder(); for (final CurricularCourse curricularCourse : notCompletedCurricularCoursesForMinimumCurricularYear) { if (stringBuilder.length() > 0) { stringBuilder.append(", "); } stringBuilder.append(curricularCourse.getName()); } final String[] args = { minimumCompletedCurricularYear.toString(), stringBuilder.toString() }; throw new NotCompletedCurricularYearException(null, args); } // if (minimumNumberOfCompletedCourses != null) { // int numberCompletedCurricularCourses = // completedCurricularCourses.size(); // if (numberCompletedCurricularCourses < // minimumNumberOfCompletedCourses) { // final int numberMissingCurricularCourses = // minimumNumberOfCompletedCourses - // numberCompletedCurricularCourses; // final String[] args = { // Integer.toString(numberMissingCurricularCourses), // notCompletedCurricularCourses.toString()}; // throw new // MinimumNumberOfCompletedCoursesNotReachedException(null, args); // } // } if (minimumCompletedCreditsFirstCycle != null) { final Double completedCredits = studentCurricularPlan.getFirstCycle().getAprovedEctsCredits(); if (minimumCompletedCreditsFirstCycle > completedCredits) { final String[] args = { completedCredits.toString(), minimumCompletedCreditsFirstCycle.toString() }; throw new MinimumCompletedCreditsFirstCycleNotReachedException(null, args); } } if (minimumCompletedCreditsSecondCycle != null) { final Double completedCredits = studentCurricularPlan.getSecondCycle().getAprovedEctsCredits(); if (minimumCompletedCreditsSecondCycle > completedCredits) { final String[] args = { completedCredits.toString(), minimumCompletedCreditsSecondCycle.toString() }; throw new MinimumCompletedCreditsSecondCycleNotReachedException(null, args); } } } GroupStudent groupStudent = new GroupStudent(); groupStudent.setRegistration(registration); groupStudent.setFinalDegreeDegreeWorkGroup(group); return true; }
From source file:airlift.util.AirliftUtil.java
/** * Converts double to byte array.// w ww .j a v a 2 s.c o m * * @param _number the _number * @return the byte[] */ public static byte[] convert(java.lang.Double _number) { return (_number == null) ? null : convert(_number.toString()); }
From source file:funcoes.funcoes.java
public static String ajustarDinheiroTabela(Double valor) { NumberFormat formato2 = NumberFormat.getCurrencyInstance(); String ValorTexto = valor.toString(); String retorno;// w w w . j a v a 2s .c om if (ValorTexto.charAt(0) == '-') { String aux = formato2.format(valor); retorno = "-" + aux.substring(4); } else { retorno = formato2.format(valor).substring(3); } return retorno; }
From source file:Data.java
/** * Creates a dataset, consisting of two series of monthly data. * * @return The dataset.// w ww . java 2s . co m * @throws ClassNotFoundException */ private static XYDataset createDataset(Statement stmt) throws ClassNotFoundException { TimeSeries s1 = new TimeSeries("Humidit"); TimeSeries s2 = new TimeSeries("Temprature"); ResultSet rs = null; try { String sqlRequest = "SELECT * FROM `t_temphum`"; rs = stmt.executeQuery(sqlRequest); Double hum; Double temp; Timestamp date; while (rs.next()) { hum = rs.getDouble("tmp_humidity"); temp = rs.getDouble("tmp_temperature"); date = rs.getTimestamp("tmp_date"); if (tempUnit == "F") { temp = celsiusToFahrenheit(temp.toString()); } if (date != null) { s1.add(new Second(date), hum); s2.add(new Second(date), temp); } else { JOptionPane.showMessageDialog(panelPrincipal, "Il manque une date dans la dase de donne", "Date null", JOptionPane.WARNING_MESSAGE); } } rs.close(); } catch (SQLException e) { String exception = e.toString(); if (e.getErrorCode() == 0) { JOptionPane.showMessageDialog(panelPrincipal, "Le serveur met trop de temps rpondre ! Veuillez rssayer plus tard ou contacter un administrateur", "Connection timed out", JOptionPane.ERROR_MESSAGE); } else { JOptionPane.showMessageDialog(panelPrincipal, "Voici l'exception : " + exception, "Titre : exception", JOptionPane.ERROR_MESSAGE); // TODO Auto-generated catch block e.printStackTrace(); } } catch (Exception e) { String exception = e.toString(); JOptionPane.showMessageDialog(panelPrincipal, "Voici l'exception : " + exception, "Titre : exception", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } // ****************************************************************** // More than 150 demo applications are included with the JFreeChart // Developer Guide...for more information, see: // // > http://www.object-refinery.com/jfreechart/guide.html // // ****************************************************************** TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(s1); dataset.addSeries(s2); return dataset; }