Java Code Examples for java.math.BigDecimal

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project accounted4, under directory /accounted4/accounted4-money/src/main/java/com/accounted4/money/.

Source file: Split.java

  20 
vote

@Override public BigDecimal nextAmount(final int index){
  if (index == (partitions - 1)) {
    BigDecimal multiplicand=new BigDecimal(partitions - 1);
    return inputMoney.getAmount().subtract(ceiling.multiply(multiplicand));
  }
  return ceiling;
}
 

Example 2

From project adbcj, under directory /api/src/main/java/org/adbcj/support/.

Source file: DefaultValue.java

  18 
vote

public BigDecimal getBigDecimal(){
  if (value == null) {
    return null;
  }
  if (value instanceof BigDecimal) {
    return (BigDecimal)value;
  }
  return new BigDecimal(value.toString());
}
 

Example 3

From project agileBase, under directory /gtpb_server/src/com/gtwm/pb/model/manageData/.

Source file: ViewTools.java

  18 
vote

public Double roundTo(int decimalPlaces,double number){
  BigDecimal bigDecimal=new BigDecimal(number);
  String stringRepresentation=bigDecimal.toPlainString();
  stringRepresentation=stringRepresentation.replaceAll("^\\-","");
  stringRepresentation=stringRepresentation.replaceAll("\\.\\d+$","");
  int precision=stringRepresentation.length() + decimalPlaces;
  MathContext mc=new MathContext(precision,RoundingMode.HALF_UP);
  bigDecimal=bigDecimal.round(mc);
  return bigDecimal.doubleValue();
}
 

Example 4

From project Amantech, under directory /Android/action_bar_sherlock/src/com/actionbarsherlock/widget/.

Source file: ActivityChooserModel.java

  18 
vote

@Override public String toString(){
  StringBuilder builder=new StringBuilder();
  builder.append("[");
  builder.append("; activity:").append(activity);
  builder.append("; time:").append(time);
  builder.append("; weight:").append(new BigDecimal(weight));
  builder.append("]");
  return builder.toString();
}
 

Example 5

From project Amoeba-for-Aladdin, under directory /src/java/com/meidusa/amoeba/sqljep/function/.

Source file: Add.java

  18 
vote

static long toDay(Number n){
  if (n instanceof BigDecimal) {
    BigDecimal dec=(BigDecimal)n;
    BigDecimal t=dec.multiply(DAY_MILIS);
    t=t.setScale(0,BigDecimal.ROUND_HALF_UP);
    return t.longValue();
  }
 else {
    return n.longValue() * 86400000;
  }
}
 

Example 6

From project andlytics, under directory /src/com/github/andlyticsproject/model/.

Source file: AppStats.java

  18 
vote

public void calcNumberOfCommentsPercentString(){
  int numberOfComments=getNumberOfComments();
  float percent=0.0f;
  if (totalDownloads > 0) {
    percent=100.0f / totalDownloads * numberOfComments;
  }
  BigDecimal percentBigDecimal=new BigDecimal(percent);
  percentBigDecimal=percentBigDecimal.setScale(2,BigDecimal.ROUND_HALF_UP);
  this.numberOfCommentsPercentString=percentBigDecimal.toPlainString();
}
 

Example 7

From project arquillian-extension-seam2, under directory /src/test/java/org/jboss/arquillian/seam2/.

Source file: ConversationTestCase.java

  18 
vote

@Test public void should_add_items_within_conversation() throws Exception {
  final Item laptop=new Item("Lappy",BigDecimal.TEN);
  final Item bike=new Item("Bike",BigDecimal.valueOf(12.0));
  shoppingCart.add(bike);
  shoppingCart.add(laptop,10);
  BigDecimal finalPrice=shoppingCart.checkout();
  assertThat(finalPrice).isEqualByComparingTo(BigDecimal.valueOf(112L));
}
 

Example 8

From project arquillian-showcase, under directory /ejb/src/main/java/com/acme/ejb/calc/.

