This file contains 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 com.mongodb.client.model.Filters; | |
import org.bson.conversions.Bson; | |
import java.util.regex.Pattern; | |
public class MongoFilters { | |
public static Bson eqIgn(String fieldName, String value) { | |
String patternString = new StringBuilder("(?i)^").append(value).append("$").toString(); | |
Pattern pattern = Pattern.compile(patternString, Pattern.CASE_INSENSITIVE); |
This file contains 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 Tuple { | |
static <T extends Tuple, T1, T2> T create(T1 item1, T2 item2) { | |
return (T) new Two<>(item1, item2); | |
} | |
static <T extends Tuple, T1, T2, T3> T create(T1 item1, T2 item2, T3 item3) { | |
return (T) new Three<>(item1, item2, item3); | |
} |
This file contains 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 Handle { | |
interface Two<T1, T2> { | |
void handle(T1 item1, T2 item2); | |
} | |
interface Three<T1, T2, T3> { | |
void handle(T1 item1, T2 item2, T3 item3); | |
} |
This file contains 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.bson.BsonBinaryReader; | |
import org.bson.BsonBinaryWriter; | |
import org.bson.Document; | |
import org.bson.codecs.Codec; | |
import org.bson.codecs.DecoderContext; | |
import org.bson.codecs.DocumentCodec; | |
import org.bson.codecs.EncoderContext; | |
import org.bson.io.BasicOutputBuffer; | |
import java.nio.ByteBuffer; |
This file contains 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 java.util.concurrent.atomic.AtomicLong; | |
import java.util.function.Predicate; | |
public class LongId { | |
private final AtomicLong atomicLong = new AtomicLong(0); | |
public long generateId(Predicate<Long> exists) { | |
if(this.atomicLong.get() == Integer.MAX_VALUE) { | |
this.atomicLong.set(0); |
This file contains 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 com.vaadin.flow.component.UI; | |
import com.vaadin.flow.component.notification.Notification; | |
import com.vaadin.flow.component.notification.NotificationVariant; | |
public class Clipboard { | |
public Clipboard() { | |
String javaScriptFunction = "window.copyToClipboard = (str) => {\n" | |
+ " const textarea = document.createElement(\"textarea\");\n" | |
+ " textarea.value = str;\n" |
This file contains 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 class StringGenerator { | |
public static String createRandomString(int length, String characters) { | |
StringBuilder stringBuilder = new StringBuilder(length); | |
for (int i = 0; i < length; i++) { | |
int index = (int) (characters.length() * Math.random()); | |
stringBuilder.append(characters.charAt(index)); | |
} | |
return stringBuilder.toString(); | |
} |
This file contains 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 java.util.concurrent.TimeUnit; | |
public class TimeStamp { | |
private static final String ZERO = "0"; | |
private static final String MILLIS = "ms"; | |
private static final String NANOS = "ns"; | |
private static final String SECONDS = "s"; | |
private static final String ZERO_MILLIS = ZERO + MILLIS; |
This file contains 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 class Pagifier<T> { | |
private final int maxItemsPerPage; | |
private final List<List<T>> allPages; | |
public Pagifier(int maxItemsPerPage) { | |
this.maxItemsPerPage = maxItemsPerPage; | |
allPages = new LinkedList<>(); | |
allPages.add(new LinkedList<>()); |
This file contains 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 javax.crypto.Cipher; | |
import javax.crypto.SecretKey; | |
import javax.crypto.spec.SecretKeySpec; | |
import java.nio.charset.StandardCharsets; | |
import java.security.MessageDigest; | |
public class EncryptUtils { | |
private static final String ALGORITHM = "AES"; |
OlderNewer