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.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"; | |
}; | |
} |
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 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(); | |
}; | |
} |
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 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(); | |
}; | |
} |
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 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; |
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 lombok.experimental.UtilityClass; | |
@UtilityClass | |
public class UtilityClassWithLombok { | |
private final int CONSTANT = 5; | |
public int addSomething(int in) { | |
return in + CONSTANT; | |
} | |
} |
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 final class UtilityClass { | |
// Private constructor to prevent instantiation | |
private UtilityClass() { | |
throw new UnsupportedOperationException(); | |
} | |
//public static methods here | |
} |
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
# This is build configuration for Java and Docker. | |
image: maven:3.3.9 | |
options: | |
docker: true | |
pipelines: | |
custom: | |
schedule-ci: #Continuous Integration | |
- step: | |
caches: |
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
FROM jboss/wildfly | |
ADD ./target/app.war /opt/jboss/wildfly/standalone/deployments/ |