Sunday, February 21, 2016

Java 8 Finding Specific Element in List with Lambda




As you probably know in Java 8 we can use Lambda expression for different manipulations with collections.
java8-lambda-expression

If you have a List with some custom objects inside and you want to find specific element in it you can use stream().filter procedure of Lambda instead of ForEach as you probably used to. Below is a simple example of this case.

List<RepositoryFile> fileList = response.getRepositoryFileList();
RepositoryFile file1 = fileList.stream().filter(f -> f.getName().contains("my-file.txt")).findFirst().orElse(null);

Thursday, February 18, 2016

Java JSON Parser Example with Regex



Recently I came across with problem where I needed to recognize and parse custom exception message inside JSON on Java server side. For that particular problem I used Regex.

The JSON response format is like this:

json-with-exception-message

And this is the code:

Wednesday, February 17, 2016

AngularJS Binding Syntax and Examples


AngularJS bindings cheat sheet:

One-way(data source -> view target):
  • {{expression}}
  • [target] = "expression"
  • bind-target = "expression"

One-way(view target -> data source):
  • (target) = "statement"
  • on-target = "statement"

Two-way:
  • [(target)] = "expression"
  • bindon-target = "expression"