List of usage examples for java.math BigDecimal compareTo
@Override public int compareTo(BigDecimal val)
From source file:com.xumpy.timesheets.services.TickedJobsDetailSrv.java
public static TickedJobsDetail calculate(List<? extends TickedJobs> tickedJobs, BigDecimal minimumPause) { TickedJobsDetail tickedJobsDetail = calculate(tickedJobs); if (!tickedJobsDetail.getActualPause().equals(new BigDecimal(0)) || tickedJobsDetail.getActualWorked().compareTo(new BigDecimal(360)) > 0) { if (tickedJobsDetail.getActualPause() != null) { BigDecimal pauseDifference = tickedJobsDetail.getActualPause().subtract(minimumPause); if (pauseDifference.compareTo(new BigDecimal(0)) < 0) { tickedJobsDetail.setActualPause(minimumPause); tickedJobsDetail.setActualWorked(tickedJobsDetail.getActualWorked().add(pauseDifference)); }//from w w w .j a va 2 s. com } } return tickedJobsDetail; }
From source file:lu.lippmann.cdb.graph.renderer.CadralEdgeColorTransformer.java
private static Color rangeColor(Color colorMin, Color colorMax, BigDecimal grow, BigDecimal minValue, BigDecimal maxValue) { BigDecimal colorValue = grow; if (colorValue == null) { return Color.LIGHT_GRAY; }/*from w w w. j a v a 2s . c o m*/ if (maxValue.compareTo(minValue) < 0) { return rangeColor(colorMin, colorMax, grow, maxValue, minValue); } else { int rMax = colorMax.getRed(); int gMax = colorMax.getGreen(); int bMax = colorMax.getBlue(); double color = 0.0; color = 255.0 - grow.subtract(minValue).doubleValue() * 255.0 / maxValue.subtract(minValue).doubleValue(); int r = rMax + (int) ((255 - rMax) * color / 255.0); int g = gMax + (int) ((255 - gMax) * color / 255.0); int b = bMax + (int) ((255 - bMax) * color / 255.0); if (r > 192 && g > 192 && b > 192) return Color.LIGHT_GRAY; return new Color(r, g, b); } }
From source file:com.cmsz.cloudplatform.utils.StringUtils.java
public static String convertHz(String hz) { if (StringUtil.isNullString(hz)) { return null; }//w w w . j ava2s. co m // NumberFormat format = new DecimalFormat("##0.00"); BigDecimal _1000 = new BigDecimal(1000); BigDecimal value = new BigDecimal(hz); if (value.compareTo(_1000) == -1) { return value + " MHz"; } else { return value.divide(_1000, 2, RoundingMode.HALF_UP) + " GHz"; } }
From source file:com.cmsz.cloudplatform.utils.StringUtils.java
public static String convertBytes(String bytes) { if (StringUtil.isNullString(bytes)) { return null; }/*from w ww . j a v a 2 s .c o m*/ // NumberFormat format = new DecimalFormat("##0.00"); BigDecimal _1024 = new BigDecimal(1024); BigDecimal value = new BigDecimal(bytes); if (value.compareTo(_1024) == -1) { return value.divide(new BigDecimal(1), 2, RoundingMode.HALF_UP) + " KB"; } else if (value.compareTo(_1024.multiply(_1024)) == -1) { return value.divide(_1024, 2, RoundingMode.HALF_UP) + " MB"; } else if (value.compareTo(_1024.multiply(_1024).multiply(_1024)) == -1) { return value.divide(_1024).divide(_1024, 2, RoundingMode.HALF_UP) + " GB"; } else { return value.divide(_1024).divide(_1024).divide(_1024, 2, RoundingMode.HALF_UP) + " TB"; } }
From source file:Main.java
public static BigDecimal cosine(BigDecimal x) { BigDecimal currentValue = BigDecimal.ONE; BigDecimal lastVal = currentValue.add(BigDecimal.ONE); BigDecimal xSquared = x.multiply(x); BigDecimal numerator = BigDecimal.ONE; BigDecimal denominator = BigDecimal.ONE; int i = 0;//from w w w. j a v a 2 s . c o m while (lastVal.compareTo(currentValue) != 0) { lastVal = currentValue; int z = 2 * i + 2; denominator = denominator.multiply(BigDecimal.valueOf(z)); denominator = denominator.multiply(BigDecimal.valueOf(z - 1)); numerator = numerator.multiply(xSquared); BigDecimal term = numerator.divide(denominator, SCALE + 5, ROUNDING_MODE); if (i % 2 == 0) { currentValue = currentValue.subtract(term); } else { currentValue = currentValue.add(term); } i++; } return currentValue; }
From source file:Main.java
public static BigDecimal cosine(BigDecimal x) { BigDecimal currentValue = BigDecimal.ONE; BigDecimal lastVal = currentValue.add(BigDecimal.ONE); BigDecimal xSquared = x.multiply(x); BigDecimal numerator = BigDecimal.ONE; BigDecimal denominator = BigDecimal.ONE; int i = 0;/*w ww . j a v a 2 s. c o m*/ while (lastVal.compareTo(currentValue) != 0) { lastVal = currentValue; int z = 2 * i + 2; denominator = denominator.multiply(BigDecimal.valueOf(z)); denominator = denominator.multiply(BigDecimal.valueOf(z - 1)); numerator = numerator.multiply(xSquared); BigDecimal term = numerator.divide(denominator, SCALE + 5, ROUNDING_MODE); if (i % 2 != 0) { currentValue = currentValue.add(term); } else { currentValue = currentValue.subtract(term); } i++; } return currentValue; }
From source file:com.qcadoo.model.api.BigDecimalUtils.java
/** * Check if decimals represent the same numeric value, even if they have different precisions or contexts. * /*from w ww. ja v a 2 s .c o m*/ * @param d1 * first BigDecimal to compare * @param d2 * second decimal to compare * @return true if decimals represent the same numeric value, even if they have different precisions or contexts. */ public static boolean valueEquals(final BigDecimal d1, final BigDecimal d2) { if (d1 == null) { return d2 == null; } else if (d2 == null) { return false; } return d1.compareTo(d2) == 0; }
From source file:org.apache.hadoop.hive.common.type.HiveIntervalDayTime.java
public static HiveIntervalDayTime valueOf(String strVal) { HiveIntervalDayTime result = null;//from www .j ava 2 s .co m if (strVal == null) { throw new IllegalArgumentException("Interval day-time string was null"); } Matcher patternMatcher = PATTERN_MATCHER.get(); patternMatcher.reset(strVal); if (patternMatcher.matches()) { // Parse out the individual parts try { // Sign - whether interval is positive or negative int sign = 1; String field = patternMatcher.group(1); if (field != null && field.equals("-")) { sign = -1; } int days = sign * IntervalDayTimeUtils.parseNumericValueWithRange("day", patternMatcher.group(2), 0, Integer.MAX_VALUE); byte hours = (byte) (sign * IntervalDayTimeUtils.parseNumericValueWithRange("hour", patternMatcher.group(3), 0, 23)); byte minutes = (byte) (sign * IntervalDayTimeUtils.parseNumericValueWithRange("minute", patternMatcher.group(4), 0, 59)); int seconds = 0; int nanos = 0; field = patternMatcher.group(5); if (field != null) { BigDecimal bdSeconds = new BigDecimal(field); if (bdSeconds.compareTo(IntervalDayTimeUtils.MAX_INT_BD) > 0) { throw new IllegalArgumentException("seconds value of " + bdSeconds + " too large"); } seconds = sign * bdSeconds.intValue(); nanos = sign * bdSeconds.subtract(new BigDecimal(bdSeconds.toBigInteger())) .multiply(IntervalDayTimeUtils.NANOS_PER_SEC_BD).intValue(); } result = new HiveIntervalDayTime(days, hours, minutes, seconds, nanos); } catch (Exception err) { throw new IllegalArgumentException("Error parsing interval day-time string: " + strVal, err); } } else { throw new IllegalArgumentException( "Interval string does not match day-time format of 'd h:m:s.n': " + strVal); } return result; }
From source file:Main.java
public static BigDecimal sine(BigDecimal x) { BigDecimal lastVal = x.add(BigDecimal.ONE); BigDecimal currentValue = x;/*from w w w . j a v a2 s.co m*/ BigDecimal xSquared = x.multiply(x); BigDecimal numerator = x; BigDecimal denominator = BigDecimal.ONE; int i = 0; while (lastVal.compareTo(currentValue) != 0) { lastVal = currentValue; int z = 2 * i + 3; denominator = denominator.multiply(BigDecimal.valueOf(z)); denominator = denominator.multiply(BigDecimal.valueOf(z - 1)); numerator = numerator.multiply(xSquared); BigDecimal term = numerator.divide(denominator, SCALE + 5, ROUNDING_MODE); if (i % 2 == 0) { currentValue = currentValue.subtract(term); } else { currentValue = currentValue.add(term); } i++; } return currentValue; }
From source file:Main.java
public static BigDecimal sine(BigDecimal x) { BigDecimal lastVal = x.add(BigDecimal.ONE); BigDecimal currentValue = x;//from ww w. ja v a 2 s .c o m BigDecimal xSquared = x.multiply(x); BigDecimal numerator = x; BigDecimal denominator = BigDecimal.ONE; int i = 0; while (lastVal.compareTo(currentValue) != 0) { lastVal = currentValue; int z = 2 * i + 3; denominator = denominator.multiply(BigDecimal.valueOf(z)); denominator = denominator.multiply(BigDecimal.valueOf(z - 1)); numerator = numerator.multiply(xSquared); BigDecimal term = numerator.divide(denominator, SCALE + 5, ROUNDING_MODE); if (i % 2 != 0) { currentValue = currentValue.add(term); } else { currentValue = currentValue.subtract(term); } i++; } return currentValue; }