Sort FlightDataTypes on group priority first, then on priority of FlightDataType. Don't sort on name

This commit is contained in:
JoePfeiffer 2024-06-01 18:02:17 -06:00
parent 942d273c8d
commit eb055cfeec
2 changed files with 27 additions and 12 deletions

View File

@ -392,14 +392,14 @@ public class FlightDataType implements Comparable<FlightDataType> {
// if something has changed, then we need to remove the old one // if something has changed, then we need to remove the old one
// otherwise, just return what we found // otherwise, just return what we found
if (!u.equals(type.getUnitGroup())) { if (!u.equals(type.getUnitGroup())) {
oldPriority = type.groupPriority; oldPriority = type.priority;
EXISTING_TYPES.remove(type); EXISTING_TYPES.remove(type);
log.info("Unitgroup of type " + type.getName() + log.info("Unitgroup of type " + type.getName() +
", has changed from " + type.getUnitGroup().toString() + ", has changed from " + type.getUnitGroup().toString() +
" to " + u.toString() + " to " + u.toString() +
". Removing old version."); ". Removing old version.");
} else if (!s.equals(type.getName())) { } else if (!s.equals(type.getName())) {
oldPriority = type.groupPriority; oldPriority = type.priority;
EXISTING_TYPES.remove(type); EXISTING_TYPES.remove(type);
log.info("Name of type " + type.getName() + ", has changed to " + s + ". Removing old version."); log.info("Name of type " + type.getName() + ", has changed to " + s + ". Removing old version.");
} else { } else {
@ -459,7 +459,7 @@ public class FlightDataType implements Comparable<FlightDataType> {
private final String symbol; private final String symbol;
private final UnitGroup units; private final UnitGroup units;
private final FlightDataTypeGroup group; private final FlightDataTypeGroup group;
private final int groupPriority; private final int priority;
private final int hashCode; private final int hashCode;
private FlightDataType(String typeName, String symbol, UnitGroup units, FlightDataTypeGroup group, int priority) { private FlightDataType(String typeName, String symbol, UnitGroup units, FlightDataTypeGroup group, int priority) {
@ -471,7 +471,7 @@ public class FlightDataType implements Comparable<FlightDataType> {
this.symbol = symbol; this.symbol = symbol;
this.units = units; this.units = units;
this.group = group; this.group = group;
this.groupPriority = priority; this.priority = priority;
this.hashCode = this.name.toLowerCase(Locale.ENGLISH).hashCode(); this.hashCode = this.name.toLowerCase(Locale.ENGLISH).hashCode();
} }
@ -492,7 +492,7 @@ public class FlightDataType implements Comparable<FlightDataType> {
} }
public int getGroupPriority() { public int getGroupPriority() {
return groupPriority; return group.getPriority();
} }
@Override @Override
@ -501,10 +501,10 @@ public class FlightDataType implements Comparable<FlightDataType> {
} }
@Override @Override
public boolean equals(Object other) { public boolean equals(Object o) {
if (!(other instanceof FlightDataType)) if (!(o instanceof FlightDataType))
return false; return false;
return this.name.equalsIgnoreCase(((FlightDataType) other).name); return this.compareTo((FlightDataType) o) == 0;
} }
@Override @Override
@ -514,8 +514,11 @@ public class FlightDataType implements Comparable<FlightDataType> {
@Override @Override
public int compareTo(FlightDataType o) { public int compareTo(FlightDataType o) {
if (this.groupPriority != o.groupPriority) final int groupCompare = this.getGroup().compareTo(o.getGroup());
return this.groupPriority - o.groupPriority; if (groupCompare != 0) {
return this.name.compareToIgnoreCase(o.name); return groupCompare;
}
return this.priority - o.priority;
} }
} }

View File

@ -3,7 +3,7 @@ package info.openrocket.core.simulation;
import info.openrocket.core.l10n.Translator; import info.openrocket.core.l10n.Translator;
import info.openrocket.core.startup.Application; import info.openrocket.core.startup.Application;
public class FlightDataTypeGroup { public class FlightDataTypeGroup implements Comparable<FlightDataTypeGroup> {
private static final Translator trans = Application.getTranslator(); private static final Translator trans = Application.getTranslator();
public static final FlightDataTypeGroup TIME = new FlightDataTypeGroup(trans.get("FlightDataTypeGroup.GROUP_TIME"), 0); public static final FlightDataTypeGroup TIME = new FlightDataTypeGroup(trans.get("FlightDataTypeGroup.GROUP_TIME"), 0);
@ -56,4 +56,16 @@ public class FlightDataTypeGroup {
public String toString() { public String toString() {
return getName(); return getName();
} }
@Override
public boolean equals(Object o) {
if (!(o instanceof FlightDataTypeGroup))
return false;
return this.compareTo((FlightDataTypeGroup) o) == 0;
}
@Override
public int compareTo(FlightDataTypeGroup o) {
return this.priority - o.priority;
}
} }