package org.expeditee.auth; import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.Optional; import org.expeditee.items.Text; public enum AuthenticationTag { Username ("txtUsername", System.getProperty("user.name")), Password ("txtPassword", System.getProperty("user.password")), PasswordAgain ("txtPasswordAgain", System.getProperty("user.password.again")), NewPassword ("txtNewPassword", System.getProperty("user.new.password")), NewPasswordAgain ("txtNewPasswordAgain", System.getProperty("user.new.password.again")), Email ("txtEmail", System.getProperty("user.email")), ColleagueOne ("txtColleagueOne", System.getProperty("user.colleague.one")), ColleagueTwo ("txtColleagueTwo", System.getProperty("user.colleague.two")); public String val; public String def; private AuthenticationTag(final String tag, final String def) { this.val = tag; this.def = def; } public static Optional> fetchUserData(final Collection from, final AuthenticationTag... tags) { final Map fetchedData = new HashMap(); for (final AuthenticationTag tag: tags) { for (final Text canditate: from) { // use the canditate if it exists if (canditate.hasData(tag.val)) { fetchedData.put(tag, canditate.getText()); break; } // otherwise try use the default final String property = tag.def; if (property != null && !property.isEmpty()) { fetchedData.put(tag, property); } } } if (fetchedData.entrySet().size() == tags.length) { return Optional.of(fetchedData); } else { return Optional.empty(); } } }