Package java.math

Examples of java.math.BigDecimal$StringBuilderHelper


    priceSpinnerModel.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          controller.removePropertyChangeListener(FurnitureController.Property.PRICE, priceChangeListener);
          Object value = priceSpinnerModel.getValue();
          controller.setPrice(value != null
              ? new BigDecimal((Float)value).setScale(2, BigDecimal.ROUND_HALF_UP)
              : (BigDecimal)value);
          controller.addPropertyChangeListener(FurnitureController.Property.PRICE, priceChangeListener);
        }
      });

    // Create VAT % label and its spinner bound to VALUE_ADDED_TAX_PERCENTAGE controller property
    this.valueAddedTaxPercentageLabel = new JLabel(SwingTools.getLocalizedLabelText(preferences,
        FurniturePanel.class, "valueAddedTaxPercentageLabel.text"));
    final NullableSpinner.NullableSpinnerNumberModel valueAddedTaxPercentageSpinnerModel =
        new NullableSpinner.NullableSpinnerNumberModel(0, 0, 100f, 0.1f);
    this.valueAddedTaxPercentageSpinner = new AutoCommitSpinner(valueAddedTaxPercentageSpinnerModel);
    valueAddedTaxPercentageSpinnerModel.setNullable(controller.getValueAddedTaxPercentage() == null);
    valueAddedTaxPercentageSpinnerModel.setValue(controller.getValueAddedTaxPercentage() == null
        ? null
        : controller.getValueAddedTaxPercentage().floatValue() * 100);
    final PropertyChangeListener valueAddedTaxPercentageChangeListener = new PropertyChangeListener() {
      public void propertyChange(PropertyChangeEvent ev) {
        valueAddedTaxPercentageSpinnerModel.setNullable(ev.getNewValue() == null);
        valueAddedTaxPercentageSpinnerModel.setValue(ev.getNewValue() == null
            ? null
            : ((Float)ev.getNewValue()) * 100);
      }
    };
    controller.addPropertyChangeListener(FurnitureController.Property.VALUE_ADDED_TAX_PERCENTAGE, valueAddedTaxPercentageChangeListener);
    valueAddedTaxPercentageSpinnerModel.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          controller.removePropertyChangeListener(FurnitureController.Property.VALUE_ADDED_TAX_PERCENTAGE, valueAddedTaxPercentageChangeListener);
          Object value = valueAddedTaxPercentageSpinnerModel.getValue();
          controller.setValueAddedTaxPercentage(value != null
              ? new BigDecimal((Float)value / 100).setScale(3, BigDecimal.ROUND_HALF_UP)
              : (BigDecimal)value);
          controller.addPropertyChangeListener(FurnitureController.Property.VALUE_ADDED_TAX_PERCENTAGE, valueAddedTaxPercentageChangeListener);
        }
      });
   
View Full Code Here


      return new DefaultTableCellRenderer() {
          @Override
          public Component getTableCellRendererComponent(JTable table,
               Object value, boolean isSelected, boolean hasFocus,
               int row, int column) {
            BigDecimal valueAddedTaxPercentage = ((CatalogPieceOfFurniture)value).getValueAddedTaxPercentage();
            if (valueAddedTaxPercentage != null) {
              NumberFormat percentInstance = DecimalFormat.getPercentInstance();
              percentInstance.setMinimumFractionDigits(valueAddedTaxPercentage.scale() - 2);
              value = percentInstance.format(valueAddedTaxPercentage);
            } else {
              value = "";
            }
            setHorizontalAlignment(JLabel.RIGHT);
View Full Code Here

          }
        }
      }
      setCreator(creator);

      BigDecimal price = firstPiece.getPrice();
      if (price != null) {
        for (int i = 1; i < this.modifiedFurniture.size(); i++) {
          if (!price.equals(this.modifiedFurniture.get(i).getPrice())) {
            price = null;
            break;
          }
        }
      }
      setPrice(price);

      BigDecimal valueAddedTaxPercentage = firstPiece.getValueAddedTaxPercentage();
      if (valueAddedTaxPercentage != null) {
        for (int i = 1; i < this.modifiedFurniture.size(); i++) {
          if (!valueAddedTaxPercentage.equals(this.modifiedFurniture.get(i).getValueAddedTaxPercentage())) {
            valueAddedTaxPercentage = null;
            break;
          }
        }
      }
