Skip to content

Instantly share code, notes, and snippets.

View RodrigoPinho's full-sized avatar
🏠
Working from home

Rodrigo Pinho RodrigoPinho

🏠
Working from home
View GitHub Profile
package com.rodrigopinho.java17.patternmatching;
sealed interface Vehicle permits Car, Bus, Motorcycle {
static String sealedVehicle(Vehicle v) {
return switch (v) {
case Bus b -> "Vehicle type: Bus";
case Car c -> "Vehicle type: Car";
case Motorcycle m -> "Vehicle type: Motorcycle";
};
}
public static String getGuardedPatternMessage(Object object) {
return switch (object) {
case String s && (s.length() > 10)->
"Big string, size: " + s.length();
case String s ->
"Small string, size: " + s.length();
default -> "Unsupported Object: " + object.getClass().getSimpleName();
};
}
public static String getPatternMatchingMessage(Object object) {
return switch (object) {
case String s -> "Type: String, value: " + s;
case Integer i -> "Type: Integer, value: " + i;
case null -> "Null object";
default -> "Type: Unknown, value: " + object.toString();
};
}
public final class UtilityClassWithLombok {
private static final int CONSTANT = 5;
private UtilityClassWithLombok() {
throw new java.lang.UnsupportedOperationException("This is a utility class and cannot be instantiated");
}
public static int addSomething(int in) {
return in + CONSTANT;
import lombok.experimental.UtilityClass;
@UtilityClass
public class UtilityClassWithLombok {
private final int CONSTANT = 5;
public int addSomething(int in) {
return in + CONSTANT;
}
}
public final class UtilityClass {
// Private constructor to prevent instantiation
private UtilityClass() {
throw new UnsupportedOperationException();
}
//public static methods here
}
# This is build configuration for Java and Docker.
image: maven:3.3.9
options:
docker: true
pipelines:
custom:
schedule-ci: #Continuous Integration
- step:
caches:
FROM jboss/wildfly
ADD ./target/app.war /opt/jboss/wildfly/standalone/deployments/