Skip to content

Instantly share code, notes, and snippets.

View Shuhala's full-sized avatar

Sophie Bernadin-Mercier Shuhala

  • Montreal
View GitHub Profile
@Shuhala
Shuhala / optionalOrElse.java
Created July 6, 2017 18:50
Optional.ofNullable example. Get value if not null, otherwise return something else.
Optional.ofNullable(properties.getProperty(key))
.filter(value -> value != null || !value.isEmpty())
.orElse(AnotherValue);
@Shuhala
Shuhala / AppConfig.java
Created July 6, 2017 18:43
Static class to load and get *.properties file values
package framework.utils;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
public final class AppConfig {
private static Properties properties;
@Shuhala
Shuhala / createmenu.java
Created June 21, 2017 12:46
Creates a JMenu filled with a bunch of JMenuItems
/**
* Creates a JMenu with his JMenuItems
*
* @param titleKey JMenu name
* @param itemKeys JMenuItems name
* @return menu
*/
private static JMenu createJMenu(String titleKey, String[] itemKeys) {
JMenu menu = new JMenu(titleKey);
Arrays.stream(itemKeys).forEach(item -> menu.add(new JMenuItem(item)));