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
package com.company; | |
import java.util.*; | |
import java.util.stream.Collectors; | |
import java.util.stream.IntStream; | |
record SymbolPair(Short symbol1, Short symbol2) {} | |
record Compressed(List<Character> symbolToText, List<SymbolPair> symbolDictionary, List<Short> compressed) {} | |
//Ideally, you can save the compressed in separate binary files with a given word size to later deserialize every value, |
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.function.UnaryOperator; | |
public class Main { | |
//Top level layer | |
public static void main(String[] args) { | |
sayHi(SHOUTING, "joshi"); | |
sayGoodbye(AFABLE, "readers"); | |
} |
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
class OperationWithOperationData { | |
Predicate<String> isOperation; | |
IntBinaryOperator reductionOperation; | |
List<Integer> toOperateOn; | |
private OperationWithOperationData() {}; | |
public static Function< | |
List<Integer>, |
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
class CharacterData { | |
int HP; | |
int attack; | |
int defense; | |
//Implement all the boilerplate :D | |
} |
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
class OperationAbstractAsClass implements Operation { | |
Predicate<String> isOperation; | |
IntBinaryOperator reductionOperation; | |
private OperationAbstractAsClass(){}; | |
public static OperationAbstractAsClass of( | |
Predicate<String> isOperation, | |
IntBinaryOperator reductionOperation |
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
class OperationInterfaceAsClass implements Operation { | |
Predicate<String> isOperation; | |
Function<List<Integer>, Integer> operate; | |
private OperationInterfaceAsClass(){}; | |
public static OperationInterfaceAsClass of( | |
Predicate<String> isOperation, | |
Function<List<Integer>, Integer> operate |
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
class OperationInterfaceAsClass { | |
Predicate<String> isOperation; | |
Function<List<Integer>, Integer> operate; | |
private OperationInterfaceAsClass(){}; | |
public static OperationInterfaceAsClass of( | |
Predicate<String> isOperation, | |
Function<List<Integer>, Integer> operate |
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.List; | |
interface Operation { | |
boolean isOperation (String input); | |
int operate (List<Integer> numbers); | |
} |
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
//Is common to use all matching functions. Whichever you need to check if a list of flags are set, | |
//if some conditions meet, even if all the fields are equal in a equals function, you need to do an all match. | |
//Many people would do this, but, please, do not do this. Specially if the set of conditions is large. | |
if (conditionA()) { | |
if (conditionB()) { | |
if (conditionC()) { | |
return true; | |
} |
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 EnumCalculator { | |
//Notice how concise the code has become in the logic | |
public int calculate(char op, int a, int b) { | |
return OperationEnum.of(op).operate(a,b); | |
} | |
} |
NewerOlder