From 7bbab8dbfa1608856d8435bf7f20ac4a795e5522 Mon Sep 17 00:00:00 2001 From: atravieso Date: Mon, 31 Mar 2025 13:23:18 -0400 Subject: [PATCH] Initial Commit --- .gitignore | 38 +++++++++++++++++ .idea/.gitignore | 3 ++ .idea/encodings.xml | 7 ++++ .idea/misc.xml | 14 +++++++ .idea/vcs.xml | 4 ++ pom.xml | 36 ++++++++++++++++ src/main/java/com/banesco/App.java | 16 ++++++++ src/main/java/com/banesco/util/JsonUtil.java | 41 +++++++++++++++++++ .../java/com/banesco/util/StringUtil.java | 24 +++++++++++ src/test/java/com/banesco/AppTest.java | 38 +++++++++++++++++ 10 files changed, 221 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml create mode 100644 pom.xml create mode 100644 src/main/java/com/banesco/App.java create mode 100644 src/main/java/com/banesco/util/JsonUtil.java create mode 100644 src/main/java/com/banesco/util/StringUtil.java create mode 100644 src/test/java/com/banesco/AppTest.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..463551f --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..d843f34 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..f64012a --- /dev/null +++ b/pom.xml @@ -0,0 +1,36 @@ + + 4.0.0 + + com.banesco + commons + 1.0 + jar + + commons + http://maven.apache.org + + + UTF-8 + + + + + junit + junit + 3.8.1 + test + + + com.fasterxml.jackson.core + jackson-databind + 2.15.4 + compile + + + org.apache.commons + commons-lang3 + 3.13.0 + + + diff --git a/src/main/java/com/banesco/App.java b/src/main/java/com/banesco/App.java new file mode 100644 index 0000000..0966d3e --- /dev/null +++ b/src/main/java/com/banesco/App.java @@ -0,0 +1,16 @@ +package com.banesco; + +import com.banesco.util.StringUtil; + + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) { +boolean value = StringUtil.isNumeric("45"); + System.out.println(value); + } +} diff --git a/src/main/java/com/banesco/util/JsonUtil.java b/src/main/java/com/banesco/util/JsonUtil.java new file mode 100644 index 0000000..050e519 --- /dev/null +++ b/src/main/java/com/banesco/util/JsonUtil.java @@ -0,0 +1,41 @@ +package com.banesco.util; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class JsonUtil { + private static final Logger LOGGER = Logger.getLogger(JsonUtil.class.getName()); + + private static boolean mustInit = true; + + public static final ObjectMapper MAPPER = new ObjectMapper(); + + public static String getJsonFromObject(Object object) { + try { + return MAPPER.writeValueAsString(object); + } catch (JsonProcessingException e) { + LOGGER.log(Level.INFO, "Object To Json Exception: {}", e.getMessage()); + } + return null; + } + + public static T getObjectFromJson(String json, Class className) { + if (StringUtil.isNotEmpty(json)) { + try { + if (mustInit) { + mustInit = false; + MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + } + + return MAPPER.readValue(json, className); + } catch (JsonProcessingException | IllegalArgumentException e) { + LOGGER.log(Level.INFO, "JSON to Object Exception: {}", e.getMessage()); + } + } + return null; + } +} diff --git a/src/main/java/com/banesco/util/StringUtil.java b/src/main/java/com/banesco/util/StringUtil.java new file mode 100644 index 0000000..e5facd7 --- /dev/null +++ b/src/main/java/com/banesco/util/StringUtil.java @@ -0,0 +1,24 @@ +package com.banesco.util; + + +import org.apache.commons.lang3.StringUtils; + +public class StringUtil { + + public static boolean isNumeric(String value) { + try { + Integer.valueOf(value); + return true; + } catch (NumberFormatException e) { + return false; + } + } + + public static boolean isNotEmpty(String value) { + return value != null && !value.trim().isEmpty(); + } + + public static String leftPad(String numberStr, int strLen, Character c) { + return StringUtils.leftPad(numberStr,strLen,c); + } +} diff --git a/src/test/java/com/banesco/AppTest.java b/src/test/java/com/banesco/AppTest.java new file mode 100644 index 0000000..f0474b7 --- /dev/null +++ b/src/test/java/com/banesco/AppTest.java @@ -0,0 +1,38 @@ +package com.banesco; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +}