List of usage examples for java.lang Float compareTo
public int compareTo(Float anotherFloat)
From source file:eu.itesla_project.iidm.ddb.ddb_ear.test.DDBManagerTest.java
@Test public void test_09() throws Exception { log.info("TEST_09"); SimulatorInst eurostagSim = dbmanager.findSimulator(Simulator.EUROSTAG, "5.1.1"); assertNotNull(eurostagSim);/*from w w w . j ava 2 s . co m*/ ModelTemplateContainer mtc1 = new ModelTemplateContainer("MTC_0002", "MTC_0002 comment"); ModelTemplate mt1 = new ModelTemplate(eurostagSim, ""); DefaultParameters dp = new DefaultParameters(1); dp.addParameter(new ParameterFloat("INTMAX", 1.1000f)); dp.addParameter(new ParameterFloat("INTMAX2", 2.2000f)); mt1.getDefaultParameters().add(dp); mtc1.getModelTemplates().add(mt1); mtc1 = dbmanager.save(mtc1); ParametersContainer pc1 = new ParametersContainer("PC_0002"); Parameters pars = new Parameters(eurostagSim); pars.setDefParamSetNum(1); pars.addParameter(new ParameterFloat("INTMAX2", 3.3000f)); pc1.getParameters().add(pars); pc1 = dbmanager.save(pc1); Internal it1 = new Internal("IT_0002"); it1.setModelContainer(mtc1); it1.setParametersContainer(pc1); it1 = dbmanager.save(it1); assertNotNull(it1.getId()); log.info("Internal (" + it1.getNativeId() + ") was persisted with id " + it1.getId()); //default param 1.1000, no corresponding param in the parameters set Float flValue = dbmanager.getFloatParameter(it1, eurostagSim, "INTMAX"); assertTrue(flValue.compareTo(1.1000f) == 0); //default param 2.2000 should be overwritten by actual param (which value is 3.3000) in the parameters set Float flValue2 = dbmanager.getFloatParameter(it1, eurostagSim, "INTMAX2"); assertTrue(flValue2.compareTo(3.3000f) == 0); //no default param, nor actual param in the param set try { Float flValue3 = dbmanager.getFloatParameter(it1, eurostagSim, "INTMAX3"); //must not get here assertTrue(false); } catch (RuntimeException e) { log.info(e.getMessage()); } }
From source file:com.redhat.rhn.domain.monitoring.command.Command.java
/** * Check that values for a given metric are in monotonically increasing * order. For the metric <code>m</code>, look at the associated threshold * parameters and ensure that the values returned by <code>toValue</code> * for them are in strictly ascending order. * <p>//from w w w.j a v a 2s. c om * Each violation is entered into the returned list as four values: (param1, * value1, param2, value2) such that * <code>param1.thresholdType < param2.thresholdType</code>, but * <code>value1 >= value2</code> when compared as numbers. The * parameters in the returned list are of type {@link ThresholdParameter}, * and the values are strings. * * @param metric the metric for which to check the parameter values * @param toValue a transformer mapping threshold parameters to their value * @return a list indicating which parameters have non-ascending values. */ public ArrayList checkAscendingValues(Metric metric, Transformer toValue) { ArrayList result = new ArrayList(); ThresholdParameter prevParam = null; Float prevValue = null; String prevStr = null; for (Iterator j = listThresholds(metric).iterator(); j.hasNext();) { ThresholdParameter currParam = (ThresholdParameter) j.next(); String currStr = (String) toValue.transform(currParam); Float currValue = null; try { currValue = NumberUtils.createFloat(currStr); } catch (NumberFormatException e) { // Ignore this value currValue = null; } if (currValue != null && prevValue != null) { if (currValue.compareTo(prevValue) <= 0) { result.add(prevParam); result.add(prevStr); result.add(currParam); result.add(currStr); } } if (currValue != null) { prevValue = currValue; prevParam = currParam; prevStr = currStr; } } assert result.size() % 4 == 0; return result; }
From source file:org.searsia.engine.Resource.java
@Override public int compareTo(Resource e2) { Float score1 = getPrior(); Float score2 = e2.getPrior(); return score1.compareTo(score2); }
From source file:ml.shifu.shifu.core.processor.VarSelectModelProcessor.java
private void prepareSEJobConf(SourceType source, final Configuration conf) throws IOException { String modelConfigPath = ShifuFileUtils.getFileSystemBySourceType(source) .makeQualified(new Path(super.getPathFinder().getModelConfigPath(source))).toString(); String columnConfigPath = ShifuFileUtils.getFileSystemBySourceType(source) .makeQualified(new Path(super.getPathFinder().getColumnConfigPath(source))).toString(); // only the first model is sued for sensitivity analysis String seModelPath = ShifuFileUtils.getFileSystemBySourceType(source) .makeQualified(new Path(super.getPathFinder().getModelsPath(), "model0." + modelConfig.getAlgorithm().toLowerCase())) .toString();/*ww w . ja v a2s . c o m*/ String filePath = modelConfigPath + "," + columnConfigPath + "," + seModelPath; // add jars and files to hadoop mapper and reducer new GenericOptionsParser(conf, new String[] { "-libjars", addRuntimeJars(), "-files", filePath }); conf.setBoolean(GuaguaMapReduceConstants.MAPRED_MAP_TASKS_SPECULATIVE_EXECUTION, true); conf.setBoolean(GuaguaMapReduceConstants.MAPRED_REDUCE_TASKS_SPECULATIVE_EXECUTION, true); conf.setBoolean(GuaguaMapReduceConstants.MAPREDUCE_MAP_SPECULATIVE, true); conf.setBoolean(GuaguaMapReduceConstants.MAPREDUCE_REDUCE_SPECULATIVE, true); conf.set(Constants.SHIFU_MODEL_CONFIG, ShifuFileUtils.getFileSystemBySourceType(source) .makeQualified(new Path(super.getPathFinder().getModelConfigPath(source))).toString()); conf.set(Constants.SHIFU_COLUMN_CONFIG, ShifuFileUtils.getFileSystemBySourceType(source) .makeQualified(new Path(super.getPathFinder().getColumnConfigPath(source))).toString()); conf.set(NNConstants.MAPRED_JOB_QUEUE_NAME, Environment.getProperty(Environment.HADOOP_JOB_QUEUE, "default")); conf.set(Constants.SHIFU_MODELSET_SOURCE_TYPE, source.toString()); // set mapreduce.job.max.split.locations to 100 to suppress warnings conf.setInt(GuaguaMapReduceConstants.MAPREDUCE_JOB_MAX_SPLIT_LOCATIONS, 5000); // Tmp set to false because of some cluster by default use gzip while CombineInputFormat will split gzip file (a // bug) conf.setBoolean(CombineInputFormat.SHIFU_VS_SPLIT_COMBINABLE, false); conf.setBoolean("mapreduce.input.fileinputformat.input.dir.recursive", true); conf.set("mapred.reduce.slowstart.completed.maps", Environment.getProperty("mapred.reduce.slowstart.completed.maps", "0.9")); conf.set(Constants.SHIFU_VARSELECT_FILTEROUT_TYPE, modelConfig.getVarSelectFilterBy()); Float filterOutRatio = this.modelConfig.getVarSelect().getFilterOutRatio(); if (filterOutRatio == null) { log.warn("filterOutRatio in var select is not set. Using default value 0.05."); filterOutRatio = 0.05f; } if (filterOutRatio.compareTo(Float.valueOf(1.0f)) >= 0) { throw new IllegalArgumentException("WrapperRatio should be in (0, 1)."); } conf.setFloat(Constants.SHIFU_VARSELECT_FILTEROUT_RATIO, filterOutRatio); conf.setInt(Constants.SHIFU_VARSELECT_FILTER_NUM, this.modelConfig.getVarSelectFilterNum()); String hdpVersion = HDPUtils.getHdpVersionForHDP224(); if (StringUtils.isNotBlank(hdpVersion)) { // for hdp 2.2.4, hdp.version should be set and configuration files should be add to container class path conf.set("hdp.version", hdpVersion); HDPUtils.addFileToClassPath(HDPUtils.findContainingFile("hdfs-site.xml"), conf); HDPUtils.addFileToClassPath(HDPUtils.findContainingFile("core-site.xml"), conf); HDPUtils.addFileToClassPath(HDPUtils.findContainingFile("mapred-site.xml"), conf); HDPUtils.addFileToClassPath(HDPUtils.findContainingFile("yarn-site.xml"), conf); } // one can set guagua conf in shifuconfig CommonUtils.injectHadoopShifuEnvironments(new ValueVisitor() { @Override public void inject(Object key, Object value) { conf.set(key.toString(), value.toString()); } }); // no matter how the mapreduce.task.io.sort.mb is set for sensitivity job, only 1 reducer and each mapper only // output column stats, 150MB is enough. conf.setInt("mapreduce.task.io.sort.mb", 150); }
From source file:org.tsaap.lti.tp.ResourceLink.java
/** * Convert outcome data type of value to a supported type if possible. * * @param ltiOutcome Outcome object/*w ww.j a va 2s . co m*/ * @param supportedType data type to be used (if null the reported supported types are used) * @return <code>true</code> if the type/value are valid and supported */ private boolean checkValueType(Outcome ltiOutcome, String supportedType) { List<String> supportedTypes = new ArrayList<String>(); String type; if (supportedType != null) { supportedTypes.add(supportedType); } else { type = this.getSetting("ext_ims_lis_resultvalue_sourcedids", EXT_TYPE_DECIMAL).toLowerCase(); type = type.replaceAll(" ", ""); String[] types = type.split(","); supportedTypes.addAll(Arrays.asList(types)); } type = ltiOutcome.getType(); String value = ltiOutcome.getValue(); // Check whether the type is supported or there is no value boolean ok = supportedTypes.contains(type) || (value.length() <= 0); if (!ok) { // Convert numeric values to decimal if (type.equals(EXT_TYPE_PERCENTAGE)) { if (value.endsWith("%")) { value = value.substring(0, value.length() - 1); } Float fValue = Utils.stringToFloat(value); ok = (fValue != null) && (fValue.compareTo(0.0f) >= 0) && (fValue.compareTo(100.0f) <= 0); if (ok) { ltiOutcome.setValue(Utils.floatToString(fValue / 100.0f)); ltiOutcome.setType(EXT_TYPE_DECIMAL); } } else if (type.equals(EXT_TYPE_RATIO)) { String[] parts = value.split("/", 2); ok = (parts.length == 2); if (ok) { Float fValue1 = Utils.stringToFloat(parts[0]); Float fValue2 = Utils.stringToFloat(parts[1]); ok = (fValue1 != null) && (fValue2 != null) && (fValue1.compareTo(0.0f) >= 0) && (fValue2.compareTo(0.0f) > 0); if (ok) { ltiOutcome.setValue(Utils.floatToString(fValue1 / fValue2)); ltiOutcome.setType(EXT_TYPE_DECIMAL); } } // Convert letter_af to letter_af_plus or text } else if (type.equals(EXT_TYPE_LETTER_AF)) { if (supportedTypes.contains(EXT_TYPE_LETTER_AF_PLUS)) { ok = true; ltiOutcome.setType(EXT_TYPE_LETTER_AF_PLUS); } else if (supportedTypes.contains(EXT_TYPE_TEXT)) { ok = true; ltiOutcome.setType(EXT_TYPE_TEXT); } // Convert letter_af_plus to letter_af or text } else if (type.equals(EXT_TYPE_LETTER_AF_PLUS)) { if (supportedTypes.contains(EXT_TYPE_LETTER_AF) && (value.length() == 1)) { ok = true; ltiOutcome.setType(EXT_TYPE_LETTER_AF); } else if (supportedTypes.contains(EXT_TYPE_TEXT)) { ok = true; ltiOutcome.setType(EXT_TYPE_TEXT); } // Convert text to decimal } else if (type.equals(EXT_TYPE_TEXT)) { Float fValue = Utils.stringToFloat(value); ok = (fValue != null) && (fValue.compareTo(0.0f) >= 0) && (fValue.compareTo(1.0f) <= 0); if (ok) { ltiOutcome.setType(EXT_TYPE_DECIMAL); } else if (value.endsWith("%")) { value = value.substring(0, value.length() - 1); fValue = Utils.stringToFloat(value); ok = (fValue != null) && (fValue.compareTo(0.0f) >= 0) && (fValue.compareTo(100.0f) <= 0); if (ok) { if (supportedTypes.contains(EXT_TYPE_PERCENTAGE)) { ltiOutcome.setType(EXT_TYPE_PERCENTAGE); } else { ltiOutcome.setValue(Utils.floatToString(fValue / 100.0f)); ltiOutcome.setType(EXT_TYPE_DECIMAL); } } } } } return ok; }
From source file:edu.cornell.mannlib.vitro.webapp.dao.jena.JenaBaseDao.java
/** * convenience method for use with functional properties *//*from ww w .ja va2s . com*/ protected void updatePropertyFloatValue(Resource res, Property dataprop, Float value, Model model) { if (dataprop != null) { Float existingValue = null; Statement stmt = res.getProperty(dataprop); if (stmt != null) { RDFNode object = stmt.getObject(); if (object != null && object.isLiteral()) { existingValue = ((Literal) object).getFloat(); } } if (value == null) { model.removeAll(res, dataprop, null); } else if (existingValue == null) { model.add(res, dataprop, Float.toString(value), XSDDatatype.XSDfloat); } else if (existingValue.compareTo(value) != 0) { model.removeAll(res, dataprop, null); model.add(res, dataprop, Float.toString(value), XSDDatatype.XSDfloat); } } }
From source file:org.etudes.component.app.jforum.JForumGradeServiceImpl.java
/** * Sorts evaluations// w ww .j ava 2 s . c om * * @param evaluations Evalutions * * @param evalSort Evaluation sort */ protected void sortEvaluations(List<Evaluation> evaluations, Evaluation.EvaluationsSort evalSort) { if (evalSort == Evaluation.EvaluationsSort.scores_a) { Collections.sort(evaluations, new Comparator<Evaluation>() { /*used 1000.0f for null scores to appear negative values below 1000 in proper order*/ public int compare(Evaluation eval1, Evaluation eval2) { Float f1 = eval1.getScore(); if (f1 == null) f1 = Float.valueOf(1000.0f); Float f2 = eval2.getScore(); if (f2 == null) f2 = Float.valueOf(1000.0f); int result = 0; result = f1.compareTo(f2); return result; } }); } else if (evalSort == Evaluation.EvaluationsSort.scores_d) { /*used 1000.0f for null scores to appear negative values below 1000 in proper order*/ Collections.sort(evaluations, new Comparator<Evaluation>() { public int compare(Evaluation eval1, Evaluation eval2) { Float f1 = eval1.getScore(); if (f1 == null) f1 = Float.valueOf(1000.0f); Float f2 = eval2.getScore(); if (f2 == null) f2 = Float.valueOf(1000.0f); int result = 0; result = -1 * f1.compareTo(f2); return result; } }); } }
From source file:org.muse.mneme.impl.SubmissionServiceImpl.java
/** * Get the submissions to the assignment made by all users. * /*from w w w . j a v a2 s. c o m*/ * @param assessment * The assessment. * @param sort * The sort. * @param question * An optional question, to use for sort-by-score (the score would be for this question in the submission, not the overall). * @return A List<Submission> of the submissions for the assessment. */ protected List<SubmissionImpl> getAssessmentSubmissions(Assessment assessment, final FindAssessmentSubmissionsSort sort, final Question question) { // collect the submissions to this assessment List<SubmissionImpl> rv = this.storage.getAssessmentSubmissions(assessment); // get all possible users who can submit Set<String> userIds = this.securityService.getUsersIsAllowed(MnemeService.SUBMIT_PERMISSION, assessment.getContext()); // filter out any userIds that are not currently defined List<User> users = this.userDirectoryService.getUsers(userIds); userIds.clear(); for (User user : users) { userIds.add(user.getId()); } // if any user is not represented in the submissions we found, add an empty submission for (String userId : userIds) { boolean found = false; for (Submission s : rv) { if (s.getUserId().equals(userId)) { found = true; break; } } if (!found) { SubmissionImpl s = this.getPhantomSubmission(userId, assessment); rv.add(s); } } // filter out any submissions found that are not for one of the users in the userIds list (they may have lost permission) for (Iterator i = rv.iterator(); i.hasNext();) { SubmissionImpl submission = (SubmissionImpl) i.next(); if (!userIds.contains(submission.getUserId())) { i.remove(); } } // sort - secondary sort of user name, or if primary is title, on submit date Collections.sort(rv, new Comparator() { public int compare(Object arg0, Object arg1) { int rv = 0; FindAssessmentSubmissionsSort secondary = null; switch (sort) { case userName_a: case userName_d: case status_a: case status_d: { String id0 = ((Submission) arg0).getUserId(); try { User u = userDirectoryService.getUser(id0); id0 = u.getSortName(); } catch (UserNotDefinedException e) { } String id1 = ((Submission) arg1).getUserId(); try { User u = userDirectoryService.getUser(id1); id1 = u.getSortName(); } catch (UserNotDefinedException e) { } rv = id0.compareToIgnoreCase(id1); secondary = FindAssessmentSubmissionsSort.sdate_a; break; } case final_a: case final_d: { Float final0 = null; Float final1 = null; if (question != null) { Answer a0 = ((Submission) arg0).getAnswer(question); Answer a1 = ((Submission) arg1).getAnswer(question); final0 = ((a0 == null) ? Float.valueOf(0f) : a0.getTotalScore()); final1 = ((a1 == null) ? Float.valueOf(0f) : a1.getTotalScore()); } else { final0 = ((Submission) arg0).getTotalScore(); final1 = ((Submission) arg1).getTotalScore(); } // null sorts small if ((final0 == null) && (final1 == null)) { rv = 0; } else if (final0 == null) { rv = -1; } else if (final1 == null) { rv = 1; } else { rv = final0.compareTo(final1); } secondary = FindAssessmentSubmissionsSort.userName_a; break; } case sdate_a: case sdate_d: { Date date0 = ((Submission) arg0).getSubmittedDate(); Date date1 = ((Submission) arg1).getSubmittedDate(); if ((date0 == null) && (date1 == null)) { rv = 0; } else if (date0 == null) { rv = -1; } else if (date1 == null) { rv = 1; } else { rv = ((Submission) arg0).getSubmittedDate() .compareTo(((Submission) arg1).getSubmittedDate()); } secondary = null; break; } } // secondary sort FindAssessmentSubmissionsSort third = null; if ((rv == 0) && (secondary != null)) { switch (secondary) { case userName_a: case userName_d: { String id0 = ((Submission) arg0).getUserId(); try { User u = userDirectoryService.getUser(id0); id0 = u.getSortName(); } catch (UserNotDefinedException e) { } String id1 = ((Submission) arg1).getUserId(); try { User u = userDirectoryService.getUser(id1); id1 = u.getSortName(); } catch (UserNotDefinedException e) { } rv = id0.compareToIgnoreCase(id1); third = FindAssessmentSubmissionsSort.sdate_a; break; } case sdate_a: case sdate_d: { Date date0 = ((Submission) arg0).getSubmittedDate(); Date date1 = ((Submission) arg1).getSubmittedDate(); if ((date0 == null) && (date1 == null)) { rv = 0; } else if (date0 == null) { rv = -1; } else if (date1 == null) { rv = 1; } else { rv = ((Submission) arg0).getSubmittedDate() .compareTo(((Submission) arg1).getSubmittedDate()); } break; } } } // third sort if ((rv == 0) && (third != null)) { switch (third) { case sdate_a: case sdate_d: { Date date0 = ((Submission) arg0).getSubmittedDate(); Date date1 = ((Submission) arg1).getSubmittedDate(); if ((date0 == null) && (date1 == null)) { rv = 0; } else if (date0 == null) { rv = -1; } else if (date1 == null) { rv = 1; } else { rv = ((Submission) arg0).getSubmittedDate() .compareTo(((Submission) arg1).getSubmittedDate()); } break; } } } return rv; } }); // reverse for descending (except for status) switch (sort) { case final_d: case userName_d: case sdate_d: { Collections.reverse(rv); } } return rv; }