forked from UnlegitDqrk/unlegitlibrary
Initial commit
This commit is contained in:
75
src/main/java/me/finn/unlegitlibrary/utils/Converter.java
Normal file
75
src/main/java/me/finn/unlegitlibrary/utils/Converter.java
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (C) 2024 UnlegitDqrk - All Rights Reserved
|
||||
*
|
||||
* You are unauthorized to remove this copyright.
|
||||
* You have to give Credits to the Author in your project and link this GitHub site: https://github.com/UnlegitDqrk
|
||||
* See LICENSE-File if exists
|
||||
*/
|
||||
|
||||
package me.finn.unlegitlibrary.utils;
|
||||
|
||||
public class Converter extends DefaultMethodsOverrider {
|
||||
|
||||
public static String convertToString(Object object) {
|
||||
return String.valueOf(object);
|
||||
}
|
||||
|
||||
public static boolean convertToBoolean(Object object, boolean fallback) {
|
||||
if (object instanceof String) return Boolean.valueOf(convertToString(object));
|
||||
else if (object instanceof Double) return Math.round(convertToDouble(object, fallback ? 1 : -1)) >= 1;
|
||||
else if (object instanceof Float) return Math.round(convertToFloat(object, fallback ? 1 : -1)) >= 1;
|
||||
else if (object instanceof Integer) return convertToInteger(object, fallback ? 1 : -1) >= 1;
|
||||
else if (object instanceof Long) return Math.round(convertToLong(object, fallback ? 1 : -1)) >= 1;
|
||||
else if (object instanceof Short) return convertToShort(object, (short) (fallback ? 1 : -1)) >= 1;
|
||||
else if (object instanceof Byte) return convertToByte(object, (byte) (fallback ? 1 : -1)) >= 0.001;
|
||||
else return fallback;
|
||||
}
|
||||
|
||||
public static int convertToInteger(Object object, int fallback) {
|
||||
try {
|
||||
return Integer.parseInt(convertToString(object));
|
||||
} catch (NumberFormatException exception) {
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
public static short convertToShort(Object object, short fallback) {
|
||||
try {
|
||||
return Short.parseShort(convertToString(object));
|
||||
} catch (NumberFormatException exception) {
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
public static byte convertToByte(Object object, byte fallback) {
|
||||
try {
|
||||
return Byte.parseByte(convertToString(object));
|
||||
} catch (NumberFormatException exception) {
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
public static long convertToLong(Object object, long fallback) {
|
||||
try {
|
||||
return Long.parseLong(convertToString(object));
|
||||
} catch (NumberFormatException exception) {
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
public static float convertToFloat(Object object, float fallback) {
|
||||
try {
|
||||
return Float.parseFloat(convertToString(object));
|
||||
} catch (NumberFormatException exception) {
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
public static double convertToDouble(Object object, double fallback) {
|
||||
try {
|
||||
return Double.parseDouble(convertToString(object));
|
||||
} catch (NumberFormatException exception) {
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) 2024 UnlegitDqrk - All Rights Reserved
|
||||
*
|
||||
* You are unauthorized to remove this copyright.
|
||||
* You have to give Credits to the Author in your project and link this GitHub site: https://github.com/UnlegitDqrk
|
||||
* See LICENSE-File if exists
|
||||
*/
|
||||
|
||||
package me.finn.unlegitlibrary.utils;
|
||||
|
||||
public class DefaultMethodsOverrider {
|
||||
|
||||
@Override
|
||||
protected final Object clone() throws CloneNotSupportedException {
|
||||
return super.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean equals(Object obj) {
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String toString() {
|
||||
return super.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int hashCode() {
|
||||
return super.hashCode();
|
||||
}
|
||||
|
||||
}
|
29
src/main/java/me/finn/unlegitlibrary/utils/Tuple.java
Normal file
29
src/main/java/me/finn/unlegitlibrary/utils/Tuple.java
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (C) 2024 UnlegitDqrk - All Rights Reserved
|
||||
*
|
||||
* You are unauthorized to remove this copyright.
|
||||
* You have to give Credits to the Author in your project and link this GitHub site: https://github.com/UnlegitDqrk
|
||||
* See LICENSE-File if exists
|
||||
*/
|
||||
|
||||
package me.finn.unlegitlibrary.utils;
|
||||
|
||||
public class Tuple<A, B> extends DefaultMethodsOverrider {
|
||||
|
||||
private final A a;
|
||||
private final B b;
|
||||
|
||||
public Tuple(final A a, final B b) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public final A getA() {
|
||||
return this.a;
|
||||
}
|
||||
|
||||
public final B getB() {
|
||||
return this.b;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user