Skip to content

Instantly share code, notes, and snippets.

@yanzm
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yanzm/023296b825f8104f1c1b to your computer and use it in GitHub Desktop.
Save yanzm/023296b825f8104f1c1b to your computer and use it in GitHub Desktop.
/**
* サイズ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