diff options
Diffstat (limited to 'src/de/animux/android/andmal/api')
-rw-r--r-- | src/de/animux/android/andmal/api/MalList.java | 79 | ||||
-rw-r--r-- | src/de/animux/android/andmal/api/MalListParser.java | 40 | ||||
-rw-r--r-- | src/de/animux/android/andmal/api/MalObject.java | 7 | ||||
-rw-r--r-- | src/de/animux/android/andmal/api/MalObjectStore.java | 5 | ||||
-rw-r--r-- | src/de/animux/android/andmal/api/MalState.java | 5 | ||||
-rw-r--r-- | src/de/animux/android/andmal/api/anime/Anime.java | 22 | ||||
-rw-r--r-- | src/de/animux/android/andmal/api/anime/AnimeList.java | 141 | ||||
-rw-r--r-- | src/de/animux/android/andmal/api/anime/AnimeListParser.java | 45 | ||||
-rw-r--r-- | src/de/animux/android/andmal/api/anime/State.java | 4 | ||||
-rw-r--r-- | src/de/animux/android/andmal/api/manga/Manga.java | 209 | ||||
-rw-r--r-- | src/de/animux/android/andmal/api/manga/MangaList.java | 86 | ||||
-rw-r--r-- | src/de/animux/android/andmal/api/manga/MangaListParser.java | 50 | ||||
-rw-r--r-- | src/de/animux/android/andmal/api/manga/State.java | 38 |
13 files changed, 641 insertions, 90 deletions
diff --git a/src/de/animux/android/andmal/api/MalList.java b/src/de/animux/android/andmal/api/MalList.java new file mode 100644 index 0000000..79a37b6 --- /dev/null +++ b/src/de/animux/android/andmal/api/MalList.java @@ -0,0 +1,79 @@ +package de.animux.android.andmal.api; + +import java.util.Collection; +import java.util.Map; + +public abstract class MalList { + + private String username; + + private String password; + + protected boolean needsRefresh; + + private static MalList cache; + + public MalList(String username, String password) { + this.username = username; + this.password = password; + cache = this; + setNeedsRefresh(true); + } + + public MalList() { + if (cache != null) { + this.username = cache.getUsername(); + this.password = cache.getPassword(); + setNeedsRefresh(false); + } + } + + public String getUsername() { + return this.username; + } + + public void setUsername(String username) { + if (this.username != null && this.username.equals(username)) + return; + + this.username = username; + this.needsRefresh = true; + + if (cache != this + && (cache.getUsername() == null || !cache.getUsername().equals( + username))) { + cache.setUsername(username); + } + } + + protected String getPassword() { + return this.password; + } + + public void setPassword(String password) { + if (this.password != null && this.password.equals(password)) + return; + + this.password = password; + this.needsRefresh = true; + + if (cache != this + && (cache.getPassword() == null || !cache.getPassword().equals( + password))) { + cache.setPassword(password); + } + } + + public void setNeedsRefresh(boolean needsRefresh) { + this.needsRefresh = needsRefresh; + } + + public boolean needsRefresh() { + return needsRefresh; + } + + abstract public void refresh(); + + abstract public Map<MalState, Collection<MalObject>> getObjects(); + +}
\ No newline at end of file diff --git a/src/de/animux/android/andmal/api/MalListParser.java b/src/de/animux/android/andmal/api/MalListParser.java new file mode 100644 index 0000000..014b718 --- /dev/null +++ b/src/de/animux/android/andmal/api/MalListParser.java @@ -0,0 +1,40 @@ +package de.animux.android.andmal.api; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +public abstract class MalListParser<T extends MalObject> extends DefaultHandler { + private StringBuffer currentValue; + + protected MalObjectStore<T> objectStore; + + public MalListParser(MalObjectStore<T> objectStore) { + super(); + + this.objectStore = objectStore; + currentValue = new StringBuffer(); + } + + @Override + public void characters(char[] ch, int start, int length) + throws SAXException { + currentValue.append(new String(ch).substring(start, length - start) + .replaceAll("&", "&")); + } + + @Override + public void endElement(String uri, String localName, String qName) + throws SAXException { + addElement(localName, currentValue.toString()); + currentValue.setLength(0); + } + + @Override + public void startElement(String uri, String localName, String qName, + Attributes attributes) throws SAXException { + currentValue.setLength(0); + } + + abstract public void addElement(String name, String value); +} diff --git a/src/de/animux/android/andmal/api/MalObject.java b/src/de/animux/android/andmal/api/MalObject.java new file mode 100644 index 0000000..9ccf279 --- /dev/null +++ b/src/de/animux/android/andmal/api/MalObject.java @@ -0,0 +1,7 @@ +package de.animux.android.andmal.api; + +public abstract class MalObject implements Comparable<MalObject> { + + public abstract String getTitle(); + public abstract String getProgress(); +} diff --git a/src/de/animux/android/andmal/api/MalObjectStore.java b/src/de/animux/android/andmal/api/MalObjectStore.java new file mode 100644 index 0000000..937ac2e --- /dev/null +++ b/src/de/animux/android/andmal/api/MalObjectStore.java @@ -0,0 +1,5 @@ +package de.animux.android.andmal.api; + +public interface MalObjectStore<T extends MalObject> { + public void add(T object); +} diff --git a/src/de/animux/android/andmal/api/MalState.java b/src/de/animux/android/andmal/api/MalState.java new file mode 100644 index 0000000..ed76bc6 --- /dev/null +++ b/src/de/animux/android/andmal/api/MalState.java @@ -0,0 +1,5 @@ +package de.animux.android.andmal.api; + +public interface MalState { + public String toString(); +} diff --git a/src/de/animux/android/andmal/api/anime/Anime.java b/src/de/animux/android/andmal/api/anime/Anime.java index d4f542f..dc4b34e 100644 --- a/src/de/animux/android/andmal/api/anime/Anime.java +++ b/src/de/animux/android/andmal/api/anime/Anime.java @@ -1,6 +1,8 @@ package de.animux.android.andmal.api.anime; -public class Anime implements Comparable<Anime> { +import de.animux.android.andmal.api.MalObject; + +public class Anime extends MalObject { private int id; private String title; @@ -180,18 +182,28 @@ public class Anime implements Comparable<Anime> { } @Override - public int compareTo(Anime arg0) { - int compareTitle = arg0.getTitle().compareTo(getTitle()); + public int compareTo(MalObject arg0) { + if ( !(arg0 instanceof Anime)) { + throw new IllegalArgumentException(); + } + + Anime a = (Anime)arg0; + int compareTitle = a.getTitle().compareTo(getTitle()); if (compareTitle != 0) { return compareTitle; } else { - if (arg0.getId() != getId()) { - return getId() - arg0.getId(); + if (a.getId() != getId()) { + return getId() - a.getId(); } } return 0; } + @Override + public String getProgress() { + return getWatchedEpisodes() + "/" + getEpisodes(); + } + } diff --git a/src/de/animux/android/andmal/api/anime/AnimeList.java b/src/de/animux/android/andmal/api/anime/AnimeList.java index 78a1e09..0fbb4ea 100644 --- a/src/de/animux/android/andmal/api/anime/AnimeList.java +++ b/src/de/animux/android/andmal/api/anime/AnimeList.java @@ -1,117 +1,90 @@ package de.animux.android.andmal.api.anime; -import java.io.IOException; import java.io.InputStream; import java.net.URL; +import java.util.Collection; import java.util.HashMap; -import java.util.List; import java.util.Map; -import javax.xml.parsers.FactoryConfigurationError; -import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.DefaultHandler; - +import de.animux.android.andmal.api.MalList; +import de.animux.android.andmal.api.MalObject; +import de.animux.android.andmal.api.MalObjectStore; +import de.animux.android.andmal.api.MalState; import de.animux.android.andmal.api.anime.State; import de.animux.android.andmal.util.SortedLinkedList; -public class AnimeList extends DefaultHandler { +public class AnimeList extends MalList implements MalObjectStore<Anime> { - private Anime currentAnime; - private StringBuffer currentValue; + // cache last instance of this class to restore if a new one is created with + // the same username and password + private static AnimeList cache; - private HashMap<State,List<Anime>> animes; + private Map<MalState, Collection<MalObject>> animes; - public AnimeList(String user) throws IOException, - ParserConfigurationException, SAXException, - FactoryConfigurationError { - currentAnime = null; - currentValue = new StringBuffer(); - - animes = new HashMap<State, List<Anime>>(); - animes.put(State.WATCHING, new SortedLinkedList<Anime>()); - animes.put(State.COMPLETED, new SortedLinkedList<Anime>()); - animes.put(State.ONHOLD, new SortedLinkedList<Anime>()); - animes.put(State.DROPPED, new SortedLinkedList<Anime>()); - animes.put(State.PLANTOWATCH, new SortedLinkedList<Anime>()); - - URL url = new URL("http://myanimelist.net/malappinfo.php?status=all&type=anime&u=" + user); - InputStream stream = url.openStream(); - - SAXParser sax = SAXParserFactory.newInstance().newSAXParser(); - sax.parse(stream, this); - } + public AnimeList(String username, String password) { + super(username, password); - public Anime getCurrentAnime() { - return currentAnime; + if (((cache != null) && cache.getUsername().equals(username)) + && cache.getPassword().equals(username)) { + animes = cache.getObjects(); + } else { + cache = this; + needsRefresh = true; + } } - public StringBuffer getCurrentValue() { - return currentValue; - } + public AnimeList() { + super(); - public Map<State, List<Anime>> getAnimes() { - return animes; + if (cache != null && cache.getUsername() != null + && cache.getUsername().equals(this.getUsername())) { + animes = cache.getObjects(); + } + else { + cache = this; + needsRefresh = true; + } } @Override - public void characters(char[] ch, int start, int length) - throws SAXException { - currentValue.append(new String(ch).substring(start, length - start) - .replaceAll("&", "&")); + public void refresh() { + if (this.getUsername() == null) + return; + + animes = new HashMap<MalState, Collection<MalObject>>(); + animes.put(State.WATCHING, new SortedLinkedList<MalObject>()); + animes.put(State.COMPLETED, new SortedLinkedList<MalObject>()); + animes.put(State.ONHOLD, new SortedLinkedList<MalObject>()); + animes.put(State.DROPPED, new SortedLinkedList<MalObject>()); + animes.put(State.PLANTOWATCH, new SortedLinkedList<MalObject>()); + + try { + URL url = new URL( + "http://myanimelist.net/malappinfo.php?status=all&type=anime&u=" + + this.getUsername()); + InputStream stream = url.openStream(); + + SAXParser sax = SAXParserFactory.newInstance().newSAXParser(); + sax.parse(stream, new AnimeListParser(this)); + needsRefresh = false; + } catch (Exception e) { + e.printStackTrace(); + } } @Override - public void endElement(String uri, String localName, String qName) - throws SAXException { - - if (localName.equals("anime")) { - if (animes.containsKey(State.valueOf(currentAnime.getMyStatus()))) { - animes.get(State.valueOf(currentAnime.getMyStatus())).add(currentAnime); - } - - } else if (localName.equals("series_animedb_id")) { - currentAnime.setId(Integer.valueOf(currentValue.toString())); - } else if (localName.equals("series_title")) { - currentAnime.setTitle(currentValue.toString()); - } else if (localName.equals("series_synonyms")) { - currentAnime.setSynonyms(currentValue.toString()); - } else if (localName.equals("series_type")) { - currentAnime.setType(Integer.valueOf(currentValue.toString())); - } else if (localName.equals("series_episodes")) { - currentAnime.setEpisodes(Integer.valueOf(currentValue.toString())); - } else if (localName.equals("series_status")) { - currentAnime.setStatus(Integer.valueOf(currentValue.toString())); - } else if (localName.equals("series_start")) { - currentAnime.setStart(currentValue.toString()); - } else if (localName.equals("series_end")) { - currentAnime.setEnd(currentValue.toString()); - } else if (localName.equals("series_image")) { - currentAnime.setImage(currentValue.toString()); - } else if (localName.equals("my_id")) { - currentAnime.setMyId(Integer.valueOf(currentValue.toString())); - } else if (localName.equals("my_watched_episodes")) { - currentAnime.setWatchedEpisodes(Integer.valueOf(currentValue - .toString())); - } else if (localName.equals("my_status")) { - currentAnime.setMyStatus(Integer.valueOf(currentValue.toString())); + public void add(Anime object) { + if (animes.containsKey(State.valueOf(object.getMyStatus()))) { + animes.get(State.valueOf(object.getMyStatus())).add(object); } - - currentValue.setLength(0); } @Override - public void startElement(String uri, String localName, String qName, - Attributes attributes) throws SAXException { - - currentValue.setLength(0); - if (localName.equals("anime")) { - currentAnime = new Anime(); - } + public Map<MalState, Collection<MalObject>> getObjects() { + return animes; } } diff --git a/src/de/animux/android/andmal/api/anime/AnimeListParser.java b/src/de/animux/android/andmal/api/anime/AnimeListParser.java new file mode 100644 index 0000000..e7545dd --- /dev/null +++ b/src/de/animux/android/andmal/api/anime/AnimeListParser.java @@ -0,0 +1,45 @@ +package de.animux.android.andmal.api.anime; + +import de.animux.android.andmal.api.MalListParser; +import de.animux.android.andmal.api.MalObjectStore; + +public class AnimeListParser extends MalListParser<Anime> { + + private Anime currentAnime; + + public AnimeListParser(MalObjectStore<Anime> objectStore) { + super(objectStore); + currentAnime = new Anime(); + } + + public void addElement(String name, String value) { + if (name.equals("anime")) { + objectStore.add(currentAnime); + currentAnime = new Anime(); + } else if (name.equals("series_animedb_id")) { + currentAnime.setId(Integer.valueOf(value)); + } else if (name.equals("series_title")) { + currentAnime.setTitle(value); + } else if (name.equals("series_synonyms")) { + currentAnime.setSynonyms(value); + } else if (name.equals("series_type")) { + currentAnime.setType(Integer.valueOf(value)); + } else if (name.equals("series_episodes")) { + currentAnime.setEpisodes(Integer.valueOf(value)); + } else if (name.equals("series_status")) { + currentAnime.setStatus(Integer.valueOf(value)); + } else if (name.equals("series_start")) { + currentAnime.setStart(value); + } else if (name.equals("series_end")) { + currentAnime.setEnd(value); + } else if (name.equals("series_image")) { + currentAnime.setImage(value); + } else if (name.equals("my_id")) { + currentAnime.setMyId(Integer.valueOf(value)); + } else if (name.equals("my_watched_episodes")) { + currentAnime.setWatchedEpisodes(Integer.valueOf(value)); + } else if (name.equals("my_status")) { + currentAnime.setMyStatus(Integer.valueOf(value)); + } + } +} diff --git a/src/de/animux/android/andmal/api/anime/State.java b/src/de/animux/android/andmal/api/anime/State.java index 639b761..9ba4769 100644 --- a/src/de/animux/android/andmal/api/anime/State.java +++ b/src/de/animux/android/andmal/api/anime/State.java @@ -1,6 +1,8 @@ package de.animux.android.andmal.api.anime; -public enum State { +import de.animux.android.andmal.api.MalState; + +public enum State implements MalState { WATCHING (1, "Watching"), COMPLETED (2, "Completed"), ONHOLD (3, "On Hold"), diff --git a/src/de/animux/android/andmal/api/manga/Manga.java b/src/de/animux/android/andmal/api/manga/Manga.java new file mode 100644 index 0000000..25670df --- /dev/null +++ b/src/de/animux/android/andmal/api/manga/Manga.java @@ -0,0 +1,209 @@ +package de.animux.android.andmal.api.manga; + +import de.animux.android.andmal.api.MalObject; + +public class Manga extends MalObject { + + private int id; + private String title; + private String synonyms; + private int type; + private int chapters; + private int volumes; + private int status; + private String start; + private String end; + private String image; + + private int personalId; + private int personalReadChapters; + private int personalReadVolumes; + private String personalStart; + private String personalEnd; + private int personalScore; + private int personalStatus; + private int personalRereading; + private int personalRereadingChapters; + private int personalLastUpdated; + private String personalTags; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getSynonyms() { + return synonyms; + } + + public void setSynonyms(String synonyms) { + this.synonyms = synonyms; + } + + public int getType() { + return type; + } + + public void setType(int type) { + this.type = type; + } + + public int getChapters() { + return chapters; + } + + public void setChapters(int chapters) { + this.chapters = chapters; + } + + public int getVolumes() { + return volumes; + } + + public void setVolumes(int volumes) { + this.volumes = volumes; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public String getStart() { + return start; + } + + public void setStart(String start) { + this.start = start; + } + + public String getEnd() { + return end; + } + + public void setEnd(String end) { + this.end = end; + } + + public String getImage() { + return image; + } + + public void setImage(String image) { + this.image = image; + } + + public int getPersonalId() { + return personalId; + } + + public void setPersonalId(int personalId) { + this.personalId = personalId; + } + + public int getPersonalReadChapters() { + return personalReadChapters; + } + + public void setPersonalReadChapters(int personalReadChapters) { + this.personalReadChapters = personalReadChapters; + } + + public int getPersonalReadVolumes() { + return personalReadVolumes; + } + + public void setPersonalReadVolumes(int personalReadVolumes) { + this.personalReadVolumes = personalReadVolumes; + } + + public String getPersonalStart() { + return personalStart; + } + + public void setPersonalStart(String personalStart) { + this.personalStart = personalStart; + } + + public String getPersonalEnd() { + return personalEnd; + } + + public void setPersonalEnd(String personalEnd) { + this.personalEnd = personalEnd; + } + + public int getPersonalScore() { + return personalScore; + } + + public void setPersonalScore(int personalScore) { + this.personalScore = personalScore; + } + + public int getPersonalStatus() { + return personalStatus; + } + + public void setPersonalStatus(int personalStatus) { + this.personalStatus = personalStatus; + } + + public int getPersonalRereading() { + return personalRereading; + } + + public void setPersonalRereading(int personalRereading) { + this.personalRereading = personalRereading; + } + + public int getPersonalRereadingChapters() { + return personalRereadingChapters; + } + + public void setPersonalRereadingChapters(int personalRereadingChapters) { + this.personalRereadingChapters = personalRereadingChapters; + } + + public int getPersonalLastUpdated() { + return personalLastUpdated; + } + + public void setPersonalLastUpdated(int personalLastUpdated) { + this.personalLastUpdated = personalLastUpdated; + } + + public String getPersonalTags() { + return personalTags; + } + + public void setPersonalTags(String personalTags) { + this.personalTags = personalTags; + } + + @Override + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + @Override + public int compareTo(MalObject arg0) { + return 0; + } + + @Override + public String getProgress() { + return getPersonalReadChapters() + "/" + getChapters() + " (" + + getPersonalReadVolumes() + "/" + getVolumes() + ")"; + } +} diff --git a/src/de/animux/android/andmal/api/manga/MangaList.java b/src/de/animux/android/andmal/api/manga/MangaList.java new file mode 100644 index 0000000..00a89e4 --- /dev/null +++ b/src/de/animux/android/andmal/api/manga/MangaList.java @@ -0,0 +1,86 @@ +package de.animux.android.andmal.api.manga; + +import java.io.InputStream; +import java.net.URL; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + +import de.animux.android.andmal.api.MalList; +import de.animux.android.andmal.api.MalObject; +import de.animux.android.andmal.api.MalObjectStore; +import de.animux.android.andmal.api.MalState; +import de.animux.android.andmal.util.SortedLinkedList; + +public class MangaList extends MalList implements MalObjectStore<Manga> { + + // cache last instance of this class to restore if a new one is created with + // the same username and password + private static MangaList cache; + private Map<MalState, Collection<MalObject>> mangas; + + public MangaList(String username, String password) { + super(username, password); + + if (((cache != null) && cache.getUsername().equals(username)) + && cache.getPassword().equals(username)) { + mangas = cache.getObjects(); + } else { + cache = this; + needsRefresh = true; + } + } + + public MangaList() { + super(); + + if (cache != null && cache.getUsername() != null + && cache.getUsername().equals(this.getUsername())) { + mangas = cache.getObjects(); + } else { + cache = this; + needsRefresh = true; + } + } + + @Override + public void refresh() { + if (this.getUsername() == null) + return; + + mangas = new HashMap<MalState, Collection<MalObject>>(); + mangas.put(State.READING, new SortedLinkedList<MalObject>()); + mangas.put(State.COMPLETED, new SortedLinkedList<MalObject>()); + mangas.put(State.ONHOLD, new SortedLinkedList<MalObject>()); + mangas.put(State.DROPPED, new SortedLinkedList<MalObject>()); + mangas.put(State.PLANTOREAD, new SortedLinkedList<MalObject>()); + + try { + URL url = new URL( + "http://myanimelist.net/malappinfo.php?status=all&type=manga&u=" + + this.getUsername()); + InputStream stream = url.openStream(); + + SAXParser sax = SAXParserFactory.newInstance().newSAXParser(); + sax.parse(stream, new MangaListParser(this)); + needsRefresh = false; + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + public void add(Manga object) { + if (mangas.containsKey(State.valueOf(object.getPersonalStatus()))) { + mangas.get(State.valueOf(object.getPersonalStatus())).add(object); + } + } + + @Override + public Map<MalState, Collection<MalObject>> getObjects() { + return mangas; + } +} diff --git a/src/de/animux/android/andmal/api/manga/MangaListParser.java b/src/de/animux/android/andmal/api/manga/MangaListParser.java new file mode 100644 index 0000000..7e0ec4b --- /dev/null +++ b/src/de/animux/android/andmal/api/manga/MangaListParser.java @@ -0,0 +1,50 @@ +package de.animux.android.andmal.api.manga; + +import de.animux.android.andmal.api.MalListParser; +import de.animux.android.andmal.api.MalObjectStore; + +public class MangaListParser extends MalListParser<Manga> { + + private Manga currentManga; + + public MangaListParser(MalObjectStore<Manga> objectStore) { + super(objectStore); + currentManga = new Manga(); + } + + @Override + public void addElement(String name, String value) { + if (name.equals("manga")) { + objectStore.add(currentManga); + currentManga = new Manga(); + } else if (name.equals("series_mangadb_id")) { + currentManga.setId(Integer.valueOf(value)); + } else if (name.equals("series_title")) { + currentManga.setTitle(value); + } else if (name.equals("series_synonyms")) { + currentManga.setSynonyms(value); + } else if (name.equals("series_type")) { + currentManga.setType(Integer.valueOf(value)); + } else if (name.equals("series_chapters")) { + currentManga.setChapters(Integer.valueOf(value)); + } else if (name.equals("volumes")) { + currentManga.setVolumes(Integer.valueOf(value)); + } else if (name.equals("series_status")) { + currentManga.setStatus(Integer.valueOf(value)); + } else if (name.equals("series_start")) { + currentManga.setStart(value); + } else if (name.equals("series_end")) { + currentManga.setEnd(value); + } else if (name.equals("series_image")) { + currentManga.setImage(value); + } else if (name.equals("my_id")) { + currentManga.setPersonalId(Integer.valueOf(value)); + } else if (name.equals("my_read_chapters")) { + currentManga.setPersonalReadChapters(Integer.valueOf(value)); + } else if (name.equals("my_read_volumes")) { + currentManga.setPersonalReadVolumes(Integer.valueOf(value)); + } else if (name.equals("my_status")) { + currentManga.setPersonalStatus(Integer.valueOf(value)); + } + } +} diff --git a/src/de/animux/android/andmal/api/manga/State.java b/src/de/animux/android/andmal/api/manga/State.java new file mode 100644 index 0000000..a39fe78 --- /dev/null +++ b/src/de/animux/android/andmal/api/manga/State.java @@ -0,0 +1,38 @@ +package de.animux.android.andmal.api.manga; + +import de.animux.android.andmal.api.MalState; + +public enum State implements MalState { + READING (1, "Reading"), + COMPLETED (2, "Completed"), + ONHOLD (3, "On Hold"), + DROPPED (4, "Dropped"), + PLANTOREAD (6, "Plan to read"); + + private final int id; + private final String name; + + State(int id, String name) { + this.id = id; + this.name = name; + } + + @Override + public String toString() { + return name; + } + + public int getId() { + return id; + } + + static State valueOf(int id) { + for (State s : State.values()) { + if (s.getId() == id) { + return s; + } + } + + return null; + } +}
\ No newline at end of file |