Skip to content

Instantly share code, notes, and snippets.

View SiAust's full-sized avatar
🏠
Open to new opportunities

Simon Aust SiAust

🏠
Open to new opportunities
View GitHub Profile
@SiAust
SiAust / gist:18c923b5d82d1545fbe99776852306b6
Created August 17, 2023 13:05
Enum abrastract method
class ArithmeticFunction {
private static enum Operation {
add {
@Override
int apply(int a, int b) {
return a + b;
}
}, subtract {
@Override
plugins {
id 'org.springframework.boot' version '2.3.1.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}
group = 'io.github.siaust'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.example.web_quiz_app.WebQuizAppApplication];
nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException:
Annotation-specified bean name 'securityConfig' for bean class [com.example.web_quiz_app.Security.SecurityConfig]
conflicts with existing, non-compatible bean definition of same name and class [io.github.siaust.web_quiz_app.Config.SecurityConfig]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:188) ~[spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE
@SiAust
SiAust / Comparator example
Created April 18, 2021 09:51
Sort a list by odd first, then odd asc, even desc
public static List<Integer> sortOddEven(List<Integer> numbers) {
// sort odd and even
// then sort odd asc, even desc
Comparator<Integer> byOddFirst = (i1, i2) -> (i1 | 1) == i1 ? -1 : (i2 | 1) > i2 ? 1 : 0;
Comparator<Integer> byOddAscEvenDesc = (i1, i2) -> {
if ((i1 | 1) == i1 && (i2 | 1) == i2) {
return Integer.compare(i1, i2);
} else if ((i1 | 1) > i1 && (i2 | 1) > i2) {
return Integer.compare(i1, i2) * -1;
@SiAust
SiAust / JUnitTest.java
Created March 16, 2021 10:07
Simple example of JUnit
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
public class JUnitTest {
@Test
public void CalculatorTest() {
Calculator calculator = new Calculator();
assertEquals(10, calculator.sum("1234"));
@SiAust
SiAust / SandwichBuilder.java
Created December 11, 2020 09:57
Example of Builder pattern.
import java.util.Scanner;
class Sandwich {
private String bun;
private int salad;
private int cheese;
private int cucumber;
private int ham;
@SiAust
SiAust / scratch_7.java
Created December 9, 2020 10:11
Java Reflection API example
// Do not remove imports
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.WildcardType;
import java.util.Set;
import java.util.Scanner;
class ListParameterInspector {
// Do not change the method
@SiAust
SiAust / Builder.java
Created October 24, 2020 10:28
Example builder pattern with interface and concrete builder.
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
* ConcreteComponent - Geek.
**/
class Geek {
private String type;
private List<String> languages;
@SiAust
SiAust / StaticBuilder.java
Created October 24, 2020 10:27
Example builder pattern in static class.
import java.util.Scanner;
class Robot {
private String CPU;
private int legs;
private int hands;
private int eyes;
Robot(String CPU, int legs, int hands, int eyes) {
@SiAust
SiAust / Direction_Enum.java
Created October 19, 2020 08:40
Enum example
class Move {
public static void main(String[] args) {
Robot robot = new Robot(0,0, Direction.UP);
System.out.printf("robotX: %d robotY: %d\n", robot.getX(), robot.getY());
moveRobot(robot, 10, 0);
System.out.printf("robotX: %d robotY: %d\n", robot.getX(), robot.getY());
}
public static void moveRobot(Robot robot, int toX, int toY) {