/** * Converts between an id and an account owner. A valid id means a Member, while an invalid means * system * * @author luis */ public class AccountOwnerConverter implements Converter<AccountOwner> { private static final long serialVersionUID = -4876497836403187578L; private static final AccountOwnerConverter INSTANCE = new AccountOwnerConverter(false); private static final AccountOwnerConverter ZERO_IS_SYSTEM_INSTANCE = new AccountOwnerConverter(true); private static final ReferenceConverter<Member> REFERENCE_CONVERTER = ReferenceConverter.instance(Member.class); public static AccountOwnerConverter instance() { return INSTANCE; } public static AccountOwnerConverter zeroIsSystemInstance() { return ZERO_IS_SYSTEM_INSTANCE; } private final boolean zeroIsSystem; private AccountOwnerConverter(final boolean zeroIsSystem) { this.zeroIsSystem = zeroIsSystem; } public boolean isZeroIsSystem() { return zeroIsSystem; } public String toString(final AccountOwner object) { if (object instanceof Member) { return REFERENCE_CONVERTER.toString((Member) object); } return ""; } public AccountOwner valueOf(final String string) { final Member member = REFERENCE_CONVERTER.valueOf(string); return member == null ? (zeroIsSystem ? SystemAccountOwner.instance() : LoggedUser.accountOwner()) : member; } }
public AccountOwner valueOf(final String string) { final Member member = REFERENCE_CONVERTER.valueOf(string); return member == null ? (zeroIsSystem ? SystemAccountOwner.instance() : LoggedUser.accountOwner()) : member; }
public String toString(final AccountOwner object) { if (object instanceof Member) { return REFERENCE_CONVERTER.toString((Member) object); } return ""; }