Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Kenny Oh Dokeun ohdoking

🎯
Focusing
View GitHub Profile
View gist:596998c519c55d54f50d7524ba032f9d
//https://stackoverflow.com/questions/45673978/aspectj-change-value-of-method-parameter
@Around("execution(* *(.., @aspectjtest.ReplaceFooBar (*), ..))")
public Object replaceFooBar(ProceedingJoinPoint pjp) throws Throwable {
//get original args
Object[] args = pjp.getArgs();
//get all annotations for arguments
MethodSignature signature = (MethodSignature) pjp.getSignature();
String methodName = signature.getMethod().getName();
Class<?>[] parameterTypes = signature.getMethod().getParameterTypes();
View gist:a215cf75818b24789b70e0bad5a45d20
public void currying() {
// Create a function that adds 2 integers
BiFunction<Integer,Integer,Integer> adder = ( a, b ) -> a + b ;
// And a function that takes an integer and returns a function
Function<Integer,Function<Integer,Integer>> currier = a -> b -> adder.apply( a, b ) ;
// Call apply 4 to currier (to get a function back)
Function<Integer,Integer> curried = currier.apply( 4 ) ;
View gist:2bdda60146b14aeaf9fb41a6870f54f6
// function to sort hashmap by values
public static HashMap<String, Integer> sortByValue(HashMap<String, Integer> hm)
{
// Create a list from elements of HashMap
List<Map.Entry<String, Integer> > list =
new LinkedList<Map.Entry<String, Integer> >(hm.entrySet());
// Sort the list
Collections.sort(list, new Comparator<Map.Entry<String, Integer> >() {
public int compare(Map.Entry<String, Integer> o1,
View gist:da4af7238f0945cdf6087dbc95505656
public static <T> Collector<T, ?, Stream<T>> reverse() {
return Collectors.collectingAndThen(Collectors.toList(), list -> {
Collections.reverse(list);
return list.stream();
});
}
View gist:a85371539b384e5feba68b7ea41da539
public static <T> Collector<T, ?, Stream<T>> reverse() {
return Collectors.collectingAndThen(Collectors.toList(), list -> {
Collections.reverse(list);
return list.stream();
});
}
View test
package com.example.floatingbubble;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.EnumMap;
import java.util.Locale;