Source file: MortgageCalculatorBean.java

  18 
vote

/** 
 * a = [ P(1 + r)^Y * r ] / [ (1 + r)^Y - 1 ]
 */
@Override public BigDecimal calculateMonthlyPayment(double principal,double interestRate,int termYears){
  BigDecimal p=new BigDecimal(principal);
  int divisionScale=p.precision() + CURRENCY_DECIMALS;
  BigDecimal r=new BigDecimal(interestRate).divide(ONE_HUNDRED,MathContext.UNLIMITED).divide(TWELVE,divisionScale,RoundingMode.HALF_EVEN);
  BigDecimal z=r.add(BigDecimal.ONE);
  BigDecimal tr=new BigDecimal(Math.pow(z.doubleValue(),termYears * 12));
  return p.multiply(tr).multiply(r).divide(tr.subtract(BigDecimal.ONE),divisionScale,RoundingMode.HALF_EVEN).setScale(CURRENCY_DECIMALS,RoundingMode.HALF_EVEN);
}
 

Example 9

From project b3log-latke, under directory /latke/src/main/java/org/b3log/latke/util/.

Source file: Stopwatchs.java

  18 
vote

@Override public String toString(){
  float percentOfRoot=getPercentOfRoot();
  if (0 > percentOfRoot) {
    percentOfRoot=0F;
  }
  final BigDecimal percenOfRoot=new BigDecimal(percentOfRoot,MATH_CONTEXT);
  final StringBuilder stringBuilder=new StringBuilder("[").append(percenOfRoot).append("]%, [").append(getElapsedTime()).append("]ms [").append(getTaskTitle()).append("]").append(Strings.LINE_SEPARATOR);
  return stringBuilder.toString();
}
 

Example 10

From project baseunits, under directory /src/main/java/jp/xet/baseunits/money/.

Source file: Money.java

  18 
vote

/** 
 * For convenience, an amount can be rounded to create a Money.
 * @param rawAmount ?
 * @param currency ??????
 * @param roundingMode ????€??
 * @return ???
 * @throws IllegalArgumentException [email protected] null}?????????
 * @since 1.1
 */
public static Money valueOf(BigDecimal rawAmount,Currency currency,RoundingMode roundingMode){
  Validate.notNull(rawAmount);
  Validate.notNull(currency);
  Validate.notNull(rawAmount);
  BigDecimal amount=rawAmount.setScale(currency.getDefaultFractionDigits(),roundingMode);
  return new Money(amount,currency);
}
 

Example 11

From project big-data-plugin, under directory /test-src/org/pentaho/hbase/.

Source file: HBaseValueMetaTest.java

  18 
vote

@Test public void testEncodeColumnValueBigNumber() throws Exception {
  BigDecimal value=new BigDecimal(42);
  ValueMetaInterface valMeta=new ValueMeta("TestBigNum",ValueMetaInterface.TYPE_BIGNUMBER);
  HBaseValueMeta mappingMeta=new HBaseValueMeta("famliy1" + HBaseValueMeta.SEPARATOR + "testcol"+ HBaseValueMeta.SEPARATOR+ "anAlias",ValueMetaInterface.TYPE_BIGNUMBER,-1,-1);
  CommonHBaseBytesUtil bu=new CommonHBaseBytesUtil();
  byte[] encoded=HBaseValueMeta.encodeColumnValue(value,valMeta,mappingMeta,bu);
  assertTrue(encoded != null);
  assertEquals(bu.toString(encoded),value.toString());
}
 

Example 12

From project 2Degrees-Toolbox, under directory /ActionBarSherlock/src/com/actionbarsherlock/widget/.

Source file: ActivityChooserModel.java

  17 
vote

@Override public String toString(){
  StringBuilder builder=new StringBuilder();
  builder.append("[");
  builder.append("; activity:").append(activity);
  builder.append("; time:").append(time);
  builder.append("; weight:").append(new BigDecimal(weight));
  builder.append("]");
  return builder.toString();
}
 

Example 13

From project ActionBarSherlock, under directory /library/src/com/actionbarsherlock/widget/.

Source file: ActivityChooserModel.java

  17 
vote

@Override public String toString(){
  StringBuilder builder=new StringBuilder();
  builder.append("[");
  builder.append("; activity:").append(activity);
  builder.append("; time:").append(time);
  builder.append("; weight:").append(new BigDecimal(weight));
  builder.append("]");
  return builder.toString();
}
 

Example 14

From project activejdbc, under directory /javalite-common/src/main/java/org/javalite/common/.

Source file: Convert.java

  17 
vote

public static BigDecimal toBigDecimal(Object value){
  if (value == null) {
    return null;
  }
 else   if (value instanceof BigDecimal) {
    return (BigDecimal)value;
  }
 else {
    return new BigDecimal(value.toString());
  }
}
 

Example 15

From project activemq-apollo, under directory /apollo-selector/src/main/java/org/apache/activemq/apollo/filter/.

Source file: UnaryExpression.java

  17 
vote

private static Number negate(Number left){
  Class clazz=left.getClass();
  if (clazz == Integer.class) {
    return new Integer(-left.intValue());
  }
 else   if (clazz == Long.class) {
    return new Long(-left.longValue());
  }
 else   if (clazz == Float.class) {
    return new Float(-left.floatValue());
  }
 else   if (clazz == Double.class) {
    return new Double(-left.doubleValue());
  }
 else   if (clazz == BigDecimal.class) {
    BigDecimal bd=(BigDecimal)left;
    bd=bd.negate();
    if (BD_LONG_MIN_VALUE.compareTo(bd) == 0) {
      return Long.valueOf(Long.MIN_VALUE);
    }
    return bd;
  }
 else {
    throw new RuntimeException("Don't know how to negate: " + left);
  }
}
 

Example 16

From project android-bankdroid, under directory /src/com/liato/bankdroid/banking/.

Source file: Bank.java

  17 
vote

public void update() throws BankException, LoginException, BankChoiceException {
  balance=new BigDecimal(0);
  oldAccounts=new HashMap<String,Account>();
  for (  Account account : accounts) {
    oldAccounts.put(account.getId(),account);
  }
  accounts=new ArrayList<Account>();
}
 

Example 17

From project android-sdk, under directory /src/test/java/com/mobeelizer/mobile/android/types/.

Source file: DecimalFieldTypeHelperTest.java

  17 
vote

@Test public void shouldSetErrorWhileSetGreaterThanMaxValueFromEntityToDatabase() throws Exception {
  Map<String,String> options=new HashMap<String,String>();
  options.put("maxValue","10.0");
  options.put("includeMaxValue","true");
  ContentValues values=mock(ContentValues.class);
  MobeelizerErrorsBuilder errors=mock(MobeelizerErrorsBuilder.class);
  TestEntity entity=new TestEntity();
  entity.setDoubleP(11.0);
  FieldType.DECIMAL.setValueFromEntityToDatabase(values,entity,fieldDoubleP,true,options,errors);
  verify(values,never()).put(eq("doubleP"),anyString());
  verify(errors).addFieldMustBeLessThanOrEqualTo("doubleP",new BigDecimal("10.0"));
}
 

Example 18

From project androidZenWriter, under directory /library/src/com/actionbarsherlock/widget/.

Source file: ActivityChooserModel.java

  17 
vote

@Override public String toString(){
  StringBuilder builder=new StringBuilder();
  builder.append("[");
  builder.append("; activity:").append(activity);
  builder.append("; time:").append(time);
  builder.append("; weight:").append(new BigDecimal(weight));
  builder.append("]");
  return builder.toString();
}
 

Example 19

From project arastreju, under directory /arastreju.sge/src/main/java/org/arastreju/sge/model/nodes/.

Source file: SNValue.java

  17 
vote

/** 
 * {@inheritDoc}
 */
