This file contains hidden or 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
final Options options = new Options(); | |
final Option nameCmdOption = Option.builder("n").hasArg(true).argName(NAME_CMD_OPTION).longOpt(NAME_CMD_OPTION).desc("Person's name").required(true).type(String.class).build(); | |
options.addOption(nameCmdOption); | |
final Option surnameCmdOption = Option.builder("s").hasArg(true).argName(SURNAME_CMD_OPTION).longOpt(SURNAME_CMD_OPTION).desc("Person's surname").required(true).type(String.class).build(); | |
options.addOption(surnameCmdOption); | |
final Option ageCmdOption = Option.builder("a").hasArg(true).argName(AGE_CMD_OPTION).longOpt(AGE_CMD_OPTION).desc("Person's age").required(true).type(Integer.class).build(); | |
options.addOption(ageCmdOption); |
This file contains hidden or 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
try { | |
final CommandLine cmd = new DefaultParser().parse(PersonalInfoReader.createCommandLineOptions(), args); | |
if (cmd.hasOption(HELP_CMD_OPTION)) { | |
new HelpFormatter().printHelp(120, "java", "Person Parsing", PersonalInfoReader.createCommandLineOptions(), ""); | |
return; | |
} | |
final String name = cmd.getOptionValue(NAME_CMD_OPTION); | |
final String surname = cmd.getOptionValue(SURNAME_CMD_OPTION); |
This file contains hidden or 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 SingletonClass { | |
private static final com.nikoskatsanos.nkjutils.yalf.YalfLogger log = com.nikoskatsanos.nkjutils.yalf.YalfLogger.getLogger(SingletonClass.class); | |
private SingletonClass() { | |
log.info("Initializing %s", this.getClass().getName()); | |
} | |
public static final SingletonClass getInstance() { | |
return SingletonClassHelper.INSTANCE; |
This file contains hidden or 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 Person(String name, String surname, int age, String email) { | |
this.name = name; | |
this.surname = surname; | |
this.age = age; | |
this.email = email; | |
} |
This file contains hidden or 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 class PersonBuilder { | |
private static final Pattern EMAIL_VALIDATION_REGEX = Pattern.compile("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"); | |
private String name; | |
private String surname; | |
private int age; | |
private String email; | |
private PersonBuilder() { |
This file contains hidden or 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
@FunctionalInterface | |
public interface NowService { | |
/** | |
* @return the number of milliseconds since 1st January 1970 UTC | |
*/ | |
long nowMillis(); | |
} |
This file contains hidden or 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 SystemClockNowService implements NowService { | |
@Override | |
public long nowMillis() { | |
return System.currentTimeMillis(); | |
} | |
} |
This file contains hidden or 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 NamedThreadFactory implements ThreadFactory { | |
private final String name; | |
private final boolean isDaemon; | |
private final AtomicInteger threadCounter; | |
public NamedThreadFactory() { | |
this("Thread"); | |
} |
This file contains hidden or 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 void start() { | |
final ExecutorService left = Executors.newSingleThreadExecutor(new NamedThreadFactory("Left", true)); | |
final Object leftObject = new Object(); | |
final ExecutorService right = Executors.newSingleThreadExecutor(new NamedThreadFactory("Right", false)); | |
final Object rightObject = new Object(); | |
left.execute(() -> { | |
while (true) { | |
synchronized (leftObject) { | |
ThreadUtils.sleepWithoutInterruption(3000L, TimeUnit.MILLISECONDS); |
This file contains hidden or 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 enum Weekdays { | |
MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY | |
} |
OlderNewer