Skip to content

Instantly share code, notes, and snippets.

@Matthewacon
Created April 13, 2016 02:14
Show Gist options
  • Save Matthewacon/540203f6db83455865dc763c2c2a2d47 to your computer and use it in GitHub Desktop.
Save Matthewacon/540203f6db83455865dc763c2c2a2d47 to your computer and use it in GitHub Desktop.
package examples;
import java.util.HashMap;
/**
* Created by matthew on 12/04/16.
*/
public class AlessioAskedForAnExample {
public enum ExampleEnums {
EXAMPLE_ONE, EXAMPLE_TWO, EXAMPLE_THREE, EXAMPLE_FOUR, EXAMPLE_FIVE, EXAMPLE_SIX
}
public HashMap<ExampleEnums, Boolean> exampleMap = new HashMap<ExampleEnums, Boolean>();
/**When the underlying map of objects is just of booleans, this works better, less code.
*
* @param e
* @return
*/
public Boolean getExampleValue(ExampleEnums e) {
return exampleMap.get(e);
}
/**In cases where there is a more complex underlying map or list of consumers, and multiple operations are required
* to obtain the value requested, this method, of iteration, works best.
*
* @param e
* @return
*/
public Boolean getExampleValue(ExampleEnums e) {
Boolean toReturn = null;
for (ExampleEnums ex : ExampleEnums.values()) {
if (ex.equals(e)) {
toReturn = exampleMap.get(ex);
break;
}
}
return toReturn;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment