Skip to content

Commit

Permalink
Sort names (any strings) case insensitive
Browse files Browse the repository at this point in the history
Issue: #407
  • Loading branch information
buchen committed Jan 17, 2016
1 parent 987fedf commit 466e352
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ else if (attribute2 == null)
switch (type)
{
case 1:
return ((String) attribute1).compareTo((String) attribute2);
return ((String) attribute1).compareToIgnoreCase((String) attribute2);
case 2:
return ((Enum<?>) attribute2).name().compareTo(((Enum<?>) attribute2).name());
case 3:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public void visit(TaxonomyNode node)
@Override
public int compare(Assignment o1, Assignment o2)
{
return o1.getInvestmentVehicle().toString().compareTo(o2.getInvestmentVehicle().toString());
return o1.getInvestmentVehicle().toString().compareToIgnoreCase(o2.getInvestmentVehicle().toString());
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -767,14 +766,7 @@ public Object[] getElements(Object inputElement)
for (Enum<?> entry : mapFormat.map().keySet())
elements.add(new Entry(mapFormat.map(), entry));

Collections.sort(elements, new Comparator<Entry<?>>()
{
@Override
public int compare(Entry<?> e1, Entry<?> e2)
{
return e1.key.name().compareTo(e2.key.name());
}
});
Collections.sort(elements, (e1, e2) -> e1.key.name().compareToIgnoreCase(e2.key.name()));

return elements.toArray();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ else if (o2 == null)
else if (type == Double.class)
return ((Double) o1).compareTo((Double) o2);
else if (type == String.class)
return ((String) o1).compareTo((String) o2);
return ((String) o1).compareToIgnoreCase((String) o2);
else
return ((Comparable<Object>) o1).compareTo((Comparable<Object>) o2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public int compare(Named n1, Named n2)
{
if (n1 == null)
return n2 == null ? 0 : -1;
return n1.getName().compareTo(n2.getName());
return n1.getName().compareToIgnoreCase(n2.getName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public int compare(Security s1, Security s2)
{
if (s1 == null)
return s2 == null ? 0 : -1;
return s1.name.compareTo(s2.name);
return s1.name.compareToIgnoreCase(s2.name);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ private void addCapitalGains()
capitalGains.positions = valuation.entrySet().stream() //
.filter(entry -> !entry.getValue().isZero())
.map(entry -> new Position(entry.getKey(), entry.getValue().toMoney()))
.sorted((p1, p2) -> p1.getLabel().compareTo(p2.getLabel())) //
.sorted((p1, p2) -> p1.getLabel().compareToIgnoreCase(p2.getLabel())) //
.collect(Collectors.toList());

// total capital gains -> sum it up
Expand Down Expand Up @@ -375,7 +375,7 @@ private void addEarnings()
//
.filter(entry -> !entry.getValue().isZero())
.map(entry -> new Position(entry.getKey(), entry.getValue().toMoney()))
.sorted((p1, p2) -> p1.getLabel().compareTo(p2.getLabel())) //
.sorted((p1, p2) -> p1.getLabel().compareToIgnoreCase(p2.getLabel())) //
.collect(Collectors.toList());

if (!otherEarnings.isZero())
Expand Down

0 comments on commit 466e352

Please sign in to comment.