Skip to content

Commit

Permalink
Merge branch 'main' into native
Browse files Browse the repository at this point in the history
  • Loading branch information
GoldenGnu committed Dec 18, 2024
2 parents 789ee5a + 4f4af10 commit 7a78303
Show file tree
Hide file tree
Showing 10 changed files with 341 additions and 194 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import net.nikr.eve.jeveasset.CliOptions;
import net.nikr.eve.jeveasset.gui.tabs.values.Value;
Expand All @@ -37,7 +39,7 @@
public class TrackerData {

private static final Logger LOG = LoggerFactory.getLogger(TrackerData.class);
private static final Map<String, List<Value>> TRACKER_DATA = new HashMap<String, List<Value>>(); //ownerID :: long
private static final Map<String, List<Value>> TRACKER_DATA = new HashMap<>(); //ownerID :: long
private static final ReentrantReadWriteLock LOCK = new ReentrantReadWriteLock();
private static final Object SAVE_QUEUE_SYNC = new Object();
private static Integer SAVE_QUEUE = 0;
Expand Down Expand Up @@ -116,10 +118,29 @@ public static void add(String owner, Value add) {
}
}

public static void addAll(Map<String, List<Value>> trackerData) {
public static void addAll(Map<String, List<Value>> trackerData, boolean overwrite) {
try {
LOCK.writeLock().lock();
TRACKER_DATA.putAll(trackerData);
for (Map.Entry<String, List<Value>> entry : trackerData.entrySet()) {
//For each owner
String owner = entry.getKey();
List<Value> list = TRACKER_DATA.get(owner);
if (list == null) { //Owner doesn't exist
list = new ArrayList<>();
TRACKER_DATA.put(owner, list);
}
//Remove duplicates, while staying in order
Set<Value> set = new TreeSet<>(Value.DATE_COMPARATOR);
if (overwrite) {
set.addAll(entry.getValue()); //Add new data (First)
set.addAll(list); //Add old data (Second, only add if not already contains)
} else {
set.addAll(list); //Add old data (First)
set.addAll(entry.getValue()); //Add new data (Second, only add if not already contains)
}
list.clear(); //Clear old data
list.addAll(set); //Set new merged data
}
} finally {
LOCK.writeLock().unlock();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
import net.nikr.eve.jeveasset.gui.shared.table.containers.NumberValue;
import net.nikr.eve.jeveasset.gui.tabs.stockpile.Stockpile.StockpileItem;
import net.nikr.eve.jeveasset.gui.tabs.stockpile.Stockpile.StockpileTotal;
import net.nikr.eve.jeveasset.gui.tabs.stockpile.Stockpile.SubpileItem;
import net.nikr.eve.jeveasset.gui.tabs.stockpile.Stockpile.SubpileStock;
import net.nikr.eve.jeveasset.gui.tabs.stockpile.StockpileTableFormat;
import net.nikr.eve.jeveasset.i18n.GuiShared;
import org.slf4j.Logger;
Expand Down Expand Up @@ -419,26 +417,8 @@ private Object eval(Formula formula, Q e) {
return null;
}
StockpileTotal totalItem = (StockpileTotal) e;
Map<Integer, StockpileItem> map = new HashMap<>();
//Items
for (StockpileItem item : totalItem.getStockpile().getItems()) {
if (item.isTotal()) {
continue; //Ignore Total
}
map.put(item.getItemTypeID(), item);
}
//SubpileItem (Overwrites StockpileItem items)
for (SubpileItem item : totalItem.getStockpile().getSubpileItems()) {
if (item instanceof SubpileStock) {
continue;
}
map.put(item.getItemTypeID(), item);
}
double total = 0.0;
for (StockpileItem item : map.values()) {
if (item.isTotal()) {
continue; //Ignore Total
}
for (StockpileItem item : totalItem.getStockpile().getClaims()) {
setVariables(formula, StockpileTableFormat.values(), item);
BigDecimal value = safeEval(expression);
if (value != null) {
Expand Down
103 changes: 86 additions & 17 deletions src/main/java/net/nikr/eve/jeveasset/gui/tabs/stockpile/Stockpile.java
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,23 @@ public Collection<StockpileItem> getItems() {
}

public List<StockpileItem> getClaims() {
List<StockpileItem> list = new ArrayList<>();
list.addAll(items);
list.addAll(subpileAll);
return list;
return new ArrayList<>(getClaimsMap().values());
}

public Map<TypeIdentifier, StockpileItem> getClaimsMap() {
Map<TypeIdentifier, StockpileItem> map = new HashMap<>();
//Items
for (StockpileItem item : items) {
if (item.isTotal()) {
continue;
}
map.put(item.getType(), item);
}
//SubpileItem (Overwrites StockpileItem items)
for (SubpileItem item : subpileItems) {
map.put(item.getType(), item);
}
return map;
}

@Override
Expand Down Expand Up @@ -492,20 +505,8 @@ public double getPercentFull() {
public void updateTotal() {
totalItem.reset();
percentFull = Double.MAX_VALUE;
Map<Integer, StockpileItem> map = new HashMap<>();
//Items
for (StockpileItem item : items) {
if (item.isTotal()) {
continue; //Ignore Total
}
map.put(item.getItemTypeID(), item);
}
//SubpileItem (Overwrites StockpileItem items)
for (SubpileItem item : subpileItems) {
map.put(item.getItemTypeID(), item);
}
//For each item type
for (StockpileItem item : map.values()) {
for (StockpileItem item : getClaims()) {
if (item.isTotal()) {
continue; //Ignore Total
}
Expand Down Expand Up @@ -567,6 +568,7 @@ public static class StockpileItem implements Comparable<StockpileItem>, Location
private Stockpile stockpile;
private Item item;
private int typeID;
private TypeIdentifier type;
private double countMinimum;
private boolean runs;
private boolean ignoreMultiplier;
Expand Down Expand Up @@ -621,6 +623,7 @@ public StockpileItem(final Stockpile stockpile, final Item item, final int typeI
this.runs = runs;
this.ignoreMultiplier = ignoreMultiplier;
this.id = id;
this.type = new TypeIdentifier(typeID, runs);
}

void update(StockpileItem stockpileItem) {
Expand All @@ -630,6 +633,7 @@ void update(StockpileItem stockpileItem) {
this.countMinimum = stockpileItem.countMinimum;
this.runs = stockpileItem.runs;
this.ignoreMultiplier = stockpileItem.ignoreMultiplier;
this.type = new TypeIdentifier(typeID, runs);
}

@Override
Expand Down Expand Up @@ -1318,6 +1322,10 @@ public Double getTransactionAveragePrice() {
return transactionAveragePrice;
}

public TypeIdentifier getType() {
return type;
}

public int getItemTypeID() {
return typeID;
}
Expand Down Expand Up @@ -2140,4 +2148,65 @@ public void setCountMinimum(double subMultiplier) {
public double getVolumeNeeded() { return 0; };

}

public static class TypeIdentifier {

private final int typeID;
private final boolean runs;

public TypeIdentifier(StockpileItem stockpileItem) {
this.typeID = stockpileItem.typeID;
this.runs = stockpileItem.isRuns();
}

public TypeIdentifier(int typeID, boolean runs) {
this.typeID = typeID;
this.runs = runs;
}

public boolean isEmpty() {
return typeID == 0;
}

public boolean isBPC() {
return typeID < 0;
}

public boolean isRuns() {
return runs;
}

public int getTypeID() {
return typeID;
}

@Override
public int hashCode() {
int hash = 7;
hash = 59 * hash + this.typeID;
hash = 59 * hash + (this.runs ? 1 : 0);
return hash;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final TypeIdentifier other = (TypeIdentifier) obj;
if (this.typeID != other.typeID) {
return false;
}
if (this.runs != other.runs) {
return false;
}
return true;
}
}
}
Loading

0 comments on commit 7a78303

Please sign in to comment.