Skip to content

Commit

Permalink
Bug Fix: Made string columns sorting case insensitive (Issue #506)
Browse files Browse the repository at this point in the history
  • Loading branch information
GoldenGnu committed Dec 20, 2024
1 parent e529062 commit 921a1f0
Show file tree
Hide file tree
Showing 30 changed files with 588 additions and 558 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -460,25 +460,19 @@ private Set<PriceChange> selectPriceChanges(Map<Integer, Long> typeIDs, boolean
priceData.setBuyAvg(rs.getDouble("buyavg"));
priceData.setBuyMedian(rs.getDouble("buymedian"));
priceData.setBuyMin(rs.getDouble("buymin"));
try {
PriceChange priceChange = data.get(typeID);
double price = PriceMode.getDefaultPrice(priceData, priceMode);
if (priceChange == null) {
Item item = ApiIdConverter.getItem(typeID);
priceChange = new PriceChange(typeID, item, typeIDs.getOrDefault(typeID, 0L));
data.put(typeID, priceChange);
}
if (date.equals(fromString)) {
priceChange.setPriceFrom(price);
} else if (date.equals(toString)) {
priceChange.setPriceTo(price);
} else {
LOG.warn("Date is don't equals to or from???");
}


} catch (ParseException ex) {
//Ignore
PriceChange priceChange = data.get(typeID);
double price = PriceMode.getDefaultPrice(priceData, priceMode);
if (priceChange == null) {
Item item = ApiIdConverter.getItem(typeID);
priceChange = new PriceChange(typeID, item, typeIDs.getOrDefault(typeID, 0L));
data.put(typeID, priceChange);
}
if (date.equals(fromString)) {
priceChange.setPriceFrom(price);
} else if (date.equals(toString)) {
priceChange.setPriceTo(price);
} else {
LOG.warn("Date is don't equals to or from???");
}
}
} catch (SQLException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

package net.nikr.eve.jeveasset.gui.dialogs.account;

import ca.odell.glazedlists.GlazedLists;
import java.util.Comparator;
import net.nikr.eve.jeveasset.data.api.accounts.OwnerType;
import net.nikr.eve.jeveasset.gui.shared.table.EnumTableColumn;
Expand All @@ -31,7 +30,7 @@


public enum AccountTableFormat implements EnumTableColumn<OwnerType> {
SHOW_ASSETS(Boolean.class, GlazedLists.comparableComparator()) {
SHOW_ASSETS(Boolean.class) {
@Override
public String getColumnName() {
return "";
Expand Down Expand Up @@ -60,7 +59,7 @@ public boolean setColumnValue(final Object baseObject, final Object editedValue)
return false;
}
},
NAME(String.class, GlazedLists.comparableComparator()) {
NAME(String.class) {
@Override
public String getColumnName() {
return DialoguesAccount.get().tableFormatName();
Expand All @@ -70,7 +69,7 @@ public Object getColumnValue(final OwnerType from) {
return from.getOwnerName();
}
},
CORPORATION(YesNo.class, GlazedLists.comparableComparator()) {
CORPORATION(YesNo.class) {
@Override
public String getColumnName() {
return DialoguesAccount.get().tableFormatCorporation();
Expand All @@ -80,7 +79,7 @@ public Object getColumnValue(final OwnerType from) {
return new YesNo(from.isCorporation());
}
},
ASSET_LIST(YesNo.class, GlazedLists.comparableComparator()) {
ASSET_LIST(YesNo.class) {
@Override
public String getColumnName() {
return DialoguesAccount.get().tableFormatAssetList();
Expand All @@ -90,7 +89,7 @@ public Object getColumnValue(final OwnerType from) {
return new YesNo(from.isAssetList());
}
},
ACCOUNT_BALANCE(YesNo.class, GlazedLists.comparableComparator()) {
ACCOUNT_BALANCE(YesNo.class) {
@Override
public String getColumnName() {
return DialoguesAccount.get().tableFormatAccountBalance();
Expand All @@ -100,7 +99,7 @@ public Object getColumnValue(final OwnerType from) {
return new YesNo(from.isAccountBalance());
}
},
INDUSTRY_JOBS(YesNo.class, GlazedLists.comparableComparator()) {
INDUSTRY_JOBS(YesNo.class) {
@Override
public String getColumnName() {
return DialoguesAccount.get().tableFormatIndustryJobs();
Expand All @@ -110,7 +109,7 @@ public Object getColumnValue(final OwnerType from) {
return new YesNo(from.isIndustryJobs());
}
},
MARKET_ORDERS(YesNo.class, GlazedLists.comparableComparator()) {
MARKET_ORDERS(YesNo.class) {
@Override
public String getColumnName() {
return DialoguesAccount.get().tableFormatMarketOrders();
Expand All @@ -120,7 +119,7 @@ public Object getColumnValue(final OwnerType from) {
return new YesNo(from.isMarketOrders());
}
},
TRANSACTIONS(YesNo.class, GlazedLists.comparableComparator()) {
TRANSACTIONS(YesNo.class) {
@Override
public String getColumnName() {
return DialoguesAccount.get().tableFormatTransactions();
Expand All @@ -130,7 +129,7 @@ public Object getColumnValue(final OwnerType from) {
return new YesNo(from.isTransactions());
}
},
JOURNAL(YesNo.class, GlazedLists.comparableComparator()) {
JOURNAL(YesNo.class) {
@Override
public String getColumnName() {
return DialoguesAccount.get().tableFormatJournal();
Expand All @@ -140,7 +139,7 @@ public Object getColumnValue(final OwnerType from) {
return new YesNo(from.isJournal());
}
},
CONTRACTS(YesNo.class, GlazedLists.comparableComparator()) {
CONTRACTS(YesNo.class) {
@Override
public String getColumnName() {
return DialoguesAccount.get().tableFormatContracts();
Expand All @@ -150,7 +149,7 @@ public Object getColumnValue(final OwnerType from) {
return new YesNo(from.isContracts());
}
},
LOCATIONS(YesNo.class, GlazedLists.comparableComparator()) {
LOCATIONS(YesNo.class) {
@Override
public String getColumnName() {
return DialoguesAccount.get().tableFormatLocations();
Expand All @@ -160,7 +159,7 @@ public Object getColumnValue(final OwnerType from) {
return new YesNo(from.isLocations());
}
},
STRUCTURES(YesNo.class, GlazedLists.comparableComparator()) {
STRUCTURES(YesNo.class) {
@Override
public String getColumnName() {
return DialoguesAccount.get().tableFormatStructures();
Expand All @@ -170,7 +169,7 @@ public Object getColumnValue(final OwnerType from) {
return new YesNo(from.isStructures());
}
},
MARKET_STRUCTURES(YesNo.class, GlazedLists.comparableComparator()) {
MARKET_STRUCTURES(YesNo.class) {
@Override
public String getColumnName() {
return DialoguesAccount.get().tableFormatMarketStructures();
Expand All @@ -180,7 +179,7 @@ public Object getColumnValue(final OwnerType from) {
return new YesNo(from.isMarketStructures());
}
},
BOOKMARKS(YesNo.class, GlazedLists.comparableComparator()) {
BOOKMARKS(YesNo.class) {
@Override
public String getColumnName() {
return DialoguesAccount.get().tableFormatBookmarks();
Expand All @@ -190,7 +189,7 @@ public Object getColumnValue(final OwnerType from) {
return new YesNo(from.isBookmarks());
}
},
BLUEPRINTS(YesNo.class, GlazedLists.comparableComparator()) {
BLUEPRINTS(YesNo.class) {
@Override
public String getColumnName() {
return DialoguesAccount.get().tableFormatBlueprints();
Expand All @@ -200,7 +199,7 @@ public Object getColumnValue(final OwnerType from) {
return new YesNo(from.isBlueprints());
}
},
DIVISIONS(YesNo.class, GlazedLists.comparableComparator()) {
DIVISIONS(YesNo.class) {
@Override
public String getColumnName() {
return DialoguesAccount.get().tableFormatDivisions();
Expand All @@ -210,7 +209,7 @@ public Object getColumnValue(final OwnerType from) {
return new YesNo(from.isDivisions());
}
},
SHIP(YesNo.class, GlazedLists.comparableComparator()) {
SHIP(YesNo.class) {
@Override
public String getColumnName() {
return DialoguesAccount.get().tableFormatShip();
Expand All @@ -220,7 +219,7 @@ public Object getColumnValue(final OwnerType from) {
return new YesNo(from.isShip());
}
},
PLANETARY_INTERACTION(YesNo.class, GlazedLists.comparableComparator()) {
PLANETARY_INTERACTION(YesNo.class) {
@Override
public String getColumnName() {
return DialoguesAccount.get().tableFormatPlanetaryInteraction();
Expand All @@ -230,7 +229,7 @@ public Object getColumnValue(final OwnerType from) {
return new YesNo(from.isPlanetaryInteraction());
}
},
OPEN_WINDOWS(YesNo.class, GlazedLists.comparableComparator()) {
OPEN_WINDOWS(YesNo.class) {
@Override
public String getColumnName() {
return DialoguesAccount.get().tableFormatOpenWindows();
Expand All @@ -240,7 +239,7 @@ public Object getColumnValue(final OwnerType from) {
return new YesNo(from.isOpenWindows());
}
},
AUTOPILOT(YesNo.class, GlazedLists.comparableComparator()) {
AUTOPILOT(YesNo.class) {
@Override
public String getColumnName() {
return DialoguesAccount.get().tableFormatAutopilot();
Expand All @@ -250,7 +249,7 @@ public Object getColumnValue(final OwnerType from) {
return new YesNo(from.isAutopilot());
}
},
SKILLS(YesNo.class, GlazedLists.comparableComparator()) {
SKILLS(YesNo.class) {
@Override
public String getColumnName() {
return DialoguesAccount.get().tableFormatSkills();
Expand All @@ -260,7 +259,7 @@ public Object getColumnValue(final OwnerType from) {
return new YesNo(from.isSkills());
}
},
MINING(YesNo.class, GlazedLists.comparableComparator()) {
MINING(YesNo.class) {
@Override
public String getColumnName() {
return DialoguesAccount.get().tableFormatMining();
Expand All @@ -270,7 +269,7 @@ public Object getColumnValue(final OwnerType from) {
return new YesNo(from.isMining());
}
},
EXPIRES(ExpirerDate.class, GlazedLists.comparableComparator()) {
EXPIRES(ExpirerDate.class) {
@Override
public String getColumnName() {
return DialoguesAccount.get().tableFormatExpires();
Expand All @@ -283,9 +282,9 @@ public Object getColumnValue(final OwnerType from) {

private final Class<?> type;
private final Comparator<?> comparator;
private AccountTableFormat(final Class<?> type, final Comparator<?> comparator) {
private AccountTableFormat(final Class<?> type) {
this.type = type;
this.comparator = comparator;
this.comparator = EnumTableColumn.getComparator(type);
}
@Override
public Class<?> getType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@
*/
package net.nikr.eve.jeveasset.gui.dialogs.settings;

import ca.odell.glazedlists.GlazedLists;
import java.awt.Color;
import java.util.Comparator;
import net.nikr.eve.jeveasset.data.settings.ColorSettings.ColorRow;
import net.nikr.eve.jeveasset.gui.shared.table.EnumTableColumn;
import net.nikr.eve.jeveasset.i18n.DialoguesSettings;

public enum ColorsTableFormat implements EnumTableColumn<ColorRow> {
NAME(String.class, GlazedLists.comparableComparator()) {
NAME(String.class) {
@Override
public String getColumnName() {
return DialoguesSettings.get().columnName();
Expand All @@ -38,7 +37,7 @@ public Object getColumnValue(final ColorRow from) {
return from.getColorEntry().getDescription();
}
},
BACKGROUND(Color.class, GlazedLists.comparableComparator()) {
BACKGROUND(Color.class) {
@Override
public String getColumnName() {
return DialoguesSettings.get().columnBackground();
Expand All @@ -48,7 +47,7 @@ public Object getColumnValue(final ColorRow from) {
return from.getBackground();
}
},
FOREGROUND(Color.class, GlazedLists.comparableComparator()) {
FOREGROUND(Color.class) {
@Override
public String getColumnName() {
return DialoguesSettings.get().columnForeground();
Expand All @@ -58,7 +57,7 @@ public Object getColumnValue(final ColorRow from) {
return from.getForeground();
}
},
PREVIEW(String.class, GlazedLists.comparableComparator()) {
PREVIEW(String.class) {
@Override
public String getColumnName() {
return DialoguesSettings.get().columnPreview();
Expand All @@ -68,7 +67,7 @@ public Object getColumnValue(final ColorRow from) {
return DialoguesSettings.get().testText();
}
},
SELECTED(String.class, GlazedLists.comparableComparator()) {
SELECTED(String.class) {
@Override
public String getColumnName() {
return DialoguesSettings.get().columnSelected();
Expand All @@ -82,9 +81,9 @@ public Object getColumnValue(final ColorRow from) {
private final Class<?> type;
private final Comparator<?> comparator;

private ColorsTableFormat(final Class<?> type, final Comparator<?> comparator) {
private ColorsTableFormat(final Class<?> type) {
this.type = type;
this.comparator = comparator;
this.comparator = EnumTableColumn.getComparator(type);
}
@Override
public Class<?> getType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@

package net.nikr.eve.jeveasset.gui.shared.table;

import ca.odell.glazedlists.GlazedLists;
import java.awt.Color;
import java.awt.Component;
import java.util.Comparator;
import net.nikr.eve.jeveasset.gui.shared.table.containers.ISK;
import net.nikr.eve.jeveasset.gui.shared.table.containers.ModulePriceValue;

/**
*
Expand All @@ -47,4 +52,20 @@ public default String getColumnToolTip() {
return null;
}

public static Comparator<?> getComparator(final Class<?> type) {
if (type.equals(String.class)) {
return GlazedLists.caseInsensitiveComparator();
} else if (Comparable.class.isAssignableFrom(type)) {
return GlazedLists.comparableComparator();
} else if (Component.class.isAssignableFrom(type)
|| ModulePriceValue.class.isAssignableFrom(type)
|| ISK.class.isAssignableFrom(type)
|| Color.class.isAssignableFrom(type)
) {
return null; //Not sortable
} else {
throw new RuntimeException(type.getName() + " is not comparable");
}
}

}
Loading

0 comments on commit 921a1f0

Please sign in to comment.