Optimize boolean, byte
This commit is contained in:
parent
6cc6894528
commit
9118f2271b
@ -12,6 +12,8 @@ public class Nullableboolean implements Serializable, INullable, NativeNullable<
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final Nullableboolean NULL = new Nullableboolean(null);
|
||||
private static final Nullableboolean TRUE = new Nullableboolean(true);
|
||||
private static final Nullableboolean FALSE = new Nullableboolean(false);
|
||||
|
||||
private final Boolean value;
|
||||
|
||||
@ -20,14 +22,14 @@ public class Nullableboolean implements Serializable, INullable, NativeNullable<
|
||||
}
|
||||
|
||||
public static Nullableboolean of(boolean value) {
|
||||
return new Nullableboolean(value);
|
||||
return value ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
public static Nullableboolean ofNullable(@Nullable Boolean value) {
|
||||
if (value == null) {
|
||||
return NULL;
|
||||
} else {
|
||||
return new Nullableboolean(value);
|
||||
return value ? TRUE : FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,13 @@ public class Nullablebyte implements Serializable, INullable, NativeNullable<Byt
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final Nullablebyte NULL = new Nullablebyte(null);
|
||||
private static final Nullablebyte[] BYTES = new Nullablebyte[1 << Byte.SIZE];
|
||||
|
||||
static {
|
||||
for (short i = Byte.MIN_VALUE; i <= Byte.MAX_VALUE; i++) {
|
||||
BYTES[i - Byte.MIN_VALUE] = new Nullablebyte((byte) i);
|
||||
}
|
||||
}
|
||||
|
||||
private final Byte value;
|
||||
|
||||
@ -20,14 +27,14 @@ public class Nullablebyte implements Serializable, INullable, NativeNullable<Byt
|
||||
}
|
||||
|
||||
public static Nullablebyte of(byte value) {
|
||||
return new Nullablebyte(value);
|
||||
return BYTES[value - Byte.MIN_VALUE];
|
||||
}
|
||||
|
||||
public static Nullablebyte ofNullable(@Nullable Byte value) {
|
||||
if (value == null) {
|
||||
return NULL;
|
||||
} else {
|
||||
return new Nullablebyte(value);
|
||||
return BYTES[value - Byte.MIN_VALUE];
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,7 +42,7 @@ public class Nullablebyte implements Serializable, INullable, NativeNullable<Byt
|
||||
if (value == null) {
|
||||
return NULL;
|
||||
} else {
|
||||
return new Nullablebyte(value.byteValue());
|
||||
return BYTES[value.byteValue() - Byte.MIN_VALUE];
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user