public BigDecimal getDecimalValue(){
  if (value instanceof String) {
    return new BigDecimal((String)value);
  }
  return (BigDecimal)value;
}
 

Example 20

From project arquillian-rusheye, under directory /rusheye-api/src/main/java/org/jboss/rusheye/result/.

Source file: ResultEvaluator.java

  17 
vote

/** 
 * Evaluates the comparison result using perception settings to obtain conclusion of comparison process.
 * @param perception the perception settings used in process of comparison which got the given comparisonResult
 * @param comparisonResult the result of comparison process
 * @return the simple conclusion of comparison process
 */
public ResultConclusion evaluate(Perception perception,ComparisonResult comparisonResult){
  if (comparisonResult.isEqualsImages()) {
    return ResultConclusion.SAME;
  }
  if (perception.getGlobalDifferencePercentage() != null) {
    BigDecimal totalPixels=new BigDecimal(comparisonResult.getTotalPixels());
    BigDecimal differentPixels=new BigDecimal(comparisonResult.getDifferentPixels());
    BigDecimal ratio;
    if (comparisonResult.getTotalPixels() != 0) {
      ratio=differentPixels.multiply(ONE_HUNDRED).divide(totalPixels);
    }
 else {
      ratio=BigDecimal.ZERO;
    }
    int result=ratio.compareTo(new BigDecimal(perception.getGlobalDifferencePercentage()));
    if (result <= 0) {
      return ResultConclusion.PERCEPTUALLY_SAME;
    }
  }
 else   if (perception.getGlobalDifferencePixelAmount() != null) {
    if (comparisonResult.getDifferentPixels() <= perception.getGlobalDifferencePixelAmount()) {
      return ResultConclusion.PERCEPTUALLY_SAME;
    }
  }
 else {
    return ResultConclusion.ERROR;
  }
  return ResultConclusion.DIFFER;
}
 

Example 21

From project asakusafw-examples, under directory /example-basketanalysis/src/test/java/com/example/basketanalysis/testing/.

Source file: LogLineFactory.java

  17 
vote

public static LogLine create(String userId,String accessDateTime,String query){
  LogLine result=new LogLine();
  result.setUserIdAsString(userId);
  result.setAccessDateTime(new BigDecimal(accessDateTime));
  result.setQueryAsString(query);
  return result;
}
 

Example 22

From project Betfair-Trickle, under directory /src/main/java/uk/co/onehp/trickle/services/betfair/.

Source file: BetfairServiceImpl.java

  17 
vote

@Override @Transactional public void placeBet(Bet bet){
  PlaceBetsReq placeBetsReq=new PlaceBetsReq();
  placeBetsReq.setBets(new ArrayOfPlaceBets());
  Strategy strategy=bet.getStrategy();
  BigDecimal liability=strategy.getLiability().divide(new BigDecimal(bet.getNumberOfSplits()),BigDecimal.ROUND_HALF_UP);
  Pricing bestPricing=BettingUtil.bestPrice(bet.getHorse().getPrices(),strategy.getAspect());
  if (bestPricing.getPrice().compareTo(strategy.getMaxOdds()) <= 0 && bestPricing.getPrice().compareTo(strategy.getMinOdds()) >= 0) {
    if (strategy.getChasePriceByTick() == 0) {
      if (bestPricing.getAmountAvailable().compareTo(liability) >= 0) {
        placeBetsReq.getBets().getPlaceBets().add(createMOCExchangeBet(bet,liability,bestPricing.getPrice()));
      }
 else {
        placeBetsReq.getBets().getPlaceBets().add(createMOCExchangeBet(bet,bestPricing.getAmountAvailable(),bestPricing.getPrice()));
        placeBetsReq.getBets().getPlaceBets().add(createLimitedSPBet(bet,liability.subtract(bestPricing.getAmountAvailable())));
      }
    }
 else {
      placeBetsReq.getBets().getPlaceBets().add(createMOCExchangeBet(bet,liability,BettingUtil.findChasePrice(bestPricing.getPrice(),strategy.getChasePriceByTick(),strategy.getAspect())));
    }
  }
 else {
    placeBetsReq.getBets().getPlaceBets().add(createLimitedSPBet(bet,liability));
  }
  sendRequest(placeBetsReq);
}
 

