blob: d49ed7b566d137a307e2af4d7d8706ac2bc0fe40 [file] [log] [blame]
HIGUCHI Yuta501c4652015-10-29 14:21:48 -07001package org.onlab.util;
2
3import com.google.common.annotations.Beta;
4
5/**
6 * Data rate unit.
7 */
8@Beta
9public enum DataRateUnit {
10 /**
11 * Bit per second.
12 */
13 BPS(1L),
14 /**
15 * Kilobit per second.
16 * (Decimal/SI)
17 */
18 KBPS(1_000L),
19 /**
20 * Megabit per second.
21 * (Decimal/SI)
22 */
23 MBPS(1_000_000L),
24 /**
25 * Gigabit per second.
26 * (Decimal/SI)
27 */
28 GBPS(1_000_000_000L);
29
30 private final long multiplier;
31
32 DataRateUnit(long multiplier) {
33 this.multiplier = multiplier;
34 }
35
36 /**
37 * Returns the multiplier to use, when converting value of this unit to bps.
38 *
39 * @return multiplier
40 */
41 public long multiplier() {
42 return multiplier;
43 }
44
45 /**
46 * Converts given value in this unit to bits per seconds.
47 *
48 * @param v data rate value
49 * @return {@code v} in bits per seconds
50 */
51 public long toBitsPerSecond(long v) {
52 return v * multiplier;
53 }
54
55 /**
56 * Converts given value in this unit to bits per seconds.
57 *
58 * @param v data rate value
59 * @return {@code v} in bits per seconds
60 */
61 public double toBitsPerSecond(double v) {
62 return v * multiplier;
63 }
64}