Last active
December 9, 2015 16:56
-
-
Save shelajev/0d15c7deb6dea6acaecd to your computer and use it in GitHub Desktop.
RebelLabs post: A Fluent API or not API fluent a? That is the Question!
This file contains hidden or 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
| configurations.markdown | |
| .resolve() | |
| .collect { artifact -> artifact.name } | |
| .join(',') | |
| .concat(',.') |
This file contains hidden or 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
| lib1,lib2,lib3,. |
This file contains hidden or 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
| public class Foo { | |
| private String bar; | |
| private int number; | |
| public Foo() { | |
| // Do some stuff | |
| } | |
| public String getBar() { return this.bar; } | |
| public void setBar(String bar) { this.bar = bar; } | |
| public int getNumber() { return this.number; } | |
| public void setNumber(int number) { this.number = number; } | |
| } |
This file contains hidden or 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
| public class FooFactory { | |
| private static Foo f; | |
| public static Foo getInstance() { | |
| final String pathToNative; | |
| if(PlatformUtil.isMac()) { | |
| pathToNative = "lib.so"; | |
| } else if(PlatformUtil.isWindows()) { | |
| pathToNative = "lib.dll"; | |
| } else { | |
| pathToNative = "lib.sh"; | |
| } | |
| return new Foo(pathToNative); | |
| } | |
| } |
This file contains hidden or 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
| println "Hello RebelLabs" |
This file contains hidden or 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
| final String[] array = { "10", "20", "30" }; | |
| System.out.println(Arrays.stream(array) | |
| .map(Integer::parseInt) | |
| .reduce((i1, i2) -> i1 + i2)); |
This file contains hidden or 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
| final String[] array = { "10", "20", "30" }; | |
| final Map<Integer, Double> results = Arrays.stream(array) | |
| .map(Integer::parseInt) | |
| .collect( | |
| Collectors.toMap( | |
| Function.identity(), | |
| number -> Math.pow(number, 2) | |
| ) | |
| ); | |
| for(Map.Entry entry : results.entrySet()) { | |
| System.out.println(entry.toString()); | |
| } |
This file contains hidden or 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
| final LocalDate date = LocalDate.now().plusDays(10).plusMonths(3); | |
| final LocalTime time = LocalTime.now().plusHours(2).plusMinutes(120); |
This file contains hidden or 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
| final Foo foo = new Foo(); | |
| // Do some stuff ... | |
| // And then ... | |
| foo.setBar("RebelLabs").setNumber(10); |
This file contains hidden or 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
| public class Foo { | |
| private String bar; | |
| private int number; | |
| public Foo() { | |
| // Do some stuff | |
| } | |
| public String getBar() { return this.bar; } | |
| public Foo setBar(String bar) { | |
| this.bar = bar; | |
| return this; | |
| } | |
| public int getNumber() { return this.number; } | |
| public Foo setNumber(int number) { | |
| this.number = number; | |
| return this; | |
| } | |
| } |
This file contains hidden or 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
| public class Foo { | |
| private String bar; | |
| private int number; | |
| public Foo() { | |
| // Do some stuff | |
| } | |
| public String bar() { return this.bar; } | |
| public Foo bar(String bar) { | |
| this.bar = bar; | |
| return this; | |
| } | |
| public int number() { return this.number; } | |
| public Foo number(int number) { | |
| this.number = number; | |
| return this; | |
| } | |
| } |
This file contains hidden or 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
| final Foo foo = new Foo(); | |
| // Do some stuff ... | |
| // And then ... | |
| foo.bar("RebelLabs").number(10); |
This file contains hidden or 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
| final PropertyDescriptor descriptor = new PropertyDescriptor("bar", Foo.class); | |
| final Method getter = descriptor.getReadMethod(); | |
| final Method setter = descriptor.getWriteMethod(); |
This file contains hidden or 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
| final BeanInfo beanInfo = Introspector.getBeanInfo(Foo.class); | |
| final PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors(); | |
| Arrays.stream(descriptors).forEach(descriptor -> { | |
| final Method getter = descriptor.getReadMethod(); | |
| final Method setter = descriptor.getWriteMethod(); | |
| ... | |
| }); |
This file contains hidden or 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
| final Connection connection = ... | |
| final DSLContext context = DSL.using(connection, SQLDialect.H2); | |
| final Result<Record2<Long, String>> result = context.select(Users.ID, Users.USER_NAME) | |
| .from(Users.TABLE) | |
| .where(Users.USER_NAME.equal(user.getUserName().toLowerCase())) | |
| .fetch(); |
This file contains hidden or 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
| var obj = { | |
| "person": { | |
| "firstName": "Thierry", | |
| "lastName": "Wasylczenko", | |
| "gender": "male" | |
| }, | |
| "projects": [ "SlideshowFX", "Base64FX" ] | |
| }; | |
| console.log(obj.person.lastName); | |
| console.log(obj.projects); |
This file contains hidden or 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
| public class SomeClass { | |
| // Instead of this | |
| public class methodA(final int number, final String name, final boolean create, final List<String> nicknames) { | |
| // ... | |
| } | |
| // How about this | |
| public class methodB(final Context ctx) { | |
| // ... | |
| } | |
| } |
This file contains hidden or 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
| import static spark.Spark.*; | |
| public class SparkExample { | |
| public static void main(String[] args) { | |
| port(10080); | |
| get("/index", (request, response) -> ... ); | |
| get("/users/:id", (request, response) -> ... ); | |
| post("/users", (request, response) -> ... ); | |
| } | |
| } |
This file contains hidden or 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
| def name = 'RebelLabs' | |
| def message = "Hello ${name}" |
This file contains hidden or 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
| final Router router = ... | |
| router.get("/some/url").handler(...); | |
| router.post("/some/url").handler(...); | |
| router.put("/some/other/url").handler(...); |
This file contains hidden or 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
| Vertx vertx = Vertx.vertx(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment