-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: applenick <applenick@users.noreply.github.com>
- Loading branch information
Showing
9 changed files
with
59 additions
and
15 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
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
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
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
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
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
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
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
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,34 @@ | ||
package dev.pgm.community.utils; | ||
|
||
import co.aikar.idb.DbRow; | ||
|
||
public class DatabaseUtils { | ||
|
||
public static boolean parseBoolean(DbRow row, String fieldName) throws ClassCastException { | ||
Object obj = row.get(fieldName); | ||
if (obj instanceof Integer) { | ||
int activeInt = (Integer) obj; | ||
return (activeInt != 0); | ||
} else if (obj instanceof Boolean) { | ||
return (Boolean) obj; | ||
} else { | ||
throw new ClassCastException( | ||
"Unexpected type for '" + fieldName + "': " + obj.getClass().getName()); | ||
} | ||
} | ||
|
||
public static long parseLong(DbRow row, String fieldName) throws ClassCastException { | ||
Object obj = row.get(fieldName); | ||
if (obj instanceof String) { | ||
String rawLong = (String) obj; | ||
return Long.parseLong(rawLong); | ||
} else if (obj instanceof Long) { | ||
return (Long) obj; | ||
} else if (obj instanceof Integer) { | ||
return (Integer) obj; | ||
} else { | ||
throw new ClassCastException( | ||
"Unexpected type for '" + fieldName + "': " + obj.getClass().getName()); | ||
} | ||
} | ||
} |