Skip to content

Instantly share code, notes, and snippets.

View marvk's full-sized avatar
🐧

Marvin marvk

🐧
View GitHub Profile
@marvk
marvk / Groupify.java
Last active February 15, 2019 11:32
Groupify
public final class Groupify {
public static String groupify(final String input, final int groupSize) {
if (groupSize < 1) {
throw new IllegalArgumentException("groupSize must be bigger than zero, was " + groupSize);
}
final String inputPadded = input + "x".repeat((groupSize - input.length() % groupSize) % groupSize);
final String[] split = inputPadded.split("(?<=\\G.{" + groupSize + "})");
@marvk
marvk / Caesar.java
Last active February 15, 2019 11:05
Ceasar Cypher
public final class Caesar {
private static final int NUM_LETTERS = 26;
public static String caesar(final String s, final int shift) {
return s.chars()
.filter(Caesar::isEnglishLetter)
.map(character -> getIntUnaryOperator((char) character, shift))
.collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append)
.toString();
}

So, whats wrong with the following start to a constructor of a Graph class?

public Graph(String fileName) {
    File file = null;
    try {
        file = new File(fileName);
    } catch (Exception e) {
        // TODO: handle exception
 }