Last active
August 29, 2015 14:21
-
-
Save yanzm/023296b825f8104f1c1b to your computer and use it in GitHub Desktop.
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
/** | |
* サイズId値を保持するクラス | |
* <p/> | |
* 値がセットされていない状態を持つ | |
*/ | |
public class ValidatableSize { | |
public static final int VALID_SIZE1 = 1; | |
public static final int VALID_SIZE2 = 2; | |
@Retention(RetentionPolicy.SOURCE) | |
@IntDef({VALID_SIZE1, VALID_SIZE2}) | |
public @interface ValidSizeId { | |
} | |
public static class SizeId { | |
@ValidSizeId | |
private int sizeId; | |
@ValidSizeId | |
public int getId() { | |
return sizeId; | |
} | |
public void setId(@ValidSizeId int sizeId) { | |
this.sizeId = sizeId; | |
} | |
} | |
private final SizeId value = new SizeId(); | |
private boolean isValid = false; | |
@Nullable | |
public SizeId getValue() { | |
return isValid ? value : null; | |
} | |
public void setValue(@ValidSizeId int sizeId) { | |
value.setId(sizeId); | |
isValid = true; | |
} | |
public void clear() { | |
isValid = false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment