|
From: <bur...@us...> - 2010-01-16 13:44:27
|
Revision: 6291
http://freecol.svn.sourceforge.net/freecol/?rev=6291&view=rev
Author: burschik
Date: 2010-01-16 13:44:20 +0000 (Sat, 16 Jan 2010)
Log Message:
-----------
Implement Comparable.
Modified Paths:
--------------
freecol/trunk/src/net/sf/freecol/common/model/Building.java
freecol/trunk/src/net/sf/freecol/common/model/BuildingType.java
freecol/trunk/src/net/sf/freecol/common/model/UnitType.java
Modified: freecol/trunk/src/net/sf/freecol/common/model/Building.java
===================================================================
--- freecol/trunk/src/net/sf/freecol/common/model/Building.java 2010-01-16 09:52:49 UTC (rev 6290)
+++ freecol/trunk/src/net/sf/freecol/common/model/Building.java 2010-01-16 13:44:20 UTC (rev 6291)
@@ -39,8 +39,10 @@
/**
* Represents a building in a colony.
*/
-public final class Building extends FreeColGameObject implements WorkLocation, Ownable, Named {
- private static Logger logger = Logger.getLogger(Building.class.getName());
+public final class Building extends FreeColGameObject implements WorkLocation, Ownable, Named,
+ Comparable<Building> {
+
+ private static Logger logger = Logger.getLogger(Building.class.getName());
public static final String UNIT_CHANGE = "UNIT_CHANGE";
@@ -985,14 +987,8 @@
buildingType, getGame().getTurn()));
}
- private static Comparator<Building> buildingComparator = new Comparator<Building>() {
- public int compare(Building b1, Building b2) {
- return b1.getType().getSequence() - b2.getType().getSequence();
- }
- };
-
- public static Comparator<Building> getBuildingComparator() {
- return buildingComparator;
+ public int compareTo(Building other) {
+ return getType().compareTo(other.getType());
}
/**
Modified: freecol/trunk/src/net/sf/freecol/common/model/BuildingType.java
===================================================================
--- freecol/trunk/src/net/sf/freecol/common/model/BuildingType.java 2010-01-16 09:52:49 UTC (rev 6290)
+++ freecol/trunk/src/net/sf/freecol/common/model/BuildingType.java 2010-01-16 13:44:20 UTC (rev 6291)
@@ -32,7 +32,7 @@
* given building type can have. The levels contain the information about the
* name of the building in a given level and what is needed to build it.
*/
-public final class BuildingType extends BuildableType {
+public final class BuildingType extends BuildableType implements Comparable<BuildingType> {
private int level;
@@ -101,6 +101,10 @@
return productionModifier;
}
+ public int compareTo(BuildingType other) {
+ return getIndex() - other.getIndex();
+ }
+
public void readAttributes(XMLStreamReader in, Specification specification) throws XMLStreamException {
if (hasAttribute(in, "upgradesFrom")) {
upgradesFrom = specification.getBuildingType(in.getAttributeValue(null, "upgradesFrom"));
Modified: freecol/trunk/src/net/sf/freecol/common/model/UnitType.java
===================================================================
--- freecol/trunk/src/net/sf/freecol/common/model/UnitType.java 2010-01-16 09:52:49 UTC (rev 6290)
+++ freecol/trunk/src/net/sf/freecol/common/model/UnitType.java 2010-01-16 13:44:20 UTC (rev 6291)
@@ -33,7 +33,7 @@
import net.sf.freecol.common.Specification;
import net.sf.freecol.common.model.UnitTypeChange.ChangeType;
-public final class UnitType extends BuildableType {
+public final class UnitType extends BuildableType implements Comparable<UnitType> {
public static final int DEFAULT_OFFENCE = 0;
public static final int DEFAULT_DEFENCE = 1;
@@ -498,6 +498,11 @@
this.foodConsumed = newFoodConsumed;
}
+
+ public int compareTo(UnitType other) {
+ return getIndex() - other.getIndex();
+ }
+
/**
* Returns true if the UnitType is available to the given
* Player.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|