Example 23

From project Bitcoin-Wallet-for-Android, under directory /wallet/src/de/schildbach/wallet/ui/.

Source file: AmountCalculatorFragment.java

  17 
vote

private void updateAppearance(){
  if (exchangeRate != null) {
    localAmountView.setEnabled(true);
    final BigDecimal bdExchangeRate=new BigDecimal(exchangeRate);
    if (exchangeDirection) {
      final BigInteger btcAmount=btcAmountView.getAmount();
      if (btcAmount != null) {
        localAmountView.setAmount(null);
        localAmountView.setHint(new BigDecimal(btcAmount).multiply(bdExchangeRate).toBigInteger());
        btcAmountView.setHint(null);
      }
    }
 else {
      final BigInteger localAmount=localAmountView.getAmount();
      if (localAmount != null) {
        btcAmountView.setAmount(null);
        btcAmountView.setHint(new BigDecimal(localAmount).divide(bdExchangeRate,RoundingMode.HALF_UP).toBigInteger());
        localAmountView.setHint(null);
      }
    }
    exchangeRateView.setText(getString(R.string.amount_calculator_dialog_exchange_rate,exchangeCurrency,WalletUtils.formatValue(new BigDecimal(Utils.COIN).multiply(bdExchangeRate).toBigInteger())));
  }
 else {
    localAmountView.setEnabled(false);
    exchangeRateView.setText(R.string.amount_calculator_dialog_exchange_rate_not_available);
  }
}
 

Example 24

From project bitfluids, under directory /src/main/java/at/bitcoin_austria/bitfluids/.

Source file: Tx2FluidsAdapter.java

  17 
vote

public TxNotifier convert(final FluidsNotifier fluidsNotifier){
  return new TxNotifier(){
    @Override public void onValue(    Bitcoins bitcoins,    Address key,    Sha256Hash hash){
      FluidType type=Preconditions.checkNotNull(lookup.get(key));
      try {
        double price=priceService.getEurQuote();
        BigDecimal eurPerBitcoin=BigDecimal.valueOf(price);
        BigDecimal euros=bitcoins.multiply(eurPerBitcoin);
        BigDecimal euroPrice=BigDecimal.valueOf(type.getEuroPrice());
        BigDecimal anzahl=euros.divide(euroPrice,RoundingMode.HALF_UP);
        BigDecimal rounded=BigDecimal.valueOf(anzahl.add(BigDecimal.valueOf(0.5)).longValue());
        anzahl=rounded;
        fluidsNotifier.onFluidPaid(new TransactionItem(type,bitcoins,anzahl.intValue(),price,hash));
      }
 catch (      RemoteSystemFail remoteSystemFail) {
        fluidsNotifier.onError(remoteSystemFail.getMessage(),type,bitcoins);
      }
    }
  }
;
}
 

Example 25

From project blueprint-namespaces, under directory /blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/.

Source file: AggregateConverter.java

  16 
vote

public Object convertToNumber(Number value,Class toType) throws Exception {
  toType=unwrap(toType);
  if (AtomicInteger.class == toType) {
    return new AtomicInteger((Integer)convertToNumber(value,Integer.class));
  }
 else   if (AtomicLong.class == toType) {
    return new AtomicLong((Long)convertToNumber(value,Long.class));
  }
 else   if (Integer.class == toType) {
    return value.intValue();
  }
 else   if (Short.class == toType) {
    return value.shortValue();
  }
 else   if (Long.class == toType) {
    return value.longValue();
  }
 else   if (Float.class == toType) {
    return value.floatValue();
  }
 else   if (Double.class == toType) {
    return value.doubleValue();
  }
 else   if (Byte.class == toType) {
    return value.byteValue();
  }
 else   if (BigInteger.class == toType) {
    return new BigInteger(value.toString());
  }
 else   if (BigDecimal.class == toType) {
    return new BigDecimal(value.toString());
  }
 else {
    throw new Exception("Unable to convert number " + value + " to "+ toType);
  }
}
 

