-
Notifications
You must be signed in to change notification settings - Fork 0
Core Sucre library. Provides the core set of Sucre modules.
License
nzjess/sucre-core
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Introduction ------------- Sucre core provides the core set of Sucre modules. It also includes common utilities that are depended on by other, separately distributed modules. The core modules are generally those that have no non-core Java dependencies. Sucre core provides the following: - Reflect - Makes reflection a little more sugary for Java Bean-style classes. - Coercer - Give your simple types a gentle nudge this way or that when they need it. - Attributes - In the style of java.util.Properties, but a bit sweeter. Combines Reflect and Coercer and adds a nice proxying layer. Usage -------------- There are plenty of usage examples in the code under src/test. Like this: import static org.junit.Assert.assertEquals; import java.util.HashMap; import java.util.Map; import org.junit.Test; public class AttributesTest { private static interface TestMe { String getHello(); String getNumber(); @AttributeKey("my.key") String getSomeString(); @AttributeDefaultInt(42) int getTheAnswer(); void setTheAnswer(int answer); long getNotFussy(); void setNotFussy(String string); } @Test public void testMe() { // start with a map Map<Object, Object> values = new HashMap<Object, Object>(); values.put("hello", "World"); values.put("number", 12345); values.put("my.key", "my.value"); values.put("notFussy", (byte)3); // test me TestMe me = Attributes.backedBy(values).proxy(TestMe.class); // hello world assertEquals("World", me.getHello()); // coerce int to String assertEquals("12345", me.getNumber()); // use a non-default key assertEquals("my.value", me.getSomeString()); // use a default value assertEquals(42, me.getTheAnswer()); // modify a value me.setTheAnswer(101); assertEquals(101, me.getTheAnswer()); // not fussy assertEquals(3L, me.getNotFussy()); // still not me.setNotFussy("4"); assertEquals(4L, me.getNotFussy()); } } Building -------------- Uses Maven. From the root of the project dir, type: $ mvn install Maven Artifact -------------- <dependency> <groupId>org.ubercraft.sucre</groupId> <artifactId>sucre-core</artifactId> </dependency>
About
Core Sucre library. Provides the core set of Sucre modules.
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published