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.Collections; | |
import java.util.List; | |
import java.util.Objects; | |
import java.util.function.Predicate; | |
public class RandomGist { | |
public static <T> T requireNonEmpty(T object, Predicate<T> predicate, String msgToCaller){ | |
Objects.requireNonNull(object); | |
Objects.requireNonNull(predicate); |
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.abhirockzz.wordpress.ejb.lifecycle.singleton; | |
import com.abhirockzz.wordpress.ejb.lifecycle.stateful.MyStatefulBean; | |
import java.util.Date; | |
import java.util.logging.Level; | |
import java.util.logging.Logger; | |
import javax.ejb.Singleton; | |
import javax.ejb.Startup; | |
@Singleton |
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.Date; | |
import java.util.logging.Level; | |
import java.util.logging.Logger; | |
import javax.ejb.ConcurrencyManagement; | |
import javax.ejb.ConcurrencyManagementType; | |
import javax.ejb.Lock; | |
import javax.ejb.LockType; | |
import javax.ejb.Singleton; | |
import javax.ejb.Startup; | |
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 Optional<String> stringOptional(String input) { | |
return Optional.of(input); | |
} |
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 Optional<String> stringNullableOptional(String input) { | |
if (!new Random().nextBoolean()) { | |
input = null; | |
} | |
return Optional.ofNullable(input); | |
} |
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 Optional<String> emptyOptional() { | |
return Optional.empty(); | |
} |
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 void consumingOptional() { | |
Optional<String> wrapped = Optional.of("aString"); | |
if (wrapped.isPresent()) { | |
System.out.println("Got string - " + wrapped.get()); | |
} | |
else { | |
System.out.println("Gotcha !"); | |
} | |
} |
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 void consumingNullableOptional() { | |
String input = null; | |
if (new Random().nextBoolean()) { | |
input = "iCanBeNull"; | |
} | |
Optional<String> wrapped = Optional.ofNullable(input); | |
System.out.println(wrapped.orElse("default")); | |
} |
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 void consumingEmptyOptional() { | |
String input = null; | |
if (new Random().nextBoolean()) { | |
input = "iCanBeNull"; | |
} | |
Optional<String> wrapped = Optional.ofNullable(input); | |
System.out.println(wrapped.orElseGet( | |
() -> { | |
return "defaultBySupplier"; | |
} |
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.abhirockzz.wordpress.npesaviors; | |
import java.util.Map; | |
import java.util.Objects; | |
public class UsingObjects { | |
String getVal(Map<String, String> aMap, String key) { | |
return aMap.containsKey(key) ? aMap.get(key) : null; | |
} |
OlderNewer