View Full Code Here

  /**
   * Sets the edited price.
   */
  public void setPrice(BigDecimal price) {
    if (price != this.price) {
      BigDecimal oldPrice = this.price;
      this.price = price;
      this.propertyChangeSupport.firePropertyChange(Property.ICON.name(), oldPrice, price);
    }
  }
View Full Code Here

  /**
   * Sets the edited value added tax percentage.
   */
  public void setValueAddedTaxPercentage(BigDecimal valueAddedTaxPercentage) {
    if (valueAddedTaxPercentage != this.valueAddedTaxPercentage) {
      BigDecimal oldValueAddedTaxPercentage = this.valueAddedTaxPercentage;
      this.valueAddedTaxPercentage = valueAddedTaxPercentage;
      this.propertyChangeSupport.firePropertyChange(Property.VALUE_ADDED_TAX_PERCENTAGE.name(), oldValueAddedTaxPercentage, valueAddedTaxPercentage);
    }
  }
View Full Code Here

      Boolean resizable = getResizable();
      Boolean deformable = getDeformable();
      Boolean doorOrWindow = getDoorOrWindow();
      float [][] modelRotation = getModelRotation();
      String creator = getCreator();
      BigDecimal price = getPrice();
      BigDecimal valueAddedTaxPercentage = getValueAddedTaxPercentage();
      boolean defaultFurnitureLanguage = FurnitureLibrary.DEFAULT_LANGUAGE.equals(this.furnitureLanguageController.getFurnitureLangauge());
     
      // Apply modification
      int piecesCount = this.modifiedFurniture.size();
      for (CatalogPieceOfFurniture piece : this.modifiedFurniture) {
        int index = this.furnitureLibrary.getPieceOfFurnitureIndex(piece);
        // Retrieve localized data
        Map<String, Object> localizedNames = new HashMap<String, Object>();
        Map<String, Object> localizedDescriptions = new HashMap<String, Object>();
        Map<String, Object> localizedCategories = new HashMap<String, Object>();
        for (String language : this.furnitureLibrary.getSupportedLanguages()) {
          Object pieceName = this.furnitureLibrary.getPieceOfFurnitureLocalizedData(
              piece, language, FurnitureLibrary.FURNITURE_NAME_PROPERTY);
          if (pieceName != null) {
            localizedNames.put(language, pieceName);
          }
          Object pieceDescription = this.furnitureLibrary.getPieceOfFurnitureLocalizedData(
              piece, language, FurnitureLibrary.FURNITURE_DESCRIPTION_PROPERTY);
          if (pieceDescription != null) {
            localizedDescriptions.put(language, pieceDescription);
          }
          Object categoryName = this.furnitureLibrary.getPieceOfFurnitureLocalizedData(
              piece, language, FurnitureLibrary.FURNITURE_CATEGORY_PROPERTY);
          if (categoryName != null) {
            localizedCategories.put(language, categoryName);
          }
        }
        this.furnitureLibrary.deletePieceOfFurniture(piece);
       
        String pieceId = id != null || piecesCount == 1 ? id : piece.getId();
        String pieceName = name != null && defaultFurnitureLanguage ? name : piece.getName();
        String pieceDescription = description != null && defaultFurnitureLanguage ? description : piece.getDescription();
        FurnitureCategory pieceCategory = category != null && defaultFurnitureLanguage ? category : piece.getCategory();
        Content pieceModel = model != null ? model : piece.getModel();
        Content pieceIcon = icon != null ? icon : piece.getIcon();
        float pieceWidth = width != null ? width : piece.getWidth();
        float pieceDepth = depth != null ? depth : piece.getDepth();
        float pieceHeight = height != null ? height : piece.getHeight();
        float pieceElevation = elevation != null ? elevation : piece.getElevation();
        boolean pieceMovable = movable != null ? movable : piece.isMovable();
        float [][] pieceModelRotation = modelRotation != null ? modelRotation : piece.getModelRotation();
        String pieceCreator = creator != null || piecesCount == 1 ? creator : piece.getCreator();
        boolean pieceResizable = resizable != null ? resizable : piece.isResizable();
        boolean pieceDeformable = deformable != null ? deformable : piece.isDeformable();
        BigDecimal piecePrice = price != null ? price : piece.getPrice();
        BigDecimal pieceValueAddedTaxPercentage = valueAddedTaxPercentage != null
            ? valueAddedTaxPercentage : piece.getValueAddedTaxPercentage();
       
        if (piece instanceof CatalogDoorOrWindow) {
          CatalogDoorOrWindow opening = (CatalogDoorOrWindow)piece;
          piece = new CatalogDoorOrWindow(pieceId, pieceName, pieceDescription,
View Full Code Here

                    case Types.DOUBLE:
                        return new Double(resultSet.getDouble(index));

                    case Types.DECIMAL:
                    case Types.NUMERIC:
                        BigDecimal num = resultSet.getBigDecimal(index);
                        if (num == null) {
                            break;
                        }

                        if (num.scale() > 0) {
                            return new Double(num.doubleValue());
                        } else {
                            return new Long(num.longValue());
                        }

                    case Types.VARBINARY:
                    case Types.BINARY:
                        return resultSet.getString(index);
View Full Code Here

      // This array list will produce the problem
      // Remove it and the test case will succeed
      ArrayList<String> genericList = new ArrayList<String>();
      genericList.add("something");
      entry.getMap().put("D", genericList);
      entry.getMap().put("E", new BigDecimal("0.00"));
    }

    DozerExampleEntry mapped = dozerBeanMapper.map(entry, DozerExampleEntry.class);

    // All the fields which are visited/mapped before the
    // ArrayList are mapped successfully and to correct type
    assertEquals("foobar", mapped.getMap().get("A"));
    assertEquals(new Date(0), mapped.getMap().get("B"));
    assertEquals(Boolean.TRUE, mapped.getMap().get("C"));
    ArrayList<String> expectedList = new ArrayList<String>();
    expectedList.add("something");
    assertEquals(expectedList, mapped.getMap().get("D"));
    assertNotSame(expectedList, mapped.getMap().get("D"));

    // The BigDecimal was visited _after_ the ArrayList
    // and thus converted to String due to the bug.
    assertEquals(new BigDecimal("0.00"), mapped.getMap().get("E"));
  }
View Full Code Here

    int[] intArray = { 1, 1 };
    Integer[] integerArray = { new Integer(1), new Integer(1) };
    custom.setAnArray(intArray);
    custom.setArrayForLists(integerArray);
    custom.setBigDecimalToInt(new BigDecimal(1));
    custom.setIntToBigDecimal(1);
    Date date = new Date();
    custom.setDate(date);
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTime(date);
View Full Code Here

  public void shouldMapPrimitiveTypes() throws Exception {
    Source source = new Source();
    source.file = "a";
    source.url = "http://a";
    source.type = "java.lang.String";
    source.bigDecimal = new BigDecimal("1");
    source.myDouble = new Double("1");

    Destination result = mapper.map(source, Destination.class);

    assertThat(result.file, equalTo(new File("a")));
    assertThat(result.url, equalTo(new URL("http://a")));
    assertThat(result.type, sameInstance(String.class));
    assertThat(result.bigDecimal, equalTo(new Double("1")));
    assertThat(result.myDouble, equalTo(new BigDecimal("1.0")));
  }
View Full Code Here

TOP

Related Classes of java.math.BigDecimal$StringBuilderHelper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.