Example 26

From project aerogear-controller, under directory /src/test/java/org/jboss/aerogear/controller/.

Source file: TypeNameExtractorTest.java

  15 
vote

@Test public void shouldDecapitalizeSomeCharsUntilItFindsOneUppercased() throws NoSuchMethodException {
  Assert.assertEquals("urlClassLoader",extractor.nameFor(URLClassLoader.class));
  Assert.assertEquals("bigDecimal",extractor.nameFor(BigDecimal.class));
  Assert.assertEquals("string",extractor.nameFor(String.class));
  Assert.assertEquals("aClass",extractor.nameFor(AClass.class));
  Assert.assertEquals("url",extractor.nameFor(URL.class));
}
 

Example 27

From project android_8, under directory /src/com/google/gson/.

Source file: DefaultTypeAdapters.java

  15 
vote

private static ParameterizedTypeHandlerMap<JsonSerializer<?>> createDefaultSerializers(){
  ParameterizedTypeHandlerMap<JsonSerializer<?>> map=new ParameterizedTypeHandlerMap<JsonSerializer<?>>();
  map.register(URL.class,URL_TYPE_ADAPTER);
  map.register(URI.class,URI_TYPE_ADAPTER);
  map.register(UUID.class,UUUID_TYPE_ADAPTER);
  map.register(Locale.class,LOCALE_TYPE_ADAPTER);
  map.register(Date.class,DATE_TYPE_ADAPTER);
  map.register(java.sql.Date.class,JAVA_SQL_DATE_TYPE_ADAPTER);
  map.register(Timestamp.class,DATE_TYPE_ADAPTER);
  map.register(Time.class,TIME_TYPE_ADAPTER);
  map.register(Calendar.class,GREGORIAN_CALENDAR_TYPE_ADAPTER);
  map.register(GregorianCalendar.class,GREGORIAN_CALENDAR_TYPE_ADAPTER);
  map.register(BigDecimal.class,BIG_DECIMAL_TYPE_ADAPTER);
  map.register(BigInteger.class,BIG_INTEGER_TYPE_ADAPTER);
  map.register(BitSet.class,BIT_SET_ADAPTER);
  map.register(Boolean.class,BOOLEAN_TYPE_ADAPTER);
  map.register(boolean.class,BOOLEAN_TYPE_ADAPTER);
  map.register(Byte.class,BYTE_TYPE_ADAPTER);
  map.register(byte.class,BYTE_TYPE_ADAPTER);
  map.register(Character.class,CHARACTER_TYPE_ADAPTER);
  map.register(char.class,CHARACTER_TYPE_ADAPTER);
  map.register(Integer.class,INTEGER_TYPE_ADAPTER);
  map.register(int.class,INTEGER_TYPE_ADAPTER);
  map.register(Number.class,NUMBER_TYPE_ADAPTER);
  map.register(Short.class,SHORT_TYPE_ADAPTER);
  map.register(short.class,SHORT_TYPE_ADAPTER);
  map.register(String.class,STRING_TYPE_ADAPTER);
  map.register(StringBuilder.class,STRING_BUILDER_TYPE_ADAPTER);
  map.register(StringBuffer.class,STRING_BUFFER_TYPE_ADAPTER);
  map.makeUnmodifiable();
  return map;
}
 

Example 28

From project arquillian-examples, under directory /jpalab/src/main/java/com/acme/jpa/business/.

Source file: JavaPersistenceHelperBean.java

  15 
vote

/** 
 * Seed the database with sample records
 */
