
package de.ivu.elect.business.datei.entity;

public enum BinaryUnit {

  BYTE("B", 1),

  KILOBYTE("kB", BYTE.toBytes() * 1000),
  MEGABYTE("MB", KILOBYTE.toBytes() * 1000),
  GIGABYTE("GB", MEGABYTE.toBytes() * 1000),

  KIBIBYTE("KiB", BYTE.toBytes() * 1024),
  MEBIBYTE("MiB", KIBIBYTE.toBytes() * 1024),
  GIBIBYTE("GiB", MEBIBYTE.toBytes() * 1024),

  ;

  private final String symbol;

  private final int bytes;

  private BinaryUnit(String symbol, int bytes) {
    this.symbol = symbol;
    this.bytes = bytes;
  }

  public String getSymbol() {
    return symbol;
  }

  int toBytes() {
    return bytes;
  }

  public static int bytesOf(int amount, BinaryUnit unit) {
    if (amount > 0 && unit != null) {
      return amount * unit.toBytes();
    }

    return 0;
  }
}
