Android Open Source - WarehouseBarcode Area






From Project

Back to project page WarehouseBarcode.

License

The source code is released under:

MIT License

If you think the Android project WarehouseBarcode listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.hlgranite.warehousescanner;
//ww  w.j a  va  2 s .c  o m
import java.math.BigDecimal;

/**
 * Created by yeang-shing.then on 9/29/13.
 */
public class Area {

    /**
     * Square character.
     */
    public static final char SQUARE = '\u00B2';

    private long value;
    public long getValue() {
        return this.value;
    }

    public Area() {
        this.value = 0;
    }
    public Area(long area) {
        this.value = area;
    }

    /**
     * Add area.
     * @param area Value in mm.
     */
    public void add(long area) {
        this.value += area;
    }

    /**
     * Remove area
     * @param area Value in mm.
     */
    public void deduct(long area) {
        this.value -= area;
    }

    @Override
    public String toString() {
        // result = 16800000 / 1000000 will produce integer value 16.0
        // HACK: result = 16800000 / (double)1000000 will produce correct decimal place 16.8
        double result = value / (double)1000000;
        return round(result,2) + Unit.Meter + SQUARE;
    }

    /**
     * Convert area to square feet unit.
     * @return
     */
    public String toSquareFeet() {
        //see http://docs.oracle.com/javase/tutorial/java/data/numberformat.html
        //String.format("%.2f%n", output) + "ft" + SQUARE;
        double rate = 25.4*25.4*12*12;
        double result = value/rate;
        return round(result,2) + Unit.Feet + SQUARE;
    }

    /**
     * Round up value to desired decimal places.
     * See http://stackoverflow.com/questions/2808535/round-a-double-to-2-significant-figures-after-decimal-point
     * @param value
     * @param places
     * @return
     */
    public static double round(double value, int places) {
        if(places < 0) throw new IllegalArgumentException();
        BigDecimal bd = new BigDecimal(value);
        bd = bd.setScale(places, BigDecimal.ROUND_HALF_UP);
        return bd.doubleValue();
    }

}




Java Source Code List

com.hlgranite.Utils.java
com.hlgranite.warehousescanner.AboutActivity.java
com.hlgranite.warehousescanner.AreaComparator.java
com.hlgranite.warehousescanner.Area.java
com.hlgranite.warehousescanner.BalanceActivity.java
com.hlgranite.warehousescanner.Barcode.java
com.hlgranite.warehousescanner.CheckoutActivity.java
com.hlgranite.warehousescanner.Customer.java
com.hlgranite.warehousescanner.FusionManager.java
com.hlgranite.warehousescanner.HistoryActivity.java
com.hlgranite.warehousescanner.InventoryAdapter.java
com.hlgranite.warehousescanner.InventoryExpandableAdapter.java
com.hlgranite.warehousescanner.MainActivity.java
com.hlgranite.warehousescanner.ManualActivity.java
com.hlgranite.warehousescanner.QuantityComparator.java
com.hlgranite.warehousescanner.SettingsActivity.java
com.hlgranite.warehousescanner.ShipCode.java
com.hlgranite.warehousescanner.Shipment.java
com.hlgranite.warehousescanner.StockCodeComparator.java
com.hlgranite.warehousescanner.Stock.java
com.hlgranite.warehousescanner.Unit.java
com.hlgranite.warehousescanner.Warehouse.java
com.hlgranite.warehousescanner.WorkOrderAdapter.java
com.hlgranite.warehousescanner.WorkOrder.java