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 org.springframework.web.servlet.handler.HandlerInterceptorAdapter; | |
| public class SecureTokenInterceptor extends HandlerInterceptorAdapter { | |
| private SecureTokenService secureTokenService; | |
| /** | |
| * Constructor. | |
| * | |
| * @param secureTokenService - service to store/retrieve tokens | |
| */ |
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
| /** | |
| * Annotation to mark a controller handler as requiring secure token checking | |
| */ | |
| @Target({ElementType.METHOD, ElementType.TYPE}) | |
| @Retention(RetentionPolicy.RUNTIME) | |
| public @interface SecureToken { | |
| String TOKEN_PARAMETER_NAME = "secureToken"; | |
| String value(); | |
| } |
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
| query = new BasicDBObject("i", | |
| new BasicDBObject("$gt", 20). | |
| append("$lte", 30)); | |
| cursor = coll.find(query); |
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
| Map<Person.Sex, Double> averageAgeByGender = roster | |
| .stream() | |
| .collect( | |
| Collectors.groupingBy( | |
| Person::getGender, | |
| Collectors.averagingInt(Person::getAge))); |
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
| Stream.of(aListOfNumbers) | |
| .sorted() | |
| .limit(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
| reddit.stream() | |
| .map(post -> if(post.isCatPost) return post.getComments(); else return 0;) | |
| .reduce(0.0, (c1, c2) -> c1 + c2); |
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 interface MyInterface { | |
| default public int rollD20() { | |
| return Constants.thaco; | |
| } | |
| } |
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 interface MyInterface { | |
| default public int rollD6() { | |
| return 4; //guaranteed random by roll of dice | |
| } | |
| } |
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
| MyFunctionalInterface deepThought = () -> return 42; | |
| public void answerMe(MyFunctionalInteface calculator) { ... } | |
| answerMe(deepThought); | |
| answerMe(() -> return 42;) |
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
| @FunctionalInterface | |
| public interface MyFunctionalInterface { | |
| public int theQuestion(); | |
| } |