Skip to content
Snippets Groups Projects
Verified Commit 4eb298b5 authored by Miles Vella's avatar Miles Vella
Browse files

cleanup boolean

parent bc924438
Branches
No related tags found
1 merge request!66Refactor of Java BTypes
package de.hhu.stups.btypes; 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; private final boolean value;
public static boolean parseBoolean(String s) { public static BBoolean of(boolean value) {
return Boolean.parseBoolean(s); if (value) {
return TRUE;
} else {
return FALSE;
} }
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) { public static BBoolean of(String value) {
return b.compareTo(value); return of(Boolean.parseBoolean(value));
} }
public static Boolean valueOf(String s) { public BBoolean(boolean value) {
return Boolean.valueOf(s); this.value = value;
}
public static int compare(boolean x, boolean y) {
return Boolean.compare(x, y);
} }
public static boolean getBoolean(String name) { public BBoolean(String s) {
return Boolean.getBoolean(name); this(Boolean.parseBoolean(s));
} }
public boolean booleanValue() { public boolean booleanValue() {
return value; return this.value;
} }
@Override @Override
public String toString() { public boolean equals(Object o) {
return String.valueOf(value); if (this == o) {
return true;
} else if (!(o instanceof BBoolean)) {
return false;
} else {
return this.value == ((BBoolean) o).value;
}
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(value); return Boolean.hashCode(this.value);
} }
@Override @Override
public boolean equals(Object obj) { public String toString() {
if(!(obj instanceof BBoolean)) { return String.valueOf(this.value);
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);
} }
/* groovy operator overloading support */ /* groovy operator overloading support */
@SuppressWarnings("rawtypes") Object asType(Class<?> clazz) {
Object asType(Class clazz) { if (clazz == BBoolean.class) {
if (clazz == new BBoolean(true).getClass()) {
return this.booleanValue();
}
return this; return this;
} }
return clazz.cast(this.value);
}
public BBoolean or(BBoolean other) { public BBoolean or(BBoolean other) {
return new BBoolean(this.booleanValue() || other.booleanValue()); return new BBoolean(this.booleanValue() || other.booleanValue());
} }
public BBoolean or(Boolean other) { public BBoolean or(boolean other) {
return new BBoolean(this.booleanValue() || other); return new BBoolean(this.booleanValue() || other);
} }
...@@ -88,7 +72,7 @@ public class BBoolean implements BObject { ...@@ -88,7 +72,7 @@ public class BBoolean implements BObject {
return new BBoolean(this.booleanValue() ^ other.booleanValue()); return new BBoolean(this.booleanValue() ^ other.booleanValue());
} }
public BBoolean xor(Boolean other) { public BBoolean xor(boolean other) {
return new BBoolean(this.booleanValue() ^ other); return new BBoolean(this.booleanValue() ^ other);
} }
...@@ -96,7 +80,7 @@ public class BBoolean implements BObject { ...@@ -96,7 +80,7 @@ public class BBoolean implements BObject {
return new BBoolean(this.booleanValue() && other.booleanValue()); return new BBoolean(this.booleanValue() && other.booleanValue());
} }
public BBoolean and(Boolean other) { public BBoolean and(boolean other) {
return new BBoolean(this.booleanValue() && other); return new BBoolean(this.booleanValue() && other);
} }
...@@ -108,31 +92,31 @@ public class BBoolean implements BObject { ...@@ -108,31 +92,31 @@ public class BBoolean implements BObject {
return this.not().or(other); return this.not().or(other);
} }
public BBoolean implies(Boolean other) { public BBoolean implies(boolean other) {
return new BBoolean(this.not().booleanValue() || other); return new BBoolean(this.not().booleanValue() || other);
} }
public BBoolean equivalent(BBoolean 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); return new BBoolean(this.booleanValue() == other);
} }
public BBoolean equal(BBoolean 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) { public BBoolean unequal(BBoolean other) {
return new BBoolean(this.value != other.value); return new BBoolean(this.booleanValue() != other.booleanValue());
} }
public BBoolean isBoolean() { public BBoolean isBoolean() {
return new BBoolean(true); return TRUE;
} }
public BBoolean isNotBoolean() { public BBoolean isNotBoolean() {
return new BBoolean(false); return FALSE;
} }
} }
package de.hhu.stups.btypes; package de.hhu.stups.btypes;
public final class BUtils {
public class BUtils { public static final BSet<BBoolean> BOOL = new BSet<>(BBoolean.TRUE, BBoolean.FALSE);
public static final BSet<BBoolean> BOOL = new BSet<>(new BBoolean(true), new BBoolean(false));
private BUtils() {
}
} }
package de.hhu.stups.btypes; 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; private final boolean value;
public static boolean parseBoolean(String s) { public static BBoolean of(boolean value) {
return Boolean.parseBoolean(s); if (value) {
return TRUE;
} else {
return FALSE;
} }
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) { public static BBoolean of(String value) {
return b.compareTo(value); return of(Boolean.parseBoolean(value));
} }
public static Boolean valueOf(String s) { public BBoolean(boolean value) {
return Boolean.valueOf(s); this.value = value;
}
public static int compare(boolean x, boolean y) {
return Boolean.compare(x, y);
} }
public static boolean getBoolean(String name) { public BBoolean(String s) {
return Boolean.getBoolean(name); this(Boolean.parseBoolean(s));
} }
public boolean booleanValue() { public boolean booleanValue() {
return value; return this.value;
} }
@Override @Override
public String toString() { public boolean equals(Object o) {
return String.valueOf(value); if (this == o) {
return true;
} else if (!(o instanceof BBoolean)) {
return false;
} else {
return this.value == ((BBoolean) o).value;
}
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(value); return Boolean.hashCode(this.value);
} }
@Override @Override
public boolean equals(Object obj) { public String toString() {
if(!(obj instanceof BBoolean)) { return String.valueOf(this.value);
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);
} }
/* groovy operator overloading support */ /* groovy operator overloading support */
@SuppressWarnings("rawtypes") Object asType(Class<?> clazz) {
Object asType(Class clazz) { if (clazz == BBoolean.class) {
if (clazz == new BBoolean(true).getClass()) {
return this.booleanValue();
}
return this; return this;
} }
return clazz.cast(this.value);
}
public BBoolean or(BBoolean other) { public BBoolean or(BBoolean other) {
return new BBoolean(this.booleanValue() || other.booleanValue()); return new BBoolean(this.booleanValue() || other.booleanValue());
} }
public BBoolean or(Boolean other) { public BBoolean or(boolean other) {
return new BBoolean(this.booleanValue() || other); return new BBoolean(this.booleanValue() || other);
} }
...@@ -88,7 +72,7 @@ public class BBoolean implements BObject { ...@@ -88,7 +72,7 @@ public class BBoolean implements BObject {
return new BBoolean(this.booleanValue() ^ other.booleanValue()); return new BBoolean(this.booleanValue() ^ other.booleanValue());
} }
public BBoolean xor(Boolean other) { public BBoolean xor(boolean other) {
return new BBoolean(this.booleanValue() ^ other); return new BBoolean(this.booleanValue() ^ other);
} }
...@@ -96,7 +80,7 @@ public class BBoolean implements BObject { ...@@ -96,7 +80,7 @@ public class BBoolean implements BObject {
return new BBoolean(this.booleanValue() && other.booleanValue()); return new BBoolean(this.booleanValue() && other.booleanValue());
} }
public BBoolean and(Boolean other) { public BBoolean and(boolean other) {
return new BBoolean(this.booleanValue() && other); return new BBoolean(this.booleanValue() && other);
} }
...@@ -108,31 +92,31 @@ public class BBoolean implements BObject { ...@@ -108,31 +92,31 @@ public class BBoolean implements BObject {
return this.not().or(other); return this.not().or(other);
} }
public BBoolean implies(Boolean other) { public BBoolean implies(boolean other) {
return new BBoolean(this.not().booleanValue() || other); return new BBoolean(this.not().booleanValue() || other);
} }
public BBoolean equivalent(BBoolean 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); return new BBoolean(this.booleanValue() == other);
} }
public BBoolean equal(BBoolean 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) { public BBoolean unequal(BBoolean other) {
return new BBoolean(this.value != other.value); return new BBoolean(this.booleanValue() != other.booleanValue());
} }
public BBoolean isBoolean() { public BBoolean isBoolean() {
return new BBoolean(true); return TRUE;
} }
public BBoolean isNotBoolean() { public BBoolean isNotBoolean() {
return new BBoolean(false); return FALSE;
} }
} }
package de.hhu.stups.btypes; package de.hhu.stups.btypes;
public final class BUtils {
public class BUtils { public static final BSet<BBoolean> BOOL = new BSet<>(BBoolean.TRUE, BBoolean.FALSE);
public static final BSet<BBoolean> BOOL = new BSet<>(new BBoolean(true), new BBoolean(false));
private BUtils() {
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment