Created
July 8, 2016 22:04
-
-
Save mohiji/3e45766e02008b10f2f33d25e800cd1d to your computer and use it in GitHub Desktop.
Really basic immutable models for Java/GWT.
This file contains hidden or 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
import static com.google.common.base.Preconditions.checkNotNull; | |
public class ImmutableModel { | |
private final int id; | |
private final String label; | |
public ImmutableModel(int id, String label) { | |
this.id = id; | |
this.label = checkNotNull(label); | |
} | |
public int getId() { | |
return id; | |
} | |
public String getLabel() { | |
return label; | |
} | |
public ImmutableModel withId(int newId) { | |
return new ImmutableModel(newId, label); | |
} | |
public ImmutableModel withLabel(String newLabel) { | |
return new ImmutableModel(id, newLabel); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment