List of usage examples for java.math BigDecimal ONE
BigDecimal ONE
To view the source code for java.math BigDecimal ONE.
Click Source Link
From source file:jp.furplag.util.commons.NumberUtils.java
/** * generate cosine factor for trigonometric functions in BigDecimal. * * @param mc {@link java.math.MathContext}. * @return list of cosine factors./*w w w . j av a 2s .co m*/ */ private static List<BigDecimal> initCosineFactor(MathContext mc) { int precision = (mc == null ? MathContext.DECIMAL128 : mc).getPrecision(); List<BigDecimal> factors = new ArrayList<BigDecimal>(); BigDecimal divisor = BigDecimal.valueOf(2d); BigDecimal temporary = BigDecimal.valueOf(2d); do { factors.add(BigDecimal.ONE.divide(divisor, precision + 2, RoundingMode.HALF_UP)); temporary = temporary.add(BigDecimal.ONE); divisor = divisor.multiply(temporary); temporary = temporary.add(BigDecimal.ONE); divisor = divisor.multiply(temporary); } while (factors.get(factors.size() - 1).compareTo(new BigDecimal("1E-" + (precision + 2))) > 0); return factors; }
From source file:net.sourceforge.entrainer.gui.socket.EntrainerSocketConnector.java
private void setAutoAmplitude(double value) { int val = new BigDecimal(value * 100).divide(BigDecimal.ONE, 0, RoundingMode.HALF_UP).intValue(); if (amplitude.getValue() == value) return;//from w w w. j a v a 2 s .c om isEntrainerAmplitudeMessage = true; amplitude.setValue(val); }
From source file:org.finra.herd.dao.helper.EmrPricingHelper.java
/** * Finds all the clusters that are within the range of lowest core instance price. * <p>// w w w. ja va2 s . c o m * For example, if the core prices are 0.30, 0.32, 0.34, 0.36, and the threshold value is 0.1(10%), then the lowest core price range should be [0.30, 0.33]. * The upper bound is derived by calculating 0.30*(1 + 0.1) = 0.33 * * @param emrClusterPrices the list of clusters to select from * @param lowestCoreInstancePriceThresholdPercentage the threshold value that defines the range of lowest core instance price * * @return the list of clusters that fall in lowest core instance price range */ List<EmrClusterPriceDto> getEmrClusterPricesWithinLowestCoreInstancePriceThreshold( final List<EmrClusterPriceDto> emrClusterPrices, final BigDecimal lowestCoreInstancePriceThresholdPercentage) { // Builds a tree map that has the core instance price as the key, and the list of pricing with the same core instance price as the value. The tree map // is automatically sorted, so it is easy to find the lowest core instance price range. TreeMap<BigDecimal, List<EmrClusterPriceDto>> emrClusterPriceMapKeyedByCoreInstancePrice = new TreeMap<>(); for (final EmrClusterPriceDto emrClusterPriceDto : emrClusterPrices) { final BigDecimal coreInstancePrice = getEmrClusterCoreInstancePrice(emrClusterPriceDto); if (emrClusterPriceMapKeyedByCoreInstancePrice.containsKey(coreInstancePrice)) { emrClusterPriceMapKeyedByCoreInstancePrice.get(coreInstancePrice).add(emrClusterPriceDto); } else { List<EmrClusterPriceDto> emrClusterPriceList = new ArrayList<>(); emrClusterPriceList.add(emrClusterPriceDto); emrClusterPriceMapKeyedByCoreInstancePrice.put(coreInstancePrice, emrClusterPriceList); } } // Log all the information in the tree map LOGGER.info("All available EMR clusters keyed by core instance price: availableEmrClusters={}", jsonHelper.objectToJson(emrClusterPriceMapKeyedByCoreInstancePrice)); // Finds the list of pricing in the range of the lowest core instance price List<EmrClusterPriceDto> lowestCoreInstancePriceEmrClusters = new ArrayList<>(); if (!emrClusterPriceMapKeyedByCoreInstancePrice.isEmpty()) { // calculate the lowest core instance price range final BigDecimal lowestCoreInstancePriceLowerBound = emrClusterPriceMapKeyedByCoreInstancePrice .firstEntry().getKey(); final BigDecimal lowestCoreInstancePriceUpperBound = lowestCoreInstancePriceLowerBound .multiply(BigDecimal.ONE.add(lowestCoreInstancePriceThresholdPercentage)); LOGGER.info("emrClusterLowestCoreInstancePriceRange={}", jsonHelper.objectToJson( Arrays.asList(lowestCoreInstancePriceLowerBound, lowestCoreInstancePriceUpperBound))); for (final Map.Entry<BigDecimal, List<EmrClusterPriceDto>> entry : emrClusterPriceMapKeyedByCoreInstancePrice .entrySet()) { final BigDecimal coreInstancePrice = entry.getKey(); // Fall into the lowest price range? add it to the list. // There is no need to check the lower bound here, since the tree map is sorted, and lower bound is the lowest core price in the tree map. if (coreInstancePrice.compareTo(lowestCoreInstancePriceUpperBound) <= 0) { lowestCoreInstancePriceEmrClusters.addAll(entry.getValue()); } else { // since the tree map is sorted in ascending order, we do not need to check the rest of entries in the map break; } } } return lowestCoreInstancePriceEmrClusters; }
From source file:net.sourceforge.entrainer.gui.socket.EntrainerSocketConnector.java
private void setAutoPinkNoise(double value) { int val = new BigDecimal(value * 1000).divide(BigDecimal.ONE, 0, RoundingMode.HALF_UP).intValue(); if (pinkNoise.getValue() == val) return;//from ww w.j a v a 2 s . c o m isEntrainerPinkNoiseAmplitudeMessage = true; pinkNoise.setValue(val); }
From source file:org.jasig.ssp.service.impl.EvaluatedSuccessIndicatorServiceImpl.java
private BigDecimal normalizeForScaleEvaluation(@Nullable Object metric, @Nonnull SuccessIndicator successIndicator) throws NumberFormatException, IllegalArgumentException { if (metric == null) { return null; }/*from w w w .ja v a2s . co m*/ if (metric instanceof Boolean) { return ((Boolean) metric).booleanValue() ? BigDecimal.ONE : BigDecimal.ZERO; } if (metric instanceof BigDecimal) { return ((BigDecimal) metric); } if (metric instanceof Number) { return BigDecimal.valueOf(((Number) metric).doubleValue()).setScale(DECIMAL_SCALE); } if (metric instanceof String) { return new BigDecimal((String) metric).setScale(DECIMAL_SCALE); } if (metric instanceof Ratio) { return ((Ratio) metric).ratio(); } throw new NumberFormatException("Cannot interpret evaluation input value [" + metric + "] of type [" + metric.getClass().getName() + "] as a BigDecimal"); }
From source file:org.eclipse.jubula.client.archive.XmlExporter.java
/** * @param xmlChkConf//from w ww .j av a2 s. c om * The xml configuration where the attributes should be saved. * @param contexts * The map where the context activation will be saved. */ private void fillCheckContext(CheckConfiguration xmlChkConf, Map<String, Boolean> contexts) { for (Entry<String, Boolean> e : contexts.entrySet()) { checkForCancel(); CheckActivatedContext c = xmlChkConf.addNewActiveContext(); c.setClass1(e.getKey()); Object obj = e.getValue(); if (obj instanceof BigDecimal) { BigDecimal bd = (BigDecimal) obj; c.setActive(bd.equals(BigDecimal.ONE) ? true : false); } else { c.setActive(e.getValue()); } } }
From source file:module.siadap.domain.wrappers.SiadapUniverseWrapper.java
/** * @param totalPeople// ww w .j a va 2 s . c om * the number of people to calculate the quota on * @param quota * the percentage points of quota * @return how many people it represents, it is never 0 due to SIADAPs rules */ private BigDecimal calculateQuota(int totalPeople, Integer quota) { BigDecimal result = new BigDecimal(totalPeople).multiply(new BigDecimal(quota)).divide(new BigDecimal(100)); int value = result.intValue(); return value > 0 ? result : BigDecimal.ONE; //if the quota is 0 the the quota shifts to 1 }
From source file:net.sourceforge.entrainer.gui.socket.EntrainerSocketConnector.java
private void setAutoFrequency(double value) { int val = new BigDecimal(value).divide(BigDecimal.ONE, 0, RoundingMode.HALF_UP).intValue(); if (frequency.getValue() == val) return;/*from w ww . j a va 2s.c o m*/ isEntrainerFrequencyMessage = true; frequency.setValue(val); }
From source file:jp.furplag.util.commons.NumberUtils.java
public static BigDecimal cos(final BigDecimal angle, MathContext mc, boolean isRadians) { if (angle == null) return null; BigDecimal cos = BigDecimal.ONE; BigDecimal radians = isRadians ? angle : valueOf(toRadians(angle), BigDecimal.class); BigDecimal nSquare = radians.pow(2); int index = 0; for (BigDecimal factor : COSINE_FACTOR_DECIMAL128) { BigDecimal temporary = factor.multiply(nSquare); if (index % 2 == 0) temporary = temporary.negate(); cos = cos.add(temporary);//from w w w. j a v a 2 s . c o m nSquare = nSquare.multiply(radians.pow(2)).setScale( ((mc == null ? MathContext.DECIMAL128 : mc).getPrecision() + 2), RoundingMode.HALF_UP); index++; } return cos.setScale((mc == null ? MathContext.DECIMAL128 : mc).getPrecision(), RoundingMode.HALF_UP); }
From source file:org.estatio.dom.invoice.Invoice.java
public BigDecimal default1NewItem() { return BigDecimal.ONE; }