diff --git a/btypes_big_integer/src/main/java/de/hhu/stups/btypes/BBoolean.java b/btypes_big_integer/src/main/java/de/hhu/stups/btypes/BBoolean.java index fffbbd67954afcc50ebf289915c74258ec55f669..18cf55a2a6c4ddc984f01c9f762a3f9fc728b447 100755 --- a/btypes_big_integer/src/main/java/de/hhu/stups/btypes/BBoolean.java +++ b/btypes_big_integer/src/main/java/de/hhu/stups/btypes/BBoolean.java @@ -1,86 +1,70 @@ package de.hhu.stups.btypes; -import java.util.Objects; +public final class BBoolean implements BObject { -public class BBoolean implements BObject { + public static final BBoolean TRUE = new BBoolean(true); + public static final BBoolean FALSE = new BBoolean(false); private final boolean value; - public static boolean parseBoolean(String s) { - return Boolean.parseBoolean(s); - } - - public static String toString(boolean b) { - return Boolean.toString(b); - } - - public static Boolean valueOf(boolean b) { - return Boolean.valueOf(b); - } - - public int compareTo(Boolean b) { - return b.compareTo(value); + public static BBoolean of(boolean value) { + if (value) { + return TRUE; + } else { + return FALSE; + } } - public static Boolean valueOf(String s) { - return Boolean.valueOf(s); + public static BBoolean of(String value) { + return of(Boolean.parseBoolean(value)); } - public static int compare(boolean x, boolean y) { - return Boolean.compare(x, y); + public BBoolean(boolean value) { + this.value = value; } - public static boolean getBoolean(String name) { - return Boolean.getBoolean(name); + public BBoolean(String s) { + this(Boolean.parseBoolean(s)); } public boolean booleanValue() { - return value; + return this.value; } @Override - public String toString() { - return String.valueOf(value); + public boolean equals(Object o) { + if (this == o) { + return true; + } else if (!(o instanceof BBoolean)) { + return false; + } else { + return this.value == ((BBoolean) o).value; + } } @Override public int hashCode() { - return Objects.hash(value); + return Boolean.hashCode(this.value); } @Override - public boolean equals(Object obj) { - if(!(obj instanceof BBoolean)) { - return false; - } - if(((BBoolean) obj).booleanValue() != value) { - return false; - } - return true; - } - - public BBoolean(boolean value) { - this.value = value; - } - - public BBoolean(String s) { - this.value = Boolean.parseBoolean(s); + public String toString() { + return String.valueOf(this.value); } /* groovy operator overloading support */ - @SuppressWarnings("rawtypes") - Object asType(Class clazz) { - if (clazz == new BBoolean(true).getClass()) { - return this.booleanValue(); + Object asType(Class<?> clazz) { + if (clazz == BBoolean.class) { + return this; } - return this; + return clazz.cast(this.value); } public BBoolean or(BBoolean other) { return new BBoolean(this.booleanValue() || other.booleanValue()); } - public BBoolean or(Boolean other) { + public BBoolean or(boolean other) { return new BBoolean(this.booleanValue() || other); } @@ -88,7 +72,7 @@ public class BBoolean implements BObject { return new BBoolean(this.booleanValue() ^ other.booleanValue()); } - public BBoolean xor(Boolean other) { + public BBoolean xor(boolean other) { return new BBoolean(this.booleanValue() ^ other); } @@ -96,7 +80,7 @@ public class BBoolean implements BObject { return new BBoolean(this.booleanValue() && other.booleanValue()); } - public BBoolean and(Boolean other) { + public BBoolean and(boolean other) { return new BBoolean(this.booleanValue() && other); } @@ -108,31 +92,31 @@ public class BBoolean implements BObject { return this.not().or(other); } - public BBoolean implies(Boolean other) { + public BBoolean implies(boolean other) { return new BBoolean(this.not().booleanValue() || other); } public BBoolean equivalent(BBoolean other) { - return this.implies(other).and(other.implies(this)); + return new BBoolean(this.booleanValue() == other.booleanValue()); } - public BBoolean equivalent(Boolean other) { + public BBoolean equivalent(boolean other) { return new BBoolean(this.booleanValue() == other); } public BBoolean equal(BBoolean other) { - return new BBoolean(this.value == other.value); + return new BBoolean(this.booleanValue() == other.booleanValue()); } public BBoolean unequal(BBoolean other) { - return new BBoolean(this.value != other.value); + return new BBoolean(this.booleanValue() != other.booleanValue()); } public BBoolean isBoolean() { - return new BBoolean(true); + return TRUE; } public BBoolean isNotBoolean() { - return new BBoolean(false); + return FALSE; } } diff --git a/btypes_big_integer/src/main/java/de/hhu/stups/btypes/BUtils.java b/btypes_big_integer/src/main/java/de/hhu/stups/btypes/BUtils.java index e8e4afa9fb61207af3caa8d2501abc80a4655fae..f86498f97d544f7bb74a7b45a53a2c071129db0d 100644 --- a/btypes_big_integer/src/main/java/de/hhu/stups/btypes/BUtils.java +++ b/btypes_big_integer/src/main/java/de/hhu/stups/btypes/BUtils.java @@ -1,8 +1,9 @@ package de.hhu.stups.btypes; +public final class BUtils { -public class BUtils { - - public static final BSet<BBoolean> BOOL = new BSet<>(new BBoolean(true), new BBoolean(false)); + public static final BSet<BBoolean> BOOL = new BSet<>(BBoolean.TRUE, BBoolean.FALSE); + private BUtils() { + } } diff --git a/btypes_primitives/src/main/java/de/hhu/stups/btypes/BBoolean.java b/btypes_primitives/src/main/java/de/hhu/stups/btypes/BBoolean.java index fffbbd67954afcc50ebf289915c74258ec55f669..18cf55a2a6c4ddc984f01c9f762a3f9fc728b447 100755 --- a/btypes_primitives/src/main/java/de/hhu/stups/btypes/BBoolean.java +++ b/btypes_primitives/src/main/java/de/hhu/stups/btypes/BBoolean.java @@ -1,86 +1,70 @@ package de.hhu.stups.btypes; -import java.util.Objects; +public final class BBoolean implements BObject { -public class BBoolean implements BObject { + public static final BBoolean TRUE = new BBoolean(true); + public static final BBoolean FALSE = new BBoolean(false); private final boolean value; - public static boolean parseBoolean(String s) { - return Boolean.parseBoolean(s); - } - - public static String toString(boolean b) { - return Boolean.toString(b); - } - - public static Boolean valueOf(boolean b) { - return Boolean.valueOf(b); - } - - public int compareTo(Boolean b) { - return b.compareTo(value); + public static BBoolean of(boolean value) { + if (value) { + return TRUE; + } else { + return FALSE; + } } - public static Boolean valueOf(String s) { - return Boolean.valueOf(s); + public static BBoolean of(String value) { + return of(Boolean.parseBoolean(value)); } - public static int compare(boolean x, boolean y) { - return Boolean.compare(x, y); + public BBoolean(boolean value) { + this.value = value; } - public static boolean getBoolean(String name) { - return Boolean.getBoolean(name); + public BBoolean(String s) { + this(Boolean.parseBoolean(s)); } public boolean booleanValue() { - return value; + return this.value; } @Override - public String toString() { - return String.valueOf(value); + public boolean equals(Object o) { + if (this == o) { + return true; + } else if (!(o instanceof BBoolean)) { + return false; + } else { + return this.value == ((BBoolean) o).value; + } } @Override public int hashCode() { - return Objects.hash(value); + return Boolean.hashCode(this.value); } @Override - public boolean equals(Object obj) { - if(!(obj instanceof BBoolean)) { - return false; - } - if(((BBoolean) obj).booleanValue() != value) { - return false; - } - return true; - } - - public BBoolean(boolean value) { - this.value = value; - } - - public BBoolean(String s) { - this.value = Boolean.parseBoolean(s); + public String toString() { + return String.valueOf(this.value); } /* groovy operator overloading support */ - @SuppressWarnings("rawtypes") - Object asType(Class clazz) { - if (clazz == new BBoolean(true).getClass()) { - return this.booleanValue(); + Object asType(Class<?> clazz) { + if (clazz == BBoolean.class) { + return this; } - return this; + return clazz.cast(this.value); } public BBoolean or(BBoolean other) { return new BBoolean(this.booleanValue() || other.booleanValue()); } - public BBoolean or(Boolean other) { + public BBoolean or(boolean other) { return new BBoolean(this.booleanValue() || other); } @@ -88,7 +72,7 @@ public class BBoolean implements BObject { return new BBoolean(this.booleanValue() ^ other.booleanValue()); } - public BBoolean xor(Boolean other) { + public BBoolean xor(boolean other) { return new BBoolean(this.booleanValue() ^ other); } @@ -96,7 +80,7 @@ public class BBoolean implements BObject { return new BBoolean(this.booleanValue() && other.booleanValue()); } - public BBoolean and(Boolean other) { + public BBoolean and(boolean other) { return new BBoolean(this.booleanValue() && other); } @@ -108,31 +92,31 @@ public class BBoolean implements BObject { return this.not().or(other); } - public BBoolean implies(Boolean other) { + public BBoolean implies(boolean other) { return new BBoolean(this.not().booleanValue() || other); } public BBoolean equivalent(BBoolean other) { - return this.implies(other).and(other.implies(this)); + return new BBoolean(this.booleanValue() == other.booleanValue()); } - public BBoolean equivalent(Boolean other) { + public BBoolean equivalent(boolean other) { return new BBoolean(this.booleanValue() == other); } public BBoolean equal(BBoolean other) { - return new BBoolean(this.value == other.value); + return new BBoolean(this.booleanValue() == other.booleanValue()); } public BBoolean unequal(BBoolean other) { - return new BBoolean(this.value != other.value); + return new BBoolean(this.booleanValue() != other.booleanValue()); } public BBoolean isBoolean() { - return new BBoolean(true); + return TRUE; } public BBoolean isNotBoolean() { - return new BBoolean(false); + return FALSE; } } diff --git a/btypes_primitives/src/main/java/de/hhu/stups/btypes/BUtils.java b/btypes_primitives/src/main/java/de/hhu/stups/btypes/BUtils.java index e8e4afa9fb61207af3caa8d2501abc80a4655fae..f86498f97d544f7bb74a7b45a53a2c071129db0d 100644 --- a/btypes_primitives/src/main/java/de/hhu/stups/btypes/BUtils.java +++ b/btypes_primitives/src/main/java/de/hhu/stups/btypes/BUtils.java @@ -1,8 +1,9 @@ package de.hhu.stups.btypes; +public final class BUtils { -public class BUtils { - - public static final BSet<BBoolean> BOOL = new BSet<>(new BBoolean(true), new BBoolean(false)); + public static final BSet<BBoolean> BOOL = new BSet<>(BBoolean.TRUE, BBoolean.FALSE); + private BUtils() { + } }