-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #553 from raynigon/feature/add-binary-units
Implement binary units
- Loading branch information
Showing
12 changed files
with
257 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
unit-api-core/src/main/java/com/raynigon/unit/api/core/units/si/binary/Bit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.raynigon.unit.api.core.units.si.binary; | ||
|
||
import com.raynigon.unit.api.core.function.unitconverter.MultiplyConverter; | ||
import com.raynigon.unit.api.core.units.general.TransformedUnit; | ||
|
||
import javax.measure.quantity.Dimensionless; | ||
|
||
public class Bit extends TransformedUnit<Dimensionless> { | ||
public Bit() { | ||
super("bit", "Bit", new Byte(), MultiplyConverter.ofRational(1, 8)); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
unit-api-core/src/main/java/com/raynigon/unit/api/core/units/si/binary/Byte.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.raynigon.unit.api.core.units.si.binary; | ||
|
||
import com.raynigon.unit.api.core.units.general.BaseUnit; | ||
import com.raynigon.unit.api.core.units.general.UnitDimension; | ||
import com.raynigon.unit.api.core.units.si.SISystem; | ||
|
||
import javax.measure.quantity.Dimensionless; | ||
|
||
public class Byte extends BaseUnit<Dimensionless> { | ||
public Byte() { | ||
super(SISystem.ID, "B", "Byte", Dimensionless.class, UnitDimension.NONE); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
unit-api-core/src/main/java/com/raynigon/unit/api/core/units/si/binary/Gibibyte.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.raynigon.unit.api.core.units.si.binary; | ||
|
||
import com.raynigon.unit.api.core.units.general.ScaledUnit; | ||
|
||
import javax.measure.BinaryPrefix; | ||
import javax.measure.quantity.Dimensionless; | ||
|
||
public class Gibibyte extends ScaledUnit<Dimensionless> { | ||
public Gibibyte() { | ||
super(BinaryPrefix.GIBI, new Byte(), "Gibibyte"); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
unit-api-core/src/main/java/com/raynigon/unit/api/core/units/si/binary/Gigabyte.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.raynigon.unit.api.core.units.si.binary; | ||
|
||
import com.raynigon.unit.api.core.units.general.ScaledUnit; | ||
|
||
import javax.measure.MetricPrefix; | ||
import javax.measure.quantity.Dimensionless; | ||
|
||
public class Gigabyte extends ScaledUnit<Dimensionless> { | ||
public Gigabyte() { | ||
super(MetricPrefix.GIGA, new Byte(), "Gigabyte"); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
unit-api-core/src/main/java/com/raynigon/unit/api/core/units/si/binary/Kibibyte.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.raynigon.unit.api.core.units.si.binary; | ||
|
||
import com.raynigon.unit.api.core.units.general.ScaledUnit; | ||
|
||
import javax.measure.BinaryPrefix; | ||
import javax.measure.quantity.Dimensionless; | ||
|
||
public class Kibibyte extends ScaledUnit<Dimensionless> { | ||
public Kibibyte() { | ||
super(BinaryPrefix.KIBI, new Byte(), "Kibibyte"); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
unit-api-core/src/main/java/com/raynigon/unit/api/core/units/si/binary/Kilobyte.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.raynigon.unit.api.core.units.si.binary; | ||
|
||
import com.raynigon.unit.api.core.units.general.ScaledUnit; | ||
|
||
import javax.measure.MetricPrefix; | ||
import javax.measure.quantity.Dimensionless; | ||
|
||
public class Kilobyte extends ScaledUnit<Dimensionless> { | ||
public Kilobyte() { | ||
super(MetricPrefix.KILO, new Byte(), "Kilobyte"); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
unit-api-core/src/main/java/com/raynigon/unit/api/core/units/si/binary/Mebibyte.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.raynigon.unit.api.core.units.si.binary; | ||
|
||
import com.raynigon.unit.api.core.units.general.ScaledUnit; | ||
|
||
import javax.measure.BinaryPrefix; | ||
import javax.measure.quantity.Dimensionless; | ||
|
||
public class Mebibyte extends ScaledUnit<Dimensionless> { | ||
public Mebibyte() { | ||
super(BinaryPrefix.MEBI, new Byte(), "Mebibyte"); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
unit-api-core/src/main/java/com/raynigon/unit/api/core/units/si/binary/Megabyte.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.raynigon.unit.api.core.units.si.binary; | ||
|
||
import com.raynigon.unit.api.core.units.general.ScaledUnit; | ||
|
||
import javax.measure.MetricPrefix; | ||
import javax.measure.quantity.Dimensionless; | ||
|
||
public class Megabyte extends ScaledUnit<Dimensionless> { | ||
public Megabyte() { | ||
super(MetricPrefix.MEGA, new Byte(), "Megabyte"); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
unit-api-core/src/main/java/com/raynigon/unit/api/core/units/si/binary/Tebibyte.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.raynigon.unit.api.core.units.si.binary; | ||
|
||
import com.raynigon.unit.api.core.units.general.ScaledUnit; | ||
|
||
import javax.measure.BinaryPrefix; | ||
import javax.measure.quantity.Dimensionless; | ||
|
||
public class Tebibyte extends ScaledUnit<Dimensionless> { | ||
public Tebibyte() { | ||
super(BinaryPrefix.TEBI, new Byte(), "Tebibyte"); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
unit-api-core/src/main/java/com/raynigon/unit/api/core/units/si/binary/Terabyte.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.raynigon.unit.api.core.units.si.binary; | ||
|
||
import com.raynigon.unit.api.core.units.general.ScaledUnit; | ||
|
||
import javax.measure.MetricPrefix; | ||
import javax.measure.quantity.Dimensionless; | ||
|
||
public class Terabyte extends ScaledUnit<Dimensionless> { | ||
public Terabyte() { | ||
super(MetricPrefix.TERA, new Byte(), "Terabyte"); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
unit-api-core/src/test/groovy/com/raynigon/unit/api/core/units/si/binary/ByteSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.raynigon.unit.api.core.units.si.binary | ||
|
||
import com.raynigon.unit.api.core.units.si.SISystemUnitsConstants | ||
import spock.lang.Specification | ||
|
||
class ByteSpec extends Specification { | ||
def "Bytes are 8 Bits"() { | ||
given: | ||
def bytes = SISystemUnitsConstants.Bytes(2) | ||
|
||
when: | ||
def bits = bytes.to(SISystemUnitsConstants.Bit) | ||
|
||
then: | ||
bytes.value * 8 == bits.value | ||
} | ||
|
||
def "Kilobytes and Kibibytes are different"() { | ||
when: | ||
def kilo = SISystemUnitsConstants.Kilobytes(2) | ||
def kibi = SISystemUnitsConstants.Kibibytes(2) | ||
|
||
then: | ||
kilo < kibi | ||
} | ||
} |