diff options
author | Bananeweizen <bananeweizen@gmx.de> | 2012-04-19 08:13:50 +0200 |
---|---|---|
committer | Bananeweizen <bananeweizen@gmx.de> | 2012-04-19 08:13:50 +0200 |
commit | 8e0b242e12d93ef2ee350819eda71a4148a4164e (patch) | |
tree | 6a5abfde85a03aa519628051b5fde0c02c309ce3 /main/src/cgeo/geocaching/LogEntry.java | |
parent | 580e98d2f6b89c001fb69626d67a778717e049a1 (diff) | |
download | cgeo-8e0b242e12d93ef2ee350819eda71a4148a4164e.zip cgeo-8e0b242e12d93ef2ee350819eda71a4148a4164e.tar.gz cgeo-8e0b242e12d93ef2ee350819eda71a4148a4164e.tar.bz2 |
refactoring: renames and encapsulation
Diffstat (limited to 'main/src/cgeo/geocaching/LogEntry.java')
-rw-r--r-- | main/src/cgeo/geocaching/LogEntry.java | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/LogEntry.java b/main/src/cgeo/geocaching/LogEntry.java new file mode 100644 index 0000000..3f6ed74 --- /dev/null +++ b/main/src/cgeo/geocaching/LogEntry.java @@ -0,0 +1,69 @@ +package cgeo.geocaching; + +import cgeo.geocaching.enumerations.LogType; + +import org.apache.commons.collections.CollectionUtils; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public final class LogEntry { + /** + * avoid creating new empty lists all the time using this constant. We could also return Collections.EMPTY_LIST + * using a cast, but that might trigger static code analysis tools. + */ + private static final List<cgImage> EMPTY_LIST = Collections.emptyList(); + public int id = 0; + public LogType type = LogType.LOG_NOTE; // note + public String author = ""; + public String log = ""; + public long date = 0; + public int found = -1; + /** Friend's log entry */ + public boolean friend = false; + private List<cgImage> logImages = null; + public String cacheName = ""; // used for trackables + public String cacheGuid = ""; // used for trackables + + @Override + public int hashCode() { + return (int) date * type.hashCode() * author.hashCode() * log.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof LogEntry)) { + return false; + } + final LogEntry otherLog = (LogEntry) obj; + return date == otherLog.date && + type == otherLog.type && + author.compareTo(otherLog.author) == 0 && + log.compareTo(otherLog.log) == 0; + } + + public void addLogImage(final cgImage image) { + if (logImages == null) { + logImages = new ArrayList<cgImage>(); + } + logImages.add(image); + } + + /** + * @return the log images or an empty list, never <code>null</code> + */ + public List<cgImage> getLogImages() { + if (logImages == null) { + return EMPTY_LIST; + } + return logImages; + } + + public boolean hasLogImages() { + return CollectionUtils.isNotEmpty(logImages); + } +} |