Skip to content

Instantly share code, notes, and snippets.

View ohdoking's full-sized avatar
🎯
Focusing

Kenny Oh Dokeun ohdoking

🎯
Focusing
View GitHub Profile
//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();
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 ) ;
@ohdoking
ohdoking / gist:2bdda60146b14aeaf9fb41a6870f54f6
Created January 14, 2019 05:29
sort by value in Map in Java
// 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,
@ohdoking
ohdoking / gist:da4af7238f0945cdf6087dbc95505656
Created January 3, 2019 09:33
[Java]Reverse method in Stream
public static <T> Collector<T, ?, Stream<T>> reverse() {
return Collectors.collectingAndThen(Collectors.toList(), list -> {
Collections.reverse(list);
return list.stream();
});
}
public static <T> Collector<T, ?, Stream<T>> reverse() {
return Collectors.collectingAndThen(Collectors.toList(), list -> {
Collections.reverse(list);
return list.stream();
});
}
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;