Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) cedarsoft GmbH. Licensed under the GNU General Public License version 3 (the "License") with Classpath Exception; you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.cedarsoft.org/gpl3ce (GPL 3 with Classpath Exception) This code is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 3 only, as published by the Free Software Foundation. cedarsoft GmbH designates this particular file as subject to the "Classpath" exception as provided by cedarsoft GmbH in the LICENSE file that accompanied this code. This code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License version 3 for more details (a copy is included in the LICENSE file that accompanied this code). You should have received a copy of the GNU General Public License version 3 along with this work; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. Please contact cedarsoft GmbH, 72810 Gomaringen, Germany, or visit www.cedarsoft.com if you need additional information or have any questions.
 
 
 package com.cedarsoft.business;
 
 import  org.jetbrains.annotations.NonNls;
 import  org.jetbrains.annotations.NotNull;
 
Simple money implementation that is backed up by a long.
 
 public final class Money extends AbstractMoney {
   @NotNull
   @NonNls
   public static final String PROPERTY_NEGATIVE = "negative";

  
Represents a money with the value of 0
 
   @NotNull
   public static final Money ZERO = new Money();

  
A very big value for money. Can be used as upper border
 
   @NotNull
   public static final Money BIG = Money.getMoneyForValue. );
   @NotNull
   public static final Money SMALL = Money.getMoneyForValue. );

  
This method expects internal value. This depends on *SCALE

Parameters:
value the value of value
Returns:
the money
 
   @NotNull
   public static Money getMoneyForValuelong value ) {
     return new Moneyvalue );
   }

  
Internal representation: Always an integer, scaled so that unity is the smallest measurable quantity
 
   protected final long value;//  Amount in monetary units * SCALE
 
  

Parameters:
amount the amount
 
   public Moneyfinal double amount ) {
     //    value = Math.round( amount * SCALE );
      = ( long ) ( amount *  );
   }
 
   public Money( @NotNull BigDecimal bigDecimal ) {
     thisbigDecimal.multiplynew BigDecimal ) ).longValue() );
   }

  
Creates a new money instance with the given amount as cents

Parameters:
value the *CENTS*
 
   private Moneyfinal long value ) {
    this. = value;
  }

  
Creates a new money object with an amount of "0"
  public Money() {
     = 0;
  }

  
Copy constructor

Parameters:
value the money object the value is copied from
  public Money( @NotNull final AbstractMoney value ) {
    this. = value.getValue();
  }

  
Returns the value. The value depends on the scale! This method is for internal usage only.

Returns:
the value (depending on the scale)
  public long getValue() {
    return ;
  }

  
Returns a money object with the absolute value

Returns:
a new money object with the absolute value
  @NotNull
  public Money abs() {
    if ( getValue() < 0 ) {
      return Money.getMoneyForValue( - );
    } else {
      return this;
    }
  }

  
Adds the given amount

Parameters:
money the amount that is added
Returns:
the sum
  @NotNull
  public Money plus( @NotNull AbstractMoney money ) {
    return Money.getMoneyForValue + money.getValue() );
  }

  
Adds the given amount

Parameters:
money the money that is added
Returns:
the sum
  @NotNull
  public Money plusdouble money ) {
    return Money.getMoneyForValue( ( long ) (  + money *  ) );
  }

  
Multiplies with the given multiplicator

Parameters:
multiplicator the multiplicator
Returns:
the new amount
  @NotNull
  public Money multiplydouble multiplicator ) {
    return Money.getMoneyForValue( ( long ) (  * multiplicator ) );
  }
  @NotNull
  public Money dividedouble divisor ) {
    return Money.getMoneyForValue( ( long ) (  / divisor ) );
  }
  @NotNull
  public Money minusdouble money ) {
    return Money.getMoneyForValue( ( long ) (  - money *  ) );
  }
  @NotNull
  public Money minus( @NotNull AbstractMoney money ) {
    return Money.getMoneyForValue - money.getValue() );
  }

  
Returns the negative amount

Returns:
the negative amount
  @NotNull
  public Money negative() {
    return Money.getMoneyForValue( - );
  }
  @NotNull
  public Money getNegative() {
    return negative();
  }

  
Returns a nice representation

Returns:
the nice representation
  @NotNull
  @NonNls
  public String getRepresentation() {
    NumberFormat format = NumberFormat.getNumberInstance();
    format.setMaximumFractionDigits( 2 );
    format.setMinimumFractionDigits( 2 );
    return format.formatgetEstimatedValue() ) + ' ' + Currency.getInstance( Locale.getDefault() ).getSymbol( Locale.getDefault() );
  }
  public String toString() {
    return getRepresentation();
  }

  
Returns whether the amount is greater than 0

Returns:
whether the amount is greater than 0
  public boolean isPositive() {
    return  > 0;
  }
New to GrepCode? Check out our FAQ X