List of usage examples for java.math BigDecimal intValue
@Override public int intValue()
From source file:com.nortal.petit.converter.util.ResultSetHelper.java
public static Integer getInteger(ResultSet rs, ColumnPosition column) throws SQLException { BigDecimal bd = getBigDecimal(rs, column); return bd == null ? null : Integer.valueOf(bd.intValue()); }
From source file:com.hotelbeds.hotelapimodel.auto.util.AssignUtils.java
public static ZoneOffset getZoneOffset(final BigDecimal hourDifference) { int auxValue = 0; if (hourDifference != null) { auxValue = hourDifference.intValue(); }/*from w w w . j a v a 2 s . c o m*/ return ZoneOffset.ofHours(auxValue); }
From source file:org.jlgranda.fede.ui.util.UI.java
/**Verifica que se haya cumplido con el salto dado para notificacin de cumplimiento de totales * @param total/*from ww w. j av a 2s. c o m*/ * @param gap * @return true si se ha completa la mitad y/o el total, falso en caso contrario */ public static boolean isOver(BigDecimal total, int gap) { boolean isOver = false; int half_gap = gap / 2; int factor; if (total.compareTo(BigDecimal.valueOf(gap)) > 0) { factor = total.intValue() % gap; isOver = factor == 0; } else if (total.compareTo(BigDecimal.valueOf(half_gap)) > 0) { factor = total.intValue() % half_gap; isOver = factor == 0; } return isOver; }
From source file:org.openo.nfvo.resmanagement.common.util.StringUtil.java
/** * * Number format.<br>// w ww . ja v a 2s . c om * * @param data * @return * @since NFVO 0.5 */ public static String numFormat(String data) { if (null != data && !("".equals(data))) { BigDecimal var = new BigDecimal(data); DecimalFormat formatWithoutFraction = new DecimalFormat("############"); DecimalFormat formatWithFraction = new DecimalFormat("############.############"); if (new BigDecimal(var.intValue()).compareTo(var) == 0) { return formatWithoutFraction.format(var); } return formatWithFraction.format(var); } return null; }
From source file:org.apache.hadoop.hive.common.type.HiveIntervalDayTime.java
public static HiveIntervalDayTime valueOf(String strVal) { HiveIntervalDayTime result = null;//from w w w . ja va 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:org.cubictest.persistence.LegacyUpgrade.java
private static ModelVersion getModelVersion(String xml) { String start = "<modelVersion>"; String end = "</modelVersion>"; int pos1 = xml.indexOf(start) + start.length(); int pos2 = xml.indexOf(end); BigDecimal version = new BigDecimal(xml.substring(pos1, pos2).trim()); // only supporting integer versions: return new ModelVersion(version.intValue()); }
From source file:org.kalypso.ui.wizards.results.ResultSldHelper.java
private static void configurePolygonSymbolizer(final SurfacePolygonSymbolizer symbolizer, final BigDecimal minValue, final BigDecimal maxValue) throws FilterEvaluationException { final PolygonColorMap templateColorMap = symbolizer.getColorMap(); final PolygonColorMap newColorMap = new PolygonColorMap_Impl(); // retrieve stuff from template-entries final PolygonColorMapEntry fromEntry = templateColorMap.findEntry("from", null); //$NON-NLS-1$ final PolygonColorMapEntry toEntry = templateColorMap.findEntry("to", null); //$NON-NLS-1$ // Fill/* w w w .jav a 2s.c o m*/ final Color fromPolygonColor = fromEntry.getFill().getFill(null); final Color toPolygonColor = toEntry.getFill().getFill(null); final double polygonOpacity = fromEntry.getFill().getOpacity(null); // Stroke final Color fromLineColor = fromEntry.getStroke().getStroke(null); final Color toLineColor = toEntry.getStroke().getStroke(null); final double lineOpacity = fromEntry.getStroke().getOpacity(null); // step width final double stepWidth = fromEntry.getTo(null); // scale of the step width final BigDecimal setScale = new BigDecimal(fromEntry.getFrom(null)).setScale(0, BigDecimal.ROUND_FLOOR); final int stepWidthScale = setScale.intValue(); // get rounded values below min and above max (rounded by first decimal) // as a first try we will generate isareas by using class steps of 0.1 // later, the classes will be created by using user defined class steps. // for that we fill an array of calculated (later user defined values) from max to min final BigDecimal minDecimal = minValue.setScale(1, BigDecimal.ROUND_FLOOR); final BigDecimal maxDecimal = maxValue.setScale(1, BigDecimal.ROUND_CEILING); final BigDecimal polygonStepWidth = new BigDecimal(stepWidth).setScale(stepWidthScale, BigDecimal.ROUND_FLOOR); int numOfClasses = (maxDecimal.subtract(minDecimal).divide(polygonStepWidth)).intValue(); // set to provide more them 1 or 0 classes. in such cases the color map will not be created, that results error. if (numOfClasses < 2) { numOfClasses = (maxDecimal.subtract(minDecimal).divide(polygonStepWidth.divide(new BigDecimal(4)))) .intValue(); } for (int currentClass = 0; currentClass < numOfClasses; currentClass++) { final double fromValue = minDecimal.doubleValue() + currentClass * polygonStepWidth.doubleValue(); final double toValue = minDecimal.doubleValue() + (currentClass + 1) * polygonStepWidth.doubleValue(); // Stroke Color lineColor; if (fromLineColor == toLineColor) lineColor = fromLineColor; else lineColor = interpolateColor(fromLineColor, toLineColor, currentClass, numOfClasses); // Fill final Color polygonColor = interpolateColor(fromPolygonColor, toPolygonColor, currentClass, numOfClasses); lineColor = polygonColor; final Stroke stroke = StyleFactory.createStroke(lineColor, lineOpacity, 1); final Fill fill = StyleFactory.createFill(polygonColor, polygonOpacity); final ParameterValueType label = StyleFactory.createParameterValueType("Isoflche " + currentClass); //$NON-NLS-1$ final ParameterValueType from = StyleFactory.createParameterValueType(fromValue); final ParameterValueType to = StyleFactory.createParameterValueType(toValue); final PolygonColorMapEntry colorMapEntry = new PolygonColorMapEntry_Impl(fill, stroke, label, from, to); newColorMap.addColorMapClass(colorMapEntry); } symbolizer.setColorMap(newColorMap); }
From source file:com.github.jessemull.microflex.util.BigDecimalUtil.java
/** * Converts a list of BigDecimals to a list of integers. * @param List<BigDecimal> list of BigDecimals * @return list of shorts */// w w w .j a v a 2 s. com public static List<Integer> toIntList(List<BigDecimal> list) { List<Integer> intList = new ArrayList<Integer>(); for (BigDecimal val : list) { if (!OverFlowUtil.intOverflow(val)) { OverFlowUtil.overflowError(val); } intList.add(val.intValue()); } return intList; }
From source file:org.apache.hadoop.hive.serde2.io.TimestampWritable.java
public static Timestamp doubleToTimestamp(double f) { long seconds = (long) f; // We must ensure the exactness of the double's fractional portion. // 0.6 as the fraction part will be converted to 0.59999... and // significantly reduce the savings from binary serializtion BigDecimal bd = new BigDecimal(String.valueOf(f)); bd = bd.subtract(new BigDecimal(seconds)).multiply(new BigDecimal(1000000000)); int nanos = bd.intValue(); // Convert to millis long millis = seconds * 1000; Timestamp t = new Timestamp(millis); // Set remaining fractional portion to nanos t.setNanos(nanos);// www. ja va 2s .co m return t; }
From source file:com.sfs.Formatter.java
/** * Gets the part number of months based on the number of weeks supplied. * * @param weeks the weeks value//w w w .j a va 2 s.c o m * @return the part months */ public static int getPartMonths(final int weeks) { BigDecimal bd = new BigDecimal(weeks / WEEKS_IN_MONTH); bd = bd.setScale(0, BigDecimal.ROUND_DOWN); return (int) bd.intValue(); }