List of usage examples for java.math BigDecimal ZERO
BigDecimal ZERO
To view the source code for java.math BigDecimal ZERO.
Click Source Link
From source file:com.legstar.mock.client.MockLsfileac.java
/** * Create a response to LSFILEAE execution request. * /* ww w .ja v a 2s. co m*/ * @param requestMessage the request message * @return formatted response * @throws RequestException if response cannot be built */ public static LegStarMessage getResponse(final LegStarMessage requestMessage) throws RequestException { if (LOG.isDebugEnabled()) { LOG.debug("Building response for program LSFILEAC"); } try { byte[] queryData = null; byte[] queryLimit = null; for (LegStarMessagePart part : requestMessage.getDataParts()) { if (part.getPartID().equals("QueryData")) { queryData = part.getContent(); } if (part.getPartID().equals("QueryLimit")) { queryLimit = part.getContent(); } } String namePattern = (queryData == null) ? "*" : getQueryName(queryData); List<byte[]> customers; if (queryLimit == null) { customers = FILEA.getCustomers(namePattern); } else { customers = FILEA.getCustomers(namePattern, getMaxItems(queryLimit)); } int offset = 0; String hostCharsetName = CobolContext.getDefaultHostCharsetName(); byte[] hostReplyStatus = new byte[151]; /* reply type */ CobolBinarySimpleConverter.toHostSingle(BigDecimal.ZERO, 2, false, hostReplyStatus, offset); offset += 2; /* search duration */ CobolStringSimpleConverter.toHostSingle("00:00:00", hostCharsetName, null, 8, false, hostReplyStatus, offset); offset += 8; /* total items */ CobolPackedDecimalSimpleConverter.toHostSingle(new BigDecimal(FILEA.getCustomersNumber()), 5, 8, 0, false, hostReplyStatus, offset); offset += 5; /* resp */ CobolBinarySimpleConverter.toHostSingle(BigDecimal.ZERO, 4, true, hostReplyStatus, offset); offset += 4; /* resp2 */ CobolBinarySimpleConverter.toHostSingle(BigDecimal.ZERO, 4, true, hostReplyStatus, offset); offset += 4; /* reply message */ CobolStringSimpleConverter.toHostSingle( (customers.size() > 0) ? "" : "NO CUSTOMER SATISFIES YOUR QUERY", hostCharsetName, null, 128, false, hostReplyStatus, offset); offset += 128; offset = 0; byte[] hostReplyData = null; if (customers.size() > 0) { hostReplyData = new byte[5 + 79 * customers.size()]; /* items number */ CobolPackedDecimalSimpleConverter.toHostSingle(new BigDecimal(customers.size()), 5, 8, 0, false, hostReplyData, offset); offset += 5; /* items */ for (byte[] customer : customers) { System.arraycopy(customer, 0, hostReplyData, offset, 79); offset += 79; } } LegStarMessage replyMessage = new LegStarMessage(); replyMessage.addDataPart(new ContainerPart("ReplyStatus", hostReplyStatus)); replyMessage.addDataPart(new ContainerPart("ReplyData", hostReplyData)); return replyMessage; } catch (HeaderPartException e) { throw new RequestException(e); } catch (CobolConversionException e) { throw new RequestException(e); } }
From source file:com.jnj.b2b.facades.variant.populators.VariantOptionDataPricePopulator.java
@Override public void populate(final VariantProductModel variantProductModel, final VariantOptionData variantOptionData) throws ConversionException { final PriceInformation priceInformation = getCommercePriceService() .getWebPriceForProduct(variantProductModel); PriceData priceData;/*w w w . j a va 2 s .co m*/ if (priceInformation != null && priceInformation.getPriceValue() != null) { priceData = getPriceDataFactory().create(PriceDataType.FROM, new BigDecimal(priceInformation.getPriceValue().getValue()), priceInformation.getPriceValue().getCurrencyIso()); } else { priceData = new PriceData(); priceData.setValue(BigDecimal.ZERO); priceData.setFormattedValue("0"); } variantOptionData.setPriceData(priceData); }
From source file:cz.muni.fi.dndtroops.test.TroopDaoImplTest.java
@BeforeClass public void setup() { troopA = new Troop(); troopA.setName("Angels"); troopA.setMoney(BigDecimal.ZERO); troopA.setMission("mise A"); troopB = new Troop(); troopB.setName("Bulls"); troopB.setMission("mise B"); troopB.setMoney(new BigDecimal("5")); }
From source file:pe.gob.mef.gescon.service.impl.ConsultaServiceImpl.java
@Override public List<Consulta> getQueryFilter(HashMap filters) { List<Consulta> lista = new ArrayList<Consulta>(); try {//ww w . j a v a2 s. c o m ConsultaDao consultaDao = (ConsultaDao) ServiceFinder.findBean("ConsultaDao"); List<HashMap> consulta = consultaDao.getQueryFilter(filters); if (!CollectionUtils.isEmpty(consulta)) { for (HashMap map : consulta) { Consulta c = new Consulta(); c.setIdconocimiento((BigDecimal) map.get("ID")); c.setNombre((String) map.get("NOMBRE")); c.setSumilla((String) map.get("SUMILLA")); c.setFechaPublicacion((Date) map.get("FECHA")); c.setIdCategoria((BigDecimal) map.get("IDCATEGORIA")); c.setCategoria((String) map.get("CATEGORIA")); c.setIdTipoConocimiento((BigDecimal) map.get("IDTIPOCONOCIMIENTO")); c.setTipoConocimiento((String) map.get("TIPOCONOCIMIENTO")); c.setIdEstado((BigDecimal) map.get("IDESTADO")); c.setEstado((String) map.get("ESTADO")); c.setFlgVinculo((BigDecimal) map.get("FLG")); BigDecimal contador = (BigDecimal) map.get("CONTADOR"); BigDecimal suma = (BigDecimal) map.get("SUMA"); if (BigDecimal.ZERO.equals(contador)) { c.setCalificacion(BigDecimal.ZERO.intValue()); } else { int calificacion = Math .round(Float.parseFloat(suma.toString()) / Integer.parseInt(contador.toString())); c.setCalificacion(calificacion); } lista.add(c); } } } catch (Exception e) { e.getMessage(); e.printStackTrace(); } return lista; }
From source file:com.SCI.centraltoko.utility.UtilityTools.java
public static String formatNumber(BigDecimal value) { if (value == null || value.equals(BigDecimal.ZERO)) { return "0"; } else {/*from ww w .ja v a 2 s .c om*/ NumberFormat formater = NumberFormat.getInstance(); formater.setMaximumFractionDigits(0); formater.setMinimumFractionDigits(0); return formater.format(value.setScale(0, RoundingMode.HALF_EVEN)); } }
From source file:io.seldon.recommendation.VariationTestingClientStrategy.java
public static VariationTestingClientStrategy build(List<Variation> variations) { Map<Range, ClientStrategy> strategyMap = new LinkedHashMap<>(); BigDecimal ratioTotal = BigDecimal.ZERO; for (Variation var : variations) { ratioTotal = ratioTotal.add(var.ratio); }//from ww w . j a va2 s . com BigDecimal currentMax = BigDecimal.ZERO; for (Variation var : variations) { NumberRange range = new NumberRange(currentMax, currentMax.add(var.ratio.divide(ratioTotal, 5, BigDecimal.ROUND_UP))); strategyMap.put(range, var.variationStrategy); currentMax = currentMax.add(var.ratio); } return new VariationTestingClientStrategy(strategyMap); }
From source file:edu.rice.cs.bioinfo.programs.phylonet.PhyloNetAAT.java
private static void checkTest(String nexus, String expectedStdOut, String expectedStdError, String testFile) throws IOException { String faultMessage = testFile + " failed."; ByteArrayOutputStream display = new ByteArrayOutputStream(); ByteArrayOutputStream error = new ByteArrayOutputStream(); Program.run(new ByteArrayInputStream(nexus.getBytes()), new PrintStream(error), new PrintStream(display), _rand, BigDecimal.ZERO); Assert.assertEquals(faultMessage, expectedStdError, error.toString().replace("\r", "")); Assert.assertEquals(faultMessage, expectedStdOut, display.toString().replace("\r", "")); }
From source file:org.eel.kitchen.jsonschema.keyword.DivisibleByKeywordValidator.java
@Override protected void validateDecimal(final ValidationReport report, final JsonNode instance) { final BigDecimal instanceValue = instance.decimalValue(); final BigDecimal decimalValue = number.decimalValue(); final BigDecimal remainder = instanceValue.remainder(decimalValue); /*// w ww . jav a 2 s .c o m * We cannot use equality! As far as BigDecimal goes, * "0" and "0.0" are NOT equal. But .compareTo() returns the correct * result. */ if (remainder.compareTo(BigDecimal.ZERO) == 0) return; final Message.Builder msg = newMsg().setMessage("number is not a multiple of divisibleBy") .addInfo("value", instance).addInfo("divisor", number); report.addMessage(msg.build()); }
From source file:com.miko.demo.neo4j.model.EntityC.java
public EntityC(String name, BigDecimal value) { Assert.hasText(name, "Name can not be empty"); Assert.isTrue(BigDecimal.ZERO.compareTo(value) < 0, "Value must be greater than zero!"); this.name = name; this.value = value; }
From source file:net.sf.reportengine.core.calc.TestCalculators.java
@Test public void testUniversalSumCalculator() { SumGroupCalculator calculator = new SumGroupCalculator(); assertTrue(calculator.init() instanceof DefaultCalcIntermResult); assertTrue(calculator.init().getResult() instanceof BigDecimal); assertEquals(calculator.init().getResult(), BigDecimal.ZERO); DefaultCalcIntermResult<BigDecimal> testIntermResult = new DefaultCalcIntermResult<BigDecimal>( BigDecimal.ZERO);/*from ww w .j a v a 2s. c om*/ DefaultCalcIntermResult<BigDecimal> newResult = calculator.compute(testIntermResult, "1"); assertNotNull(newResult); assertNotNull(newResult.getResult()); assertEquals(newResult.getResult(), new BigDecimal(1)); testIntermResult = newResult; newResult = calculator.compute(testIntermResult, Integer.valueOf(7)); assertNotNull(newResult); assertNotNull(newResult.getResult()); assertEquals(newResult.getResult(), new BigDecimal(8)); testIntermResult = new DefaultCalcIntermResult<BigDecimal>(BigDecimal.ZERO); newResult = calculator.compute(testIntermResult, new BigDecimal(1.18907)); assertNotNull(newResult); assertNotNull(newResult.getResult()); assertTrue(newResult.getResult().doubleValue() == 1.18907D); testIntermResult = new DefaultCalcIntermResult<BigDecimal>(new BigDecimal(1.18907)); newResult = calculator.compute(testIntermResult, new Double(2.3)); assertNotNull(newResult); assertNotNull(newResult.getResult()); assertTrue(newResult.getResult().doubleValue() == 3.48907); }