Bandwidth.java 974 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package util;
  2. import exceptions.BandwidthException;
  3. public class Bandwidth {
  4. public String task;
  5. public long bandwidth;
  6. public Bandwidth() {
  7. task = "";
  8. bandwidth = 0;
  9. }
  10. public Bandwidth(String t) {
  11. task = t;
  12. bandwidth = 0;
  13. }
  14. public Bandwidth(Bandwidth b) {
  15. task = b.task;
  16. bandwidth = b.bandwidth;
  17. }
  18. public void reset() {
  19. bandwidth = 0;
  20. }
  21. public void add(long n) {
  22. bandwidth += n;
  23. }
  24. public Bandwidth addAndReturn(Bandwidth b) {
  25. if (!task.equals(b.task))
  26. throw new BandwidthException("Task: " + task + " != " + b.task);
  27. Bandwidth total = new Bandwidth(task);
  28. total.bandwidth = bandwidth + b.bandwidth;
  29. return total;
  30. }
  31. public void add(Bandwidth b) {
  32. if (!task.equals(b.task))
  33. throw new BandwidthException("Task: " + task + " != " + b.task);
  34. bandwidth += b.bandwidth;
  35. }
  36. public String noPreToString() {
  37. return "" + bandwidth;
  38. }
  39. @Override
  40. public String toString() {
  41. return task + "(bytes): " + bandwidth;
  42. }
  43. }