@Override public List<Record> seed(boolean clear){
  if (clear) {
    em.createQuery("delete from Record").executeUpdate();
  }
  List<Record> records=new ArrayList<Record>();
  Record a=new Record("Record A");
  LineItem l1=new LineItem(new BigDecimal(50));
  a.addLineItem(l1);
  em.persist(a);
  records.add(a);
  return records;
}
 

Example 29

From project beanvalidation-tck, under directory /tests/src/main/java/org/hibernate/beanvalidation/tck/tests/constraints/builtinconstraints/.

Source file: BuiltinConstraintsTest.java

  15 
vote

@Test @SpecAssertions({@SpecAssertion(section="6",id="a"),@SpecAssertion(section="6",id="g")}) public void testMinConstraint(){
  Validator validator=TestUtil.getValidatorUnderTest();
  MinDummyEntity dummy=new MinDummyEntity();
  Set<ConstraintViolation<MinDummyEntity>> constraintViolations=validator.validate(dummy);
  assertCorrectNumberOfViolations(constraintViolations,4);
  assertCorrectPropertyPaths(constraintViolations,"bytePrimitive","intPrimitive","longPrimitive","shortPrimitive");
  dummy.intPrimitive=101;
  dummy.longPrimitive=1001;
  dummy.bytePrimitive=111;
  dummy.shortPrimitive=142;
  dummy.intObject=Integer.valueOf("100");
  dummy.longObject=Long.valueOf("0");
  dummy.byteObject=Byte.parseByte("-1");
  dummy.shortObject=Short.parseShort("3");
  dummy.bigDecimal=BigDecimal.valueOf(100.9);
  dummy.bigInteger=BigInteger.valueOf(100);
  constraintViolations=validator.validate(dummy);
  assertCorrectNumberOfViolations(constraintViolations,6);
  assertCorrectPropertyPaths(constraintViolations,"byteObject","intObject","longObject","shortObject","bigDecimal","bigInteger");
  dummy.intObject=Integer.valueOf("101");
  dummy.longObject=Long.valueOf("12345");
  dummy.byteObject=Byte.parseByte("102");
  dummy.shortObject=Short.parseShort("111");
  dummy.bigDecimal=BigDecimal.valueOf(101.1);
  dummy.bigInteger=BigInteger.valueOf(101);
  constraintViolations=validator.validate(dummy);
  assertCorrectNumberOfViolations(constraintViolations,0);
}
 

Example 30

From project bonecp, under directory /bonecp/src/main/java/com/jolbox/bonecp/.

Source file: CallableStatementHandle.java

  15 
vote

/** 
 * {@inheritDoc}
 * @see java.sql.CallableStatement#getBigDecimal(int)
 */
public BigDecimal getBigDecimal(int parameterIndex) throws SQLException {
  checkClosed();
  try {
    return this.internalCallableStatement.getBigDecimal(parameterIndex);
  }
 catch (  SQLException e) {
    throw this.connectionHandle.markPossiblyBroken(e);
  }
}
 

Example 31

From project brix-cms, under directory /brix-wrapper/src/main/java/org/brixcms/jcr/api/wrapper/.

Source file: NodeWrapper.java

  15 
vote

public JcrProperty setProperty(final String name,final BigDecimal value){
  return executeCallback(new Callback<JcrProperty>(){
    public JcrProperty execute() throws Exception {
      return JcrProperty.Wrapper.wrap(getDelegate().setProperty(name,unwrap(value)),getJcrSession());
    }
  }
);
}
 

Example 32

From project bson4jackson, under directory /src/main/java/de/undercouch/bson4jackson/.

Source file: BsonGenerator.java

  15 
vote

@Override public void writeNumber(BigDecimal dec) throws IOException, JsonGenerationException {
  float f=dec.floatValue();
  if (!Float.isInfinite(f)) {
    writeNumber(f);
  }
 else {
    double d=dec.doubleValue();
    if (!Double.isInfinite(d)) {
      writeNumber(d);
    }
 else {
      writeString(dec.toString());
    }
  }
}