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 static <T> Consumer<T> withCounter(ObjIntConsumer<T> consumer) { | |
AtomicInteger counter = new AtomicInteger(0); | |
return item -> consumer.accept(item, counter.getAndIncrement()); | |
} |
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
/** | |
* Method to invoke private methods of other objects via reflection. | |
* | |
* <pre>{@code | |
* BigDecimal object = BigDecimal.ZERO; | |
* | |
* int result = invokePrivate( | |
* object, "adjustScale", | |
* Arrays.asList(10, 2)); | |
* |
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
/** | |
* Limits the maximum number of times a given callback can be called over the time | |
* @param func - callback to throttle | |
* @param ms - interval in milliseconds to throttle a callback | |
*/ | |
function throttle<T extends (...args: any[]) => any>(func: T, ms: number): T { | |
let isThrottled = false; | |
return <T>function () { | |
if (isThrottled) { |
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
class ListNode<T> { | |
value: T; | |
prev: ListNode<T> | null; | |
next: ListNode<T> | null; | |
constructor(value: T) { | |
this.value = value; | |
this.prev = null; | |
this.next = null; | |
} |
NewerOlder