List of usage examples for java.lang Math log10
@HotSpotIntrinsicCandidate public static double log10(double a)
From source file:org.esa.s1tbx.calibration.gpf.calibrators.ERSCalibrator.java
/** * Compute ADC power loss value for given pixel value using LUT in Appendix F1 or F2. * * @param dn The pixel value// w w w . j ava 2s . c o m * @param array 2-D array holding ADC power loss value data given in Appendix F1 or F2 * @return The ADC power loss value (in linear scale) */ private static double getPowerLossValue(final double dn, final double[][] array) { final int numRows = array.length; final int numCols = array[0].length; if (numCols != 2) { throw new OperatorException("Incorrect array dimension"); } double dnInDb; if (dn < underFlowFloat) { return -underFlowFloat; } else { dnInDb = 10.0 * Math.log10(dn); } int row1 = 0; int row2 = 0; if (dnInDb < array[0][0]) { row1 = 0; row2 = 1; } else if (dnInDb > array[numRows - 1][0]) { row1 = numRows - 2; row2 = numRows - 1; } else { for (int i = 1; i < numRows; i++) { if (dnInDb < array[i][0]) { row1 = i - 1; row2 = i; break; } } } final double intensityK1 = array[row1][0]; final double intensityK2 = array[row2][0]; final double loss1 = array[row1][1]; final double loss2 = array[row2][1]; final double lambda = (dnInDb - intensityK1) / (intensityK2 - intensityK1); double loss = (1 - lambda) * loss1 + lambda * loss2; loss = FastMath.pow(10.0, loss / 10.0); // dB to linear scale return loss; }
From source file:ui.server.GetTables.java
/** * Compute the average kd per interaction and record the results in a * List<coordinates> per year/*from w ww.j av a2 s . c om*/ * * @param aptamerType * @param negativeLog10 * @param bestKdOnly * @return a list of coordinates x->(Integer) year, y->(double)kd, * z->(?)null * @throws IOException */ private List<Coordinate<Integer, Double, ?>> makeyearvsKd(String aptamerType, boolean negativeLog10, boolean bestKdOnly) throws IOException { List<Coordinate<Integer, Double, ?>> rm = new ArrayList<Coordinate<Integer, Double, ?>>(); String q = null; q = makeKdYearQuery(aptamerType) + "&cursor"; URLReader ur = new URLReader(FreebaseCredentials.getScheme(), FreebaseCredentials.getHost(), FreebaseCredentials.getPath(), q, FreebaseCredentials.getKey()); JSONObject rc = ur.getJSON(); // A map to keep track of the PMIDs that have already been retrieved Map<String, PubmedInfo> pubmeds = new HashMap<String, PubmedInfo>(); try { JSONArray r = rc.getJSONArray("result"); boolean lf = true; while (lf) { try { String cursorVal = rc.getString("cursor").replace("\"", ""); // store the kds in a temp list r: for (int i = 0; i < r.length(); i++) { JSONObject ja = r.getJSONObject(i); String anMid = ja.getString("mid"); JSONArray kds = ja.getJSONArray("/base/aptamer/interaction/has_dissociation_constant"); List<Double> tmpKds = new ArrayList<Double>(); for (int j = 0; j < kds.length(); j++) { JSONObject currKd = kds.getJSONObject(j); String kd = currKd.getString("/base/aptamer/dissociation_constant/has_value"); String kd_tmp = currKd .getString("/base/aptamer/dissociation_constant/has_temporary_string_value") .replace("\"", ""); Double aKd = -1.0; try { aKd = Double.parseDouble(kd); } catch (NumberFormatException e) { try { aKd = Double.parseDouble(kd_tmp); } catch (NumberFormatException e2) { aKd = -1.0; } } if (negativeLog10 == true) { if (aKd > 0.0) { Double x = (-1) * Math.log10(aKd); tmpKds.add(x); } } else { tmpKds.add(aKd); } } // now store only the average or the best kd Double kd_val = -1.0; if (bestKdOnly) { if (tmpKds.size() > 1) { kd_val = StatUtils.getMin(tmpKds); } else { kd_val = StatUtils.getMin(tmpKds); } } else { kd_val = StatUtils.computeAverage(tmpKds); } // now get year // get the value of the pmid JSONArray pmids = ja.getJSONArray("/base/aptamer/experimental_outcome/is_outcome_of"); JSONObject aPmidObj = pmids.getJSONObject(0); String aPmid = null; int year = -1; try { aPmid = aPmidObj.getJSONArray("/base/aptamer/experiment/pubmed_id").getString(0); } catch (JSONException e) { continue r; } if (aPmid != null && aPmid.length() > 0) { // check that the pmid is not in the pubmeds map if (!pubmeds.containsKey(aPmid)) { // get the year PubmedInfo pi = new PubmedInfo(aPmid); int y = pi.getPublicationYear(); // check if positive if (y > 0) { year = y; } pubmeds.put(aPmid, pi); } else { // get the year from the map PubmedInfo pi = pubmeds.get(aPmid); int y = pi.getPublicationYear(); if (y > 0) { year = y; } } } if (kd_val > 0 && year > 0) { // then add a coordinate Coordinate<Integer, Double, Double> c = new Coordinate<Integer, Double, Double>(anMid, year, kd_val, null); rm.add(c); } else { // TODO:deal with the case that there is no valid kd // or year } } // add the cursor to the query if (cursorVal.equals("false")) { lf = false; } else { q = makeKdYearQuery(aptamerType) + "&cursor=" + cursorVal; ur = new URLReader(FreebaseCredentials.getScheme(), FreebaseCredentials.getHost(), FreebaseCredentials.getPath(), q, FreebaseCredentials.getKey()); rc = ur.getJSON(); r = rc.getJSONArray("result"); } } catch (JSONException e) { e.printStackTrace(); } } } catch (JSONException e) { e.printStackTrace(); } return rm; }
From source file:ui.server.GetTables.java
/** * Compute the average kd per interaction and the average sequence length * per interaction and return a List<coordinates> * //from w w w. j a v a 2 s. c o m * @param anAptamerType * the type of aptamer * @param negativeLog10 * if true the logarithm of base 10 of kd values will be * multiplied by -1 and returned i.e.: -log(kd) * @param bestKdOnly * if true every coordinate will be compsed by the average * sequence length (x) and the best kd (y) * * @return the list of coodinates */ private List<Coordinate<Double, Double, Double>> makeKdVsLength(String anAptamerType, boolean negativeLog10, boolean bestKdOnly) throws IOException { List<Coordinate<Double, Double, Double>> rm = new ArrayList<Coordinate<Double, Double, Double>>(); String q = null; q = makeKdLengthQuery(anAptamerType) + "&cursor"; URLReader ur = new URLReader(FreebaseCredentials.getScheme(), FreebaseCredentials.getHost(), FreebaseCredentials.getPath(), q, FreebaseCredentials.getKey()); JSONObject rc = ur.getJSON(); try { JSONArray r = rc.getJSONArray("result"); boolean lf = true; while (lf) { try { String cursorVal = rc.getString("cursor").replace("\"", ""); for (int i = 0; i < r.length(); i++) { JSONObject jo = r.getJSONObject(i); JSONArray kds = jo.getJSONArray("/base/aptamer/interaction/has_dissociation_constant"); String mid = jo.getString("mid"); // store the kds in a temp list List<Double> tmpKds = new ArrayList<Double>(); for (int j = 0; j < kds.length(); j++) { JSONObject ja = kds.getJSONObject(j); String kd = ja.getString("/base/aptamer/dissociation_constant/has_value"); String kd_tmp = ja .getString("/base/aptamer/dissociation_constant/has_temporary_string_value") .replace("\"", ""); Double aKd = -1.0; try { aKd = Double.parseDouble(kd); } catch (NumberFormatException e) { try { aKd = Double.parseDouble(kd_tmp); } catch (NumberFormatException e2) { aKd = -1.0; } } if (negativeLog10 == true) { if (aKd > 0.0) { Double x = (-1) * Math.log10(aKd); tmpKds.add(x); } } else { tmpKds.add(aKd); } } Double kd_val = -1.0; if (bestKdOnly) { if (tmpKds.size() > 1) { kd_val = StatUtils.getMin(tmpKds); } else { kd_val = StatUtils.getMin(tmpKds); } } else { kd_val = StatUtils.computeAverage(tmpKds); } JSONArray seqlengths = jo.getJSONArray("/base/aptamer/interaction/has_participant"); List<Double> tmpSeqLens = new ArrayList<Double>(); for (int k = 0; k < seqlengths.length(); k++) { JSONObject ja = seqlengths.getJSONObject(k); String seq = ja.getString("/base/aptamer/linear_polymer/sequence").replace("\"", ""); Double length = (double) seq.length(); tmpSeqLens.add(length); } Double seq_avg = StatUtils.computeAverage(tmpSeqLens); if (kd_val > 0.0 && seq_avg > 0.0) { Coordinate<Double, Double, Double> c = new Coordinate<Double, Double, Double>(mid, seq_avg, kd_val, null); rm.add(c); } } // add the cursor to the query if (cursorVal.equals("false")) { lf = false; } else { q = makeKdLengthQuery(anAptamerType) + "&cursor=" + cursorVal; ur = new URLReader(FreebaseCredentials.getScheme(), FreebaseCredentials.getHost(), FreebaseCredentials.getPath(), q, FreebaseCredentials.getKey()); rc = ur.getJSON(); r = rc.getJSONArray("result"); } } catch (JSONException e) { e.printStackTrace(); } } } catch (JSONException e) { e.printStackTrace(); } return rm; }
From source file:org.nd4j.linalg.util.BigDecimalMath.java
/** * Convert an absolute error to a precision. * * @param x The value of the variable * The value returned depends only on the absolute value, not on the sign. * @param xerr The absolute error in the variable * The value returned depends only on the absolute value, not on the sign. * @return The number of valid digits in x. * Derived from the representation x+- xerr, as if the error was represented * 38/*from ww w . j a v a2 s . c o m*/ * in a "half width" (half of the error bar) form. * The value is rounded down, and on the pessimistic side for that reason. */ static public int err2prec(double x, double xerr) { /* Example: an error of xerr=+-0.5 at x=100 represents 100+-0.5 with * a precision = 3 (digits). */ return 1 + (int) (Math.log10(Math.abs(0.5 * x / xerr))); }
From source file:org.nd4j.linalg.util.BigDecimalMath.java
/** * Convert a relative error to a precision. * * @param xerr The relative error in the variable. * The value returned depends only on the absolute value, not on the sign. * @return The number of valid digits in x. * The value is rounded down, and on the pessimistic side for that reason. *//* w w w. j ava 2 s . co m*/ static public int err2prec(double xerr) { /* Example: an error of xerr=+-0.5 a precision of 1 (digit), an error of * +-0.05 a precision of 2 (digits) */ return 1 + (int) (Math.log10(Math.abs(0.5 / xerr))); }
From source file:org.esa.s1tbx.calibration.gpf.calibrators.ERSCalibrator.java
public void removeFactorsForCurrentTile(Band targetBand, Tile targetTile, String srcBandName) throws OperatorException { // For ground range product, // a) remove antenna pattern gain // b) remove range spreading loss corrections // c) remove replica pulse variation (ERS-2 only) // d) multiply calibration constant (done in applyCalibration) // e) apply ADC power loss correction ///*from w ww . j ava 2s. c o m*/ // For slant range complex product, // c) remove replica pulse variation (ERS-2 only) // d) multiply calibration constant (done in applyCalibration) // e) apply ADC power loss correction final Rectangle targetTileRectangle = targetTile.getRectangle(); final int tx0 = targetTileRectangle.x; final int ty0 = targetTileRectangle.y; final int tw = targetTileRectangle.width; final int th = targetTileRectangle.height; final ProductData trgData = targetTile.getDataBuffer(); //System.out.println("ERSCalibrator: tx0 = " + tx0 + ", ty0 = " + ty0 + ", tw = " + tw + ", th = " + th); final Band sourceBand1 = sourceProduct.getBand(srcBandName); final Tile sourceTile = getSourceTile(sourceBand1, targetTileRectangle); final ProductData srcData = sourceTile.getDataBuffer(); final String[] srcBandNames = { targetBand.getName() }; Band sourceBand2 = null; if (srcBandNames.length > 1) { sourceBand2 = sourceProduct.getBand(srcBandNames[1]); } final Unit.UnitType bandUnit = Unit.getUnitType(sourceBand1); if (applyADCSaturationCorrection && !adcHasBeenTestedFlag) { testADC(sourceBand1, sourceBand2, bandUnit); } boolean applyADCSaturationCorrectionToCurrentTile = false; if (applyADCSaturationCorrection && th >= blockHeight && tw >= blockWidth) { applyADCSaturationCorrectionToCurrentTile = true; } double[][] adcPowerLoss = null; if (applyADCSaturationCorrectionToCurrentTile) { adcPowerLoss = computeADCPowerLossValuesForCurrentTile(sourceBand1, sourceBand2, tx0, ty0, tw, th, bandUnit); } double sigma = 0.0; int adcJ = 0; for (int x = tx0; x < tx0 + tw; x++) { double antennaPatternByRangeSpreadingLoss = 0.0; if (!isComplex) { antennaPatternByRangeSpreadingLoss = antennaPatternGain[x] / rangeSpreadingLoss[x]; } if (applyADCSaturationCorrectionToCurrentTile) { adcJ = Math.min(((x - tx0) / blockWidth), adcPowerLoss[0].length - 1); } for (int y = ty0; y < ty0 + th; y++) { final int srcIndex = sourceTile.getDataBufferIndex(x, y); final int tgtIndex = targetTile.getDataBufferIndex(x, y); if (bandUnit == Unit.UnitType.AMPLITUDE) { final double dn = srcData.getElemDoubleAt(srcIndex); sigma = dn * dn; } else if (bandUnit == Unit.UnitType.AMPLITUDE_DB) { sigma = FastMath.pow(10, srcData.getElemDoubleAt(srcIndex) / 5.0); } else if (bandUnit == Unit.UnitType.INTENSITY) { sigma = srcData.getElemDoubleAt(srcIndex); } else if (bandUnit == Unit.UnitType.INTENSITY_DB) { sigma = FastMath.pow(10, srcData.getElemDoubleAt(srcIndex) / 10.0); } else { throw new OperatorException("ERSCalibrator: Unknown band unit"); } if (!isComplex) { // ground range sigma *= antennaPatternByRangeSpreadingLoss; } if (!isERS1Mission) { sigma /= replicaPulseVariationsCorrectionFactor; } if (applyADCSaturationCorrectionToCurrentTile) { final int adcI = Math.min(((y - ty0) / blockHeight), adcPowerLoss.length - 1); sigma *= adcPowerLoss[adcI][adcJ]; } if (bandUnit == Unit.UnitType.AMPLITUDE) { trgData.setElemDoubleAt(tgtIndex, Math.sqrt(sigma)); } else if (bandUnit == Unit.UnitType.AMPLITUDE_DB) { trgData.setElemDoubleAt(tgtIndex, 5.0 * Math.log10(sigma)); } else if (bandUnit == Unit.UnitType.INTENSITY) { trgData.setElemDoubleAt(tgtIndex, sigma); } else if (bandUnit == Unit.UnitType.INTENSITY_DB) { trgData.setElemDoubleAt(tgtIndex, 10.0 * Math.log10(sigma)); } } } }
From source file:org.esa.nest.gpf.ERSCalibrator.java
public void removeFactorsForCurrentTile(Band targetBand, Tile targetTile, String srcBandName) throws OperatorException { // For ground range product, // a) remove antenna pattern gain // b) remove range spreading loss corrections // c) remove replica pulse variation (ERS-2 only) // d) multiply calibration constant (done in applyCalibration) // e) apply ADC power loss correction ///*from w w w . j a v a 2 s .c om*/ // For slant range complex product, // c) remove replica pulse variation (ERS-2 only) // d) multiply calibration constant (done in applyCalibration) // e) apply ADC power loss correction final Rectangle targetTileRectangle = targetTile.getRectangle(); final int tx0 = targetTileRectangle.x; final int ty0 = targetTileRectangle.y; final int tw = targetTileRectangle.width; final int th = targetTileRectangle.height; final ProductData trgData = targetTile.getDataBuffer(); //System.out.println("RetroOp: tx0 = " + tx0 + ", ty0 = " + ty0 + ", tw = " + tw + ", th = " + th); final Band sourceBand1 = sourceProduct.getBand(srcBandName); final Tile sourceTile = getSourceTile(sourceBand1, targetTileRectangle); final ProductData srcData = sourceTile.getDataBuffer(); final String[] srcBandNames = { targetBand.getName() }; Band sourceBand2 = null; if (srcBandNames.length > 1) { sourceBand2 = sourceProduct.getBand(srcBandNames[1]); } final Unit.UnitType bandUnit = Unit.getUnitType(sourceBand1); if (applyADCSaturationCorrection && !adcHasBeenTestedFlag) { testADC(sourceBand1, sourceBand2, bandUnit); } boolean applyADCSaturationCorrectionToCurrentTile = false; if (applyADCSaturationCorrection && th >= blockHeight && tw >= blockWidth) { applyADCSaturationCorrectionToCurrentTile = true; } double[][] adcPowerLoss = null; if (applyADCSaturationCorrectionToCurrentTile) { adcPowerLoss = computeADCPowerLossValuesForCurrentTile(sourceBand1, sourceBand2, tx0, ty0, tw, th, bandUnit); } double sigma = 0.0; int adcJ = 0; for (int x = tx0; x < tx0 + tw; x++) { double antennaPatternByRangeSpreadingLoss = 0.0; if (!isComplex) { antennaPatternByRangeSpreadingLoss = antennaPatternGain[x] / rangeSpreadingLoss[x]; } if (applyADCSaturationCorrectionToCurrentTile) { adcJ = Math.min(((x - tx0) / blockWidth), adcPowerLoss[0].length - 1); } for (int y = ty0; y < ty0 + th; y++) { final int srcIndex = sourceTile.getDataBufferIndex(x, y); if (bandUnit == Unit.UnitType.AMPLITUDE) { final double dn = srcData.getElemDoubleAt(srcIndex); sigma = dn * dn; } else if (bandUnit == Unit.UnitType.AMPLITUDE_DB) { sigma = Math.pow(10, srcData.getElemDoubleAt(srcIndex) / 5.0); } else if (bandUnit == Unit.UnitType.INTENSITY) { sigma = srcData.getElemDoubleAt(srcIndex); } else if (bandUnit == Unit.UnitType.INTENSITY_DB) { sigma = Math.pow(10, srcData.getElemDoubleAt(srcIndex) / 10.0); } else { throw new OperatorException("ERSCalibrator: Unknown band unit"); } if (!isComplex) { // ground range sigma *= antennaPatternByRangeSpreadingLoss; } if (!isERS1Mission) { sigma /= replicaPulseVariationsCorrectionFactor; } if (applyADCSaturationCorrectionToCurrentTile) { final int adcI = Math.min(((y - ty0) / blockHeight), adcPowerLoss.length - 1); sigma *= adcPowerLoss[adcI][adcJ]; } if (bandUnit == Unit.UnitType.AMPLITUDE) { trgData.setElemDoubleAt(srcIndex, Math.sqrt(sigma)); } else if (bandUnit == Unit.UnitType.AMPLITUDE_DB) { trgData.setElemDoubleAt(srcIndex, 5.0 * Math.log10(sigma)); } else if (bandUnit == Unit.UnitType.INTENSITY) { trgData.setElemDoubleAt(srcIndex, sigma); } else if (bandUnit == Unit.UnitType.INTENSITY_DB) { trgData.setElemDoubleAt(srcIndex, 10.0 * Math.log10(sigma)); } } } }
From source file:org.esa.s1tbx.calibration.gpf.ERSCalibrator.java
public void removeFactorsForCurrentTile(Band targetBand, Tile targetTile, String srcBandName) throws OperatorException { // For ground range product, // a) remove antenna pattern gain // b) remove range spreading loss corrections // c) remove replica pulse variation (ERS-2 only) // d) multiply calibration constant (done in applyCalibration) // e) apply ADC power loss correction ///*from w w w . ja v a 2 s. c o m*/ // For slant range complex product, // c) remove replica pulse variation (ERS-2 only) // d) multiply calibration constant (done in applyCalibration) // e) apply ADC power loss correction final Rectangle targetTileRectangle = targetTile.getRectangle(); final int tx0 = targetTileRectangle.x; final int ty0 = targetTileRectangle.y; final int tw = targetTileRectangle.width; final int th = targetTileRectangle.height; final ProductData trgData = targetTile.getDataBuffer(); //System.out.println("RetroOp: tx0 = " + tx0 + ", ty0 = " + ty0 + ", tw = " + tw + ", th = " + th); final Band sourceBand1 = sourceProduct.getBand(srcBandName); final Tile sourceTile = getSourceTile(sourceBand1, targetTileRectangle); final ProductData srcData = sourceTile.getDataBuffer(); final String[] srcBandNames = { targetBand.getName() }; Band sourceBand2 = null; if (srcBandNames.length > 1) { sourceBand2 = sourceProduct.getBand(srcBandNames[1]); } final Unit.UnitType bandUnit = Unit.getUnitType(sourceBand1); if (applyADCSaturationCorrection && !adcHasBeenTestedFlag) { testADC(sourceBand1, sourceBand2, bandUnit); } boolean applyADCSaturationCorrectionToCurrentTile = false; if (applyADCSaturationCorrection && th >= blockHeight && tw >= blockWidth) { applyADCSaturationCorrectionToCurrentTile = true; } double[][] adcPowerLoss = null; if (applyADCSaturationCorrectionToCurrentTile) { adcPowerLoss = computeADCPowerLossValuesForCurrentTile(sourceBand1, sourceBand2, tx0, ty0, tw, th, bandUnit); } double sigma = 0.0; int adcJ = 0; for (int x = tx0; x < tx0 + tw; x++) { double antennaPatternByRangeSpreadingLoss = 0.0; if (!isComplex) { antennaPatternByRangeSpreadingLoss = antennaPatternGain[x] / rangeSpreadingLoss[x]; } if (applyADCSaturationCorrectionToCurrentTile) { adcJ = Math.min(((x - tx0) / blockWidth), adcPowerLoss[0].length - 1); } for (int y = ty0; y < ty0 + th; y++) { final int srcIndex = sourceTile.getDataBufferIndex(x, y); if (bandUnit == Unit.UnitType.AMPLITUDE) { final double dn = srcData.getElemDoubleAt(srcIndex); sigma = dn * dn; } else if (bandUnit == Unit.UnitType.AMPLITUDE_DB) { sigma = FastMath.pow(10, srcData.getElemDoubleAt(srcIndex) / 5.0); } else if (bandUnit == Unit.UnitType.INTENSITY) { sigma = srcData.getElemDoubleAt(srcIndex); } else if (bandUnit == Unit.UnitType.INTENSITY_DB) { sigma = FastMath.pow(10, srcData.getElemDoubleAt(srcIndex) / 10.0); } else { throw new OperatorException("ERSCalibrator: Unknown band unit"); } if (!isComplex) { // ground range sigma *= antennaPatternByRangeSpreadingLoss; } if (!isERS1Mission) { sigma /= replicaPulseVariationsCorrectionFactor; } if (applyADCSaturationCorrectionToCurrentTile) { final int adcI = Math.min(((y - ty0) / blockHeight), adcPowerLoss.length - 1); sigma *= adcPowerLoss[adcI][adcJ]; } if (bandUnit == Unit.UnitType.AMPLITUDE) { trgData.setElemDoubleAt(srcIndex, Math.sqrt(sigma)); } else if (bandUnit == Unit.UnitType.AMPLITUDE_DB) { trgData.setElemDoubleAt(srcIndex, 5.0 * Math.log10(sigma)); } else if (bandUnit == Unit.UnitType.INTENSITY) { trgData.setElemDoubleAt(srcIndex, sigma); } else if (bandUnit == Unit.UnitType.INTENSITY_DB) { trgData.setElemDoubleAt(srcIndex, 10.0 * Math.log10(sigma)); } } } }
From source file:org.forester.archaeopteryx.TreePanel.java
final private void paintCollapsedNode(final Graphics2D g, final PhylogenyNode node, final boolean to_graphics_file, final boolean to_pdf, final boolean is_in_found_nodes) { if ((to_pdf || to_graphics_file) && getOptions().isPrintBlackAndWhite()) { g.setColor(Color.BLACK);/*from w ww .ja v a 2s . c om*/ } else if (is_in_found_nodes) { g.setColor(getTreeColorSet().getFoundColor()); } else if (getControlPanel().isColorAccordingToTaxonomy()) { g.setColor(getTaxonomyBasedColor(node)); } else { g.setColor(getTreeColorSet().getCollapseFillColor()); } double d = node.getAllExternalDescendants().size(); if (d > 1000) { d = (3 * _y_distance) / 3; } else { d = (Math.log10(d) * _y_distance) / 2.5; } if (d < BOX_SIZE) { d = BOX_SIZE; } _polygon.reset(); _polygon.addPoint(ForesterUtil.roundToInt(node.getXcoord() - TreePanel.BOX_SIZE), ForesterUtil.roundToInt(node.getYcoord())); _polygon.addPoint(ForesterUtil.roundToInt(node.getXcoord() + TreePanel.BOX_SIZE), ForesterUtil.roundToInt(node.getYcoord() - d)); _polygon.addPoint(ForesterUtil.roundToInt(node.getXcoord() + TreePanel.BOX_SIZE), ForesterUtil.roundToInt(node.getYcoord() + d)); g.fillPolygon(_polygon); paintNodeData(g, node, to_graphics_file, to_pdf, is_in_found_nodes); }
From source file:org.sakaiproject.assignment.impl.AssignmentServiceImpl.java
/** * Contains logic to consistently output a String based version of a grade * Interprets the grade using the scale for display * * This should probably be moved to a static utility class - ern * * @param grade//from w ww.j a v a 2s. co m * @param typeOfGrade * @param scaleFactor * @return */ @Override public String getGradeDisplay(String grade, Assignment.GradeType typeOfGrade, Integer scaleFactor) { String returnGrade = StringUtils.trimToEmpty(grade); if (scaleFactor == null) scaleFactor = getScaleFactor(); switch (typeOfGrade) { case SCORE_GRADE_TYPE: if (!returnGrade.isEmpty() && !"0".equals(returnGrade)) { int dec = new Double(Math.log10(scaleFactor)).intValue(); String decSeparator = formattedText.getDecimalSeparator(); String decimalGradePoint = returnGrade; try { Integer.parseInt(returnGrade); // if point grade, display the grade with factor decimal place if (returnGrade.length() > dec) { decimalGradePoint = returnGrade.substring(0, returnGrade.length() - dec) + decSeparator + returnGrade.substring(returnGrade.length() - dec); } else { String newGrade = "0".concat(decSeparator); for (int i = returnGrade.length(); i < dec; i++) { newGrade = newGrade.concat("0"); } decimalGradePoint = newGrade.concat(returnGrade); } } catch (NumberFormatException nfe1) { log.debug("Could not parse grade [{}] as an Integer trying as a Float, {}", returnGrade, nfe1.getMessage()); try { Float.parseFloat(returnGrade); decimalGradePoint = returnGrade; } catch (NumberFormatException nfe2) { log.debug("Could not parse grade [{}] as a Float, {}", returnGrade, nfe2.getMessage()); } } // get localized number format NumberFormat nbFormat = formattedText.getNumberFormat(dec, dec, false); DecimalFormat dcformat = (DecimalFormat) nbFormat; // show grade in localized number format try { Double dblGrade = dcformat.parse(decimalGradePoint).doubleValue(); decimalGradePoint = nbFormat.format(dblGrade); returnGrade = decimalGradePoint; } catch (Exception e) { log.warn("Could not parse grade [{}], {}", returnGrade, e.getMessage()); } } break; case UNGRADED_GRADE_TYPE: if (returnGrade.equalsIgnoreCase("gen.nograd")) { returnGrade = resourceLoader.getString("gen.nograd"); } break; case PASS_FAIL_GRADE_TYPE: if (returnGrade.equalsIgnoreCase("Pass")) { returnGrade = resourceLoader.getString("pass"); } else if (returnGrade.equalsIgnoreCase("Fail")) { returnGrade = resourceLoader.getString("fail"); } else { returnGrade = resourceLoader.getString("ungra"); } break; case CHECK_GRADE_TYPE: if (returnGrade.equalsIgnoreCase("Checked")) { returnGrade = resourceLoader.getString("gen.checked"); } else { returnGrade = resourceLoader.getString("ungra"); } break; default: if (returnGrade.isEmpty()) { returnGrade = resourceLoader.getString("ungra"); } } return returnGrade; }