diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2011-09-16 14:36:28 +0200 |
|---|---|---|
| committer | Samuel Tardieu <sam@rfc1149.net> | 2011-09-16 14:36:28 +0200 |
| commit | 579ef7a535489d4aa632db11667a3b01deb6cafd (patch) | |
| tree | 55810021c02ac7d80d3a9702ef0b59e4af154b9c /src/cgeo/geocaching/sorting | |
| parent | 96ea21fd50334479c262da692038965d0e4d596a (diff) | |
| download | cgeo-579ef7a535489d4aa632db11667a3b01deb6cafd.zip cgeo-579ef7a535489d4aa632db11667a3b01deb6cafd.tar.gz cgeo-579ef7a535489d4aa632db11667a3b01deb6cafd.tar.bz2 | |
Move sources into the main directory
This prepares the inclusion of tests into the same repository.
Diffstat (limited to 'src/cgeo/geocaching/sorting')
16 files changed, 0 insertions, 477 deletions
diff --git a/src/cgeo/geocaching/sorting/AbstractCacheComparator.java b/src/cgeo/geocaching/sorting/AbstractCacheComparator.java deleted file mode 100644 index 03db8df..0000000 --- a/src/cgeo/geocaching/sorting/AbstractCacheComparator.java +++ /dev/null @@ -1,46 +0,0 @@ -package cgeo.geocaching.sorting; - -import cgeo.geocaching.cgCache; -import cgeo.geocaching.cgSettings; - -import android.util.Log; - -/** - * abstract super implementation for all cache comparators - * - */ -public abstract class AbstractCacheComparator implements CacheComparator { - - @Override - public final int compare(cgCache cache1, cgCache cache2) { - try { - // first check that we have all necessary data for the comparison - if (!canCompare(cache1, cache2)) { - return 0; - } - return compareCaches(cache1, cache2); - } catch (Exception e) { - Log.e(cgSettings.tag, "AbstractCacheComparator.compare: " + e.toString()); - } - return 0; - } - - /** - * check necessary preconditions (like missing fields) before running the comparison itself - * - * @param cache1 - * @param cache2 - * @return - */ - protected abstract boolean canCompare(final cgCache cache1, final cgCache cache2); - - /** - * compares two caches. Logging and exception handling is implemented outside this method already. - * - * @param cache1 - * @param cache2 - * @return an integer < 0 if cache1 is less than cache2, 0 if they are equal, and > 0 if cache1 is greater than - * cache2. - */ - protected abstract int compareCaches(final cgCache cache1, final cgCache cache2); -} diff --git a/src/cgeo/geocaching/sorting/CacheComparator.java b/src/cgeo/geocaching/sorting/CacheComparator.java deleted file mode 100644 index c9b5150..0000000 --- a/src/cgeo/geocaching/sorting/CacheComparator.java +++ /dev/null @@ -1,9 +0,0 @@ -package cgeo.geocaching.sorting; - -import java.util.Comparator; - -import cgeo.geocaching.cgCache; - -public interface CacheComparator extends Comparator<cgCache> { - -} diff --git a/src/cgeo/geocaching/sorting/DateComparator.java b/src/cgeo/geocaching/sorting/DateComparator.java deleted file mode 100644 index b59e84e..0000000 --- a/src/cgeo/geocaching/sorting/DateComparator.java +++ /dev/null @@ -1,35 +0,0 @@ -package cgeo.geocaching.sorting; - -import cgeo.geocaching.cgCache; - -import java.util.Date; - -/** - * compares caches by date - * - * @author bananeweizen - * - */ -public class DateComparator extends AbstractCacheComparator { - - @Override - protected boolean canCompare(cgCache cache1, cgCache cache2) { - return true; - } - - @Override - protected int compareCaches(cgCache cache1, cgCache cache2) { - Date date1 = cache1.hidden; - Date date2 = cache2.hidden; - if (date1 != null && date2 != null) { - return date1.compareTo(date2); - } - if (date1 != null) { - return -1; - } - if (date2 != null) { - return 1; - } - return 0; - } -} diff --git a/src/cgeo/geocaching/sorting/DifficultyComparator.java b/src/cgeo/geocaching/sorting/DifficultyComparator.java deleted file mode 100644 index 846417c..0000000 --- a/src/cgeo/geocaching/sorting/DifficultyComparator.java +++ /dev/null @@ -1,25 +0,0 @@ -package cgeo.geocaching.sorting; - -import cgeo.geocaching.cgCache; - -/** - * sorts caches by difficulty - * - */ -public class DifficultyComparator extends AbstractCacheComparator { - - @Override - protected boolean canCompare(cgCache cache1, cgCache cache2) { - return cache1.difficulty != null && cache2.difficulty != null; - } - - @Override - protected int compareCaches(final cgCache cache1, final cgCache cache2) { - if (cache1.difficulty > cache2.difficulty) { - return 1; - } else if (cache2.difficulty > cache1.difficulty) { - return -1; - } - return 0; - } -}
\ No newline at end of file diff --git a/src/cgeo/geocaching/sorting/DistanceComparator.java b/src/cgeo/geocaching/sorting/DistanceComparator.java deleted file mode 100644 index 7051718..0000000 --- a/src/cgeo/geocaching/sorting/DistanceComparator.java +++ /dev/null @@ -1,40 +0,0 @@ -package cgeo.geocaching.sorting; - -import cgeo.geocaching.cgCache; -import cgeo.geocaching.geopoint.Geopoint; - -/** - * sorts caches by distance to current position - * - */ -public class DistanceComparator extends AbstractCacheComparator { - private final Geopoint coords; - - public DistanceComparator(final Geopoint coords) { - this.coords = coords; - } - - @Override - protected boolean canCompare(cgCache cache1, cgCache cache2) { - return true; - } - - @Override - protected int compareCaches(final cgCache cache1, final cgCache cache2) { - if ((cache1.coords == null || cache2.coords == null) - && cache1.distance != null && cache2.distance != null) { - return Double.compare(cache1.distance, cache2.distance); - } else { - if (cache1.coords == null) { - return 1; - } - if (cache2.coords == null) { - return -1; - } - - return Float.compare(coords.distanceTo(cache1.coords), - coords.distanceTo(cache2.coords)); - } - } - -} diff --git a/src/cgeo/geocaching/sorting/FindsComparator.java b/src/cgeo/geocaching/sorting/FindsComparator.java deleted file mode 100644 index efde22d..0000000 --- a/src/cgeo/geocaching/sorting/FindsComparator.java +++ /dev/null @@ -1,40 +0,0 @@ -package cgeo.geocaching.sorting; - -import cgeo.geocaching.cgBase; -import cgeo.geocaching.cgCache; -import cgeo.geocaching.cgeoapplication; - -public class FindsComparator extends AbstractCacheComparator implements - CacheComparator { - - private cgeoapplication app; - - public FindsComparator(cgeoapplication app) { - this.app = app; - } - - @Override - protected boolean canCompare(cgCache cache1, cgCache cache2) { - return cache1.logCounts != null && cache2.logCounts != null; - } - - @Override - protected int compareCaches(cgCache cache1, cgCache cache2) { - int finds1 = getFindsCount(cache1); - int finds2 = getFindsCount(cache2); - return finds2 - finds1; - } - - private int getFindsCount(cgCache cache) { - int finds = 0; - if (cache.logCounts.isEmpty()) { - cache.logCounts = app.loadLogCounts(cache.geocode); - } - Integer logged = cache.logCounts.get(cgBase.LOG_FOUND_IT); - if (logged != null) { - finds = logged; - } - return finds; - } - -} diff --git a/src/cgeo/geocaching/sorting/GeocodeComparator.java b/src/cgeo/geocaching/sorting/GeocodeComparator.java deleted file mode 100644 index 136d7f5..0000000 --- a/src/cgeo/geocaching/sorting/GeocodeComparator.java +++ /dev/null @@ -1,28 +0,0 @@ -package cgeo.geocaching.sorting; - -import cgeo.geocaching.cgCache; - -import org.apache.commons.lang3.StringUtils; - -/** - * sorts caches by GC code, therefore effectively sorting by cache age - * - */ -public class GeocodeComparator extends AbstractCacheComparator { - - @Override - protected boolean canCompare(cgCache cache1, cgCache cache2) { - return StringUtils.isNotBlank(cache1.geocode) - && StringUtils.isNotBlank(cache2.geocode); - } - - @Override - protected int compareCaches(cgCache cache1, cgCache cache2) { - if (cache1.geocode.length() > cache2.geocode.length()) { - return 1; - } else if (cache2.geocode.length() > cache1.geocode.length()) { - return -1; - } - return cache1.geocode.compareToIgnoreCase(cache2.geocode); - } -} diff --git a/src/cgeo/geocaching/sorting/InventoryComparator.java b/src/cgeo/geocaching/sorting/InventoryComparator.java deleted file mode 100644 index 0833094..0000000 --- a/src/cgeo/geocaching/sorting/InventoryComparator.java +++ /dev/null @@ -1,29 +0,0 @@ -package cgeo.geocaching.sorting; - -import cgeo.geocaching.cgCache; - -/** - * sorts caches by number of items in inventory - * - * @author bananeweizen - * - */ -public class InventoryComparator extends AbstractCacheComparator { - - @Override - protected boolean canCompare(cgCache cache1, cgCache cache2) { - return true; - } - - @Override - protected int compareCaches(cgCache cache1, cgCache cache2) { - int itemCount1 = cache1.inventoryItems; - int itemCount2 = cache2.inventoryItems; - if (itemCount1 < itemCount2) { - return 1; - } else if (itemCount2 < itemCount1) { - return -1; - } - return 0; - } -} diff --git a/src/cgeo/geocaching/sorting/NameComparator.java b/src/cgeo/geocaching/sorting/NameComparator.java deleted file mode 100644 index d301180..0000000 --- a/src/cgeo/geocaching/sorting/NameComparator.java +++ /dev/null @@ -1,22 +0,0 @@ -package cgeo.geocaching.sorting; - -import cgeo.geocaching.cgCache; - -import org.apache.commons.lang3.StringUtils; - -/** - * sorts caches by name - * - */ -public class NameComparator extends AbstractCacheComparator { - - @Override - protected boolean canCompare(cgCache cache1, cgCache cache2) { - return StringUtils.isNotBlank(cache1.name) && StringUtils.isNotBlank(cache2.name); - } - - @Override - protected int compareCaches(cgCache cache1, cgCache cache2) { - return cache1.name.compareToIgnoreCase(cache2.name); - } -} diff --git a/src/cgeo/geocaching/sorting/PopularityComparator.java b/src/cgeo/geocaching/sorting/PopularityComparator.java deleted file mode 100644 index dbc418a..0000000 --- a/src/cgeo/geocaching/sorting/PopularityComparator.java +++ /dev/null @@ -1,25 +0,0 @@ -package cgeo.geocaching.sorting; - -import cgeo.geocaching.cgCache; - -/** - * sorts caches by popularity (favorite count) - * - */ -public class PopularityComparator extends AbstractCacheComparator { - - @Override - protected boolean canCompare(cgCache cache1, cgCache cache2) { - return cache1.favouriteCnt != null && cache2.favouriteCnt != null; - } - - @Override - protected int compareCaches(cgCache cache1, cgCache cache2) { - if (cache1.favouriteCnt < cache2.favouriteCnt) { - return 1; - } else if (cache2.favouriteCnt < cache1.favouriteCnt) { - return -1; - } - return 0; - } -} diff --git a/src/cgeo/geocaching/sorting/RatingComparator.java b/src/cgeo/geocaching/sorting/RatingComparator.java deleted file mode 100644 index b7140c6..0000000 --- a/src/cgeo/geocaching/sorting/RatingComparator.java +++ /dev/null @@ -1,36 +0,0 @@ -package cgeo.geocaching.sorting; - -import cgeo.geocaching.cgCache; - -/** - * sorts caches by gcvote.com rating - * - */ -public class RatingComparator extends AbstractCacheComparator { - - @Override - protected boolean canCompare(cgCache cache1, cgCache cache2) { - return cache1.rating != null && cache2.rating != null; - } - - @Override - protected int compareCaches(cgCache cache1, cgCache cache2) { - Float rating1 = cache1.rating; - Float rating2 = cache2.rating; - - // voting can be disabled for caches, then assume an average rating instead - if (rating1 == 0.0) { - rating1 = 2.5f; - } - if (rating2 == 0.0) { - rating2 = 2.5f; - } - - if (rating1 < rating2) { - return 1; - } else if (rating2 < rating1) { - return -1; - } - return 0; - } -}
\ No newline at end of file diff --git a/src/cgeo/geocaching/sorting/SizeComparator.java b/src/cgeo/geocaching/sorting/SizeComparator.java deleted file mode 100644 index a633a06..0000000 --- a/src/cgeo/geocaching/sorting/SizeComparator.java +++ /dev/null @@ -1,20 +0,0 @@ -package cgeo.geocaching.sorting; - -import cgeo.geocaching.cgCache; - -/** - * sorts caches by size - * - */ -public class SizeComparator extends AbstractCacheComparator { - - @Override - protected boolean canCompare(cgCache cache1, cgCache cache2) { - return cache1.size != null && cache2.size != null; - } - - @Override - protected int compareCaches(cgCache cache1, cgCache cache2) { - return cache2.size.comparable - cache1.size.comparable; - } -}
\ No newline at end of file diff --git a/src/cgeo/geocaching/sorting/StateComparator.java b/src/cgeo/geocaching/sorting/StateComparator.java deleted file mode 100644 index f56d3fe..0000000 --- a/src/cgeo/geocaching/sorting/StateComparator.java +++ /dev/null @@ -1,32 +0,0 @@ -package cgeo.geocaching.sorting; - -import cgeo.geocaching.cgCache; - -/** - * sort caches by state (normal, disabled, archived) - * - */ -public class StateComparator extends AbstractCacheComparator implements - CacheComparator { - - @Override - protected boolean canCompare(final cgCache cache1, final cgCache cache2) { - return true; - } - - @Override - protected int compareCaches(final cgCache cache1, final cgCache cache2) { - return getState(cache1) - getState(cache2); - } - - private static int getState(final cgCache cache) { - if (cache.disabled) { - return 1; - } - if (cache.archived) { - return 2; - } - return 0; - } - -} diff --git a/src/cgeo/geocaching/sorting/TerrainComparator.java b/src/cgeo/geocaching/sorting/TerrainComparator.java deleted file mode 100644 index 88c75e4..0000000 --- a/src/cgeo/geocaching/sorting/TerrainComparator.java +++ /dev/null @@ -1,25 +0,0 @@ -package cgeo.geocaching.sorting; - -import cgeo.geocaching.cgCache; - -/** - * sorts caches by terrain rating - * - */ -public class TerrainComparator extends AbstractCacheComparator { - - @Override - protected boolean canCompare(cgCache cache1, cgCache cache2) { - return cache1.terrain != null && cache2.terrain != null; - } - - @Override - protected int compareCaches(cgCache cache1, cgCache cache2) { - if (cache1.terrain > cache2.terrain) { - return 1; - } else if (cache2.terrain > cache1.terrain) { - return -1; - } - return 0; - } -} diff --git a/src/cgeo/geocaching/sorting/VisitComparator.java b/src/cgeo/geocaching/sorting/VisitComparator.java deleted file mode 100644 index 597efb5..0000000 --- a/src/cgeo/geocaching/sorting/VisitComparator.java +++ /dev/null @@ -1,26 +0,0 @@ -package cgeo.geocaching.sorting; - -import cgeo.geocaching.cgCache; - -/** - * sorts caches by last visited date - * - */ -public class VisitComparator extends AbstractCacheComparator { - - @Override - protected boolean canCompare(cgCache cache1, cgCache cache2) { - return cache1.visitedDate != null && cache1.visitedDate > 0 - && cache2.visitedDate != null && cache2.visitedDate > 0; - } - - @Override - protected int compareCaches(cgCache cache1, cgCache cache2) { - if (cache1.visitedDate > cache2.visitedDate) { - return -1; - } else if (cache1.visitedDate < cache2.visitedDate) { - return 1; - } - return 0; - } -} diff --git a/src/cgeo/geocaching/sorting/VoteComparator.java b/src/cgeo/geocaching/sorting/VoteComparator.java deleted file mode 100644 index 2a4b4ac..0000000 --- a/src/cgeo/geocaching/sorting/VoteComparator.java +++ /dev/null @@ -1,39 +0,0 @@ -package cgeo.geocaching.sorting; - -import cgeo.geocaching.cgCache; - -/** - * sorts caches by the users own voting (if available at all) - * - * @author bananeweizen - * - */ -public class VoteComparator extends AbstractCacheComparator { - - @Override - protected boolean canCompare(cgCache cache1, cgCache cache2) { - return true; - } - - @Override - protected int compareCaches(cgCache cache1, cgCache cache2) { - // if there is no vote available, put that cache at the end of the list - float vote1 = 0; - if (cache1.myVote != null) { - vote1 = cache1.myVote; - } - - float vote2 = 0; - if (cache2.myVote != null) { - vote2 = cache2.myVote; - } - - // compare - if (vote1 < vote2) { - return 1; - } else if (vote2 < vote1) { - return -1; - } - return 0; - } -} |
