mirror of
https://github.com/demodude4u/Factorio-FBSR.git
synced 2024-11-24 08:12:21 +02:00
Replaced Pair because of api restrictions
This commit is contained in:
parent
e4322780de
commit
b7054f532e
@ -8,12 +8,14 @@ import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.AbstractMap.SimpleEntry;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
@ -78,8 +80,6 @@ import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.LinkedHashMultiset;
|
||||
import com.google.common.collect.Multiset;
|
||||
|
||||
import javafx.util.Pair;
|
||||
|
||||
public class EntityRendererFactory {
|
||||
|
||||
private static List<String> defaultProperties = ImmutableList.of("animation", "off_animation", "structure");
|
||||
@ -384,11 +384,12 @@ public class EntityRendererFactory {
|
||||
}
|
||||
|
||||
if (!map.hasWire(key)) {
|
||||
map.setWire(key, new Pair<>(getWirePositionFor(entity, prototype, colorName, circuitId),
|
||||
new Point2D.Double()));
|
||||
map.setWire(key,
|
||||
new SimpleEntry<>(getWirePositionFor(entity, prototype, colorName, circuitId),
|
||||
new Point2D.Double()));
|
||||
|
||||
} else {
|
||||
Pair<Point2D.Double, Point2D.Double> pair = map.getWire(key);
|
||||
Entry<Point2D.Double, Point2D.Double> pair = map.getWire(key);
|
||||
|
||||
Point2D.Double p1 = pair.getKey();
|
||||
Point2D.Double p2 = pair.getValue();
|
||||
|
@ -19,6 +19,7 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.AbstractMap.SimpleEntry;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@ -58,8 +59,6 @@ import com.google.common.collect.LinkedHashMultiset;
|
||||
import com.google.common.collect.Multiset;
|
||||
import com.google.common.collect.Table;
|
||||
|
||||
import javafx.util.Pair;
|
||||
|
||||
public class FBSR {
|
||||
|
||||
private static class EntityRenderingTuple {
|
||||
@ -780,14 +779,14 @@ public class FBSR {
|
||||
|
||||
private static void populateTransitLogistics(WorldMap map) {
|
||||
Table<Integer, Integer, LogisticGridCell> logisticGrid = map.getLogisticGrid();
|
||||
ArrayDeque<Pair<Point2D.Double, LogisticGridCell>> work = new ArrayDeque<>();
|
||||
ArrayDeque<Entry<Point2D.Double, LogisticGridCell>> work = new ArrayDeque<>();
|
||||
|
||||
logisticGrid.cellSet().stream().filter(c -> c.getValue().isTransitStart()).forEach(c -> {
|
||||
Set<String> outputs = c.getValue().getOutputs().get();
|
||||
for (String item : outputs) {
|
||||
work.add(new Pair<>(map.getLogisticCellPosition(c), c.getValue()));
|
||||
work.add(new SimpleEntry<>(map.getLogisticCellPosition(c), c.getValue()));
|
||||
while (!work.isEmpty()) {
|
||||
Pair<Point2D.Double, LogisticGridCell> pair = work.pop();
|
||||
Entry<Point2D.Double, LogisticGridCell> pair = work.pop();
|
||||
Point2D.Double cellPos = pair.getKey();
|
||||
LogisticGridCell cell = pair.getValue();
|
||||
if (cell.addTransit(item) && !cell.isBannedOutput(item)) {
|
||||
@ -795,12 +794,12 @@ public class FBSR {
|
||||
Point2D.Double nextCellPos = d.offset(cellPos, 0.5);
|
||||
map.getLogisticGridCell(nextCellPos)
|
||||
.filter(nc -> !nc.isBlockTransit() && nc.acceptMoveFrom(d))
|
||||
.ifPresent(next -> work.add(new Pair<>(nextCellPos, next)));
|
||||
.ifPresent(next -> work.add(new SimpleEntry<>(nextCellPos, next)));
|
||||
});
|
||||
cell.getWarps().ifPresent(l -> {
|
||||
for (Point2D.Double p : l) {
|
||||
map.getLogisticGridCell(p).filter(nc -> !nc.isBlockTransit())
|
||||
.ifPresent(next -> work.add(new Pair<>(p, next)));
|
||||
.ifPresent(next -> work.add(new SimpleEntry<>(p, next)));
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -812,9 +811,9 @@ public class FBSR {
|
||||
logisticGrid.cellSet().stream().filter(c -> c.getValue().isTransitEnd()).forEach(c -> {
|
||||
Set<String> inputs = c.getValue().getInputs().get();
|
||||
for (String item : inputs) {
|
||||
work.add(new Pair<>(map.getLogisticCellPosition(c), c.getValue()));
|
||||
work.add(new SimpleEntry<>(map.getLogisticCellPosition(c), c.getValue()));
|
||||
while (!work.isEmpty()) {
|
||||
Pair<Point2D.Double, LogisticGridCell> pair = work.pop();
|
||||
Entry<Point2D.Double, LogisticGridCell> pair = work.pop();
|
||||
Point2D.Double cellPos = pair.getKey();
|
||||
LogisticGridCell cell = pair.getValue();
|
||||
if (cell.addTransit(item)) {
|
||||
@ -822,13 +821,13 @@ public class FBSR {
|
||||
for (Direction d : l) {
|
||||
Point2D.Double nextCellPos = d.offset(cellPos, 0.5);
|
||||
map.getLogisticGridCell(nextCellPos).filter(nc -> !nc.isBlockTransit())
|
||||
.ifPresent(next -> work.add(new Pair<>(nextCellPos, next)));
|
||||
.ifPresent(next -> work.add(new SimpleEntry<>(nextCellPos, next)));
|
||||
}
|
||||
});
|
||||
cell.getWarpedFrom().ifPresent(l -> {
|
||||
for (Point2D.Double p : l) {
|
||||
map.getLogisticGridCell(p).filter(nc -> !nc.isBlockTransit())
|
||||
.ifPresent(next -> work.add(new Pair<>(p, next)));
|
||||
.ifPresent(next -> work.add(new SimpleEntry<>(p, next)));
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -1056,7 +1055,7 @@ public class FBSR {
|
||||
}
|
||||
|
||||
private static void showRailLogistics(Consumer<Renderer> register, DataTable table, WorldMap map) {
|
||||
for (Pair<RailEdge, RailEdge> pair : map.getRailEdges()) {
|
||||
for (Entry<RailEdge, RailEdge> pair : map.getRailEdges()) {
|
||||
boolean input = pair.getKey().isInput() || pair.getValue().isInput();
|
||||
boolean output = pair.getKey().isOutput() || pair.getValue().isOutput();
|
||||
|
||||
|
@ -1,16 +1,16 @@
|
||||
package com.demod.fbsr;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.AbstractMap.SimpleEntry;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import com.demod.fbsr.WorldMap.Debug;
|
||||
|
||||
import javafx.util.Pair;
|
||||
|
||||
public class TaskReporting {
|
||||
public static enum Level {
|
||||
INFO(Color.gray), WARN(Color.orange), ERROR(Color.red), DEBUG(Color.magenta);
|
||||
@ -30,7 +30,7 @@ public class TaskReporting {
|
||||
private Optional<String> context = Optional.empty();
|
||||
private final List<String> warnings = new ArrayList<>();
|
||||
private final List<Exception> exceptions = new ArrayList<>();
|
||||
private final List<Pair<Optional<String>, String>> images = new ArrayList<>();
|
||||
private final List<Entry<Optional<String>, String>> images = new ArrayList<>();
|
||||
private final List<String> downloads = new ArrayList<>();
|
||||
private final List<String> links = new ArrayList<>();
|
||||
private final Set<String> info = new LinkedHashSet<>();
|
||||
@ -48,7 +48,7 @@ public class TaskReporting {
|
||||
}
|
||||
|
||||
public void addImage(Optional<String> label, String url) {
|
||||
images.add(new Pair<>(label, url));
|
||||
images.add(new SimpleEntry<>(label, url));
|
||||
}
|
||||
|
||||
public void addInfo(String info) {
|
||||
@ -83,7 +83,7 @@ public class TaskReporting {
|
||||
return exceptions;
|
||||
}
|
||||
|
||||
public List<Pair<Optional<String>, String>> getImages() {
|
||||
public List<Entry<Optional<String>, String>> getImages() {
|
||||
return images;
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@ import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@ -27,7 +28,6 @@ import com.demod.fbsr.app.BlueprintBotDiscordService;
|
||||
import com.demod.fbsr.app.ServiceFinder;
|
||||
import com.google.common.util.concurrent.Uninterruptibles;
|
||||
|
||||
import javafx.util.Pair;
|
||||
import net.dv8tion.jda.core.EmbedBuilder;
|
||||
import net.dv8tion.jda.core.entities.MessageEmbed;
|
||||
|
||||
@ -90,14 +90,14 @@ public final class WebUtils {
|
||||
return Utils.readJsonFromStream(new URL(url).openStream());
|
||||
}
|
||||
|
||||
public static URL uploadToBundly(String title, String description, List<Pair<URL, String>> links)
|
||||
public static URL uploadToBundly(String title, String description, List<Entry<URL, String>> links)
|
||||
throws IOException {
|
||||
JSONObject request = new JSONObject();
|
||||
request.put("title", title);
|
||||
request.put("desc", description);
|
||||
|
||||
JSONArray items = new JSONArray();
|
||||
for (Pair<URL, String> pair : links) {
|
||||
for (Entry<URL, String> pair : links) {
|
||||
JSONObject item = new JSONObject();
|
||||
item.put("url", pair.getKey().toString());
|
||||
item.put("id", Long.toString(System.currentTimeMillis()));
|
||||
|
@ -2,6 +2,7 @@ package com.demod.fbsr;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Point2D.Double;
|
||||
import java.util.AbstractMap.SimpleEntry;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
@ -9,6 +10,7 @@ import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
@ -20,8 +22,6 @@ import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Table;
|
||||
import com.google.common.collect.Table.Cell;
|
||||
|
||||
import javafx.util.Pair;
|
||||
|
||||
public class WorldMap {
|
||||
|
||||
public static enum BeltBend {
|
||||
@ -237,7 +237,7 @@ public class WorldMap {
|
||||
private final Table<Integer, Integer, Integer> heatPipes = HashBasedTable.create();
|
||||
private final Table<Integer, Integer, Object> walls = HashBasedTable.create();
|
||||
private final Table<Integer, Integer, Boolean> gates = HashBasedTable.create();
|
||||
private final Table<Integer, Integer, Pair<String, Direction>> undergroundBeltEndings = HashBasedTable.create();
|
||||
private final Table<Integer, Integer, Entry<String, Direction>> undergroundBeltEndings = HashBasedTable.create();
|
||||
private final Table<Integer, Integer, List<BlueprintEntity>> beaconed = HashBasedTable.create();
|
||||
|
||||
// Row: X*2
|
||||
@ -246,9 +246,9 @@ public class WorldMap {
|
||||
private final Table<Integer, Integer, RailNode> railNodes = HashBasedTable.create();
|
||||
|
||||
// Key: "eid1|cid1|eid2|cid2|color"
|
||||
private final Map<String, Pair<Point2D.Double, Point2D.Double>> wires = new LinkedHashMap<>();
|
||||
private final Map<String, Entry<Point2D.Double, Point2D.Double>> wires = new LinkedHashMap<>();
|
||||
|
||||
private final List<Pair<RailEdge, RailEdge>> railEdges = new ArrayList<>();
|
||||
private final List<Entry<RailEdge, RailEdge>> railEdges = new ArrayList<>();
|
||||
|
||||
private Debug debug = new Debug();
|
||||
|
||||
@ -338,7 +338,7 @@ public class WorldMap {
|
||||
return ret;
|
||||
}
|
||||
|
||||
public List<Pair<RailEdge, RailEdge>> getRailEdges() {
|
||||
public List<Entry<RailEdge, RailEdge>> getRailEdges() {
|
||||
return railEdges;
|
||||
}
|
||||
|
||||
@ -352,11 +352,11 @@ public class WorldMap {
|
||||
return railNodes;
|
||||
}
|
||||
|
||||
public Pair<Point2D.Double, Point2D.Double> getWire(String key) {
|
||||
public Entry<Point2D.Double, Point2D.Double> getWire(String key) {
|
||||
return wires.get(key);
|
||||
}
|
||||
|
||||
public Map<String, Pair<Point2D.Double, Point2D.Double>> getWires() {
|
||||
public Map<String, Entry<Point2D.Double, Point2D.Double>> getWires() {
|
||||
return wires;
|
||||
}
|
||||
|
||||
@ -469,13 +469,13 @@ public class WorldMap {
|
||||
RailEdge edge2 = new RailEdge(p2, d2, p1, d1, curved);
|
||||
node2.addOutgoingEdge(edge2);
|
||||
node1.addIncomingEdge(edge2);
|
||||
railEdges.add(new Pair<>(edge1, edge2));
|
||||
railEdges.add(new SimpleEntry<>(edge1, edge2));
|
||||
}
|
||||
|
||||
public void setUndergroundBeltEnding(String name, Point2D.Double pos, Direction dir) {
|
||||
int kr = (int) Math.floor(pos.x);
|
||||
int kc = (int) Math.floor(pos.y);
|
||||
undergroundBeltEndings.put(kr, kc, new Pair<>(name, dir));
|
||||
undergroundBeltEndings.put(kr, kc, new SimpleEntry<>(name, dir));
|
||||
}
|
||||
|
||||
public void setVerticalGate(Point2D.Double pos) {
|
||||
@ -490,7 +490,7 @@ public class WorldMap {
|
||||
walls.put(kr, kc, pos);
|
||||
}
|
||||
|
||||
public void setWire(String key, Pair<Point2D.Double, Point2D.Double> pair) {
|
||||
public void setWire(String key, Entry<Point2D.Double, Point2D.Double> pair) {
|
||||
wires.put(key, pair);
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import java.io.StringWriter;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.URL;
|
||||
import java.time.Instant;
|
||||
import java.util.AbstractMap.SimpleEntry;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -15,6 +16,7 @@ import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
@ -53,7 +55,6 @@ import com.google.common.collect.LinkedHashMultiset;
|
||||
import com.google.common.collect.Multiset;
|
||||
import com.google.common.util.concurrent.AbstractIdleService;
|
||||
|
||||
import javafx.util.Pair;
|
||||
import net.dv8tion.jda.core.EmbedBuilder;
|
||||
import net.dv8tion.jda.core.Permission;
|
||||
import net.dv8tion.jda.core.entities.Message;
|
||||
@ -185,7 +186,7 @@ public class BlueprintBotDiscordService extends AbstractIdleService {
|
||||
if (!prototype.isPresent()) {
|
||||
LevenshteinDistance levenshteinDistance = LevenshteinDistance.getDefaultInstance();
|
||||
List<String> suggestions = map.keySet().stream()
|
||||
.map(k -> new Pair<>(k, levenshteinDistance.apply(search, k)))
|
||||
.map(k -> new SimpleEntry<>(k, levenshteinDistance.apply(search, k)))
|
||||
.sorted((p1, p2) -> Integer.compare(p1.getValue(), p2.getValue())).limit(5)
|
||||
.map(p -> p.getKey()).collect(Collectors.toList());
|
||||
event.getChannel()
|
||||
@ -211,7 +212,7 @@ public class BlueprintBotDiscordService extends AbstractIdleService {
|
||||
Optional<String> context = reporting.getContext();
|
||||
List<Exception> exceptions = reporting.getExceptions();
|
||||
List<String> warnings = reporting.getWarnings();
|
||||
List<Pair<Optional<String>, String>> images = reporting.getImages();
|
||||
List<Entry<Optional<String>, String>> images = reporting.getImages();
|
||||
List<String> links = reporting.getLinks();
|
||||
List<String> downloads = reporting.getDownloads();
|
||||
Set<String> info = reporting.getInfo();
|
||||
@ -241,7 +242,7 @@ public class BlueprintBotDiscordService extends AbstractIdleService {
|
||||
}
|
||||
if (images.size() > 1) {
|
||||
WebUtils.addPossiblyLargeEmbedField(builder, "Additional Image(s)",
|
||||
images.stream().skip(1).map(Pair::getValue).collect(Collectors.joining("\n")), false);
|
||||
images.stream().skip(1).map(Entry::getValue).collect(Collectors.joining("\n")), false);
|
||||
}
|
||||
|
||||
if (!downloads.isEmpty()) {
|
||||
@ -415,17 +416,16 @@ public class BlueprintBotDiscordService extends AbstractIdleService {
|
||||
|
||||
List<Blueprint> blueprints = blueprintStrings.stream().flatMap(bs -> bs.getBlueprints().stream())
|
||||
.collect(Collectors.toList());
|
||||
List<Pair<URL, String>> links = new ArrayList<>();
|
||||
List<Entry<URL, String>> links = new ArrayList<>();
|
||||
for (Blueprint blueprint : blueprints) {
|
||||
try {
|
||||
blueprint.json().remove("index");
|
||||
|
||||
URL url = WebUtils.uploadToHostingService("blueprint.txt",
|
||||
(/*
|
||||
* blueprint.getLabel().orElse("Blueprint String") +
|
||||
* ": "
|
||||
* blueprint.getLabel().orElse("Blueprint String") + ": "
|
||||
*/" " + BlueprintStringData.encode(blueprint.json())).getBytes());
|
||||
links.add(new Pair<>(url, blueprint.getLabel().orElse(null)));
|
||||
links.add(new SimpleEntry<>(url, blueprint.getLabel().orElse(null)));
|
||||
} catch (Exception e) {
|
||||
reporting.addException(e);
|
||||
}
|
||||
@ -703,10 +703,10 @@ public class BlueprintBotDiscordService extends AbstractIdleService {
|
||||
reporting.addInfo(WebUtils.uploadToHostingService("blueprint.png", image).toString());
|
||||
}
|
||||
} else {
|
||||
List<Pair<URL, String>> links = new ArrayList<>();
|
||||
List<Entry<URL, String>> links = new ArrayList<>();
|
||||
for (Blueprint blueprint : blueprintString.getBlueprints()) {
|
||||
BufferedImage image = FBSR.renderBlueprint(blueprint, reporting);
|
||||
links.add(new Pair<>(WebUtils.uploadToHostingService("blueprint.png", image),
|
||||
links.add(new SimpleEntry<>(WebUtils.uploadToHostingService("blueprint.png", image),
|
||||
blueprint.getLabel().orElse("")));
|
||||
}
|
||||
try {
|
||||
@ -727,11 +727,12 @@ public class BlueprintBotDiscordService extends AbstractIdleService {
|
||||
}
|
||||
}
|
||||
|
||||
private void sendBundlyReplacementEmbed(MessageChannel channel, String title, List<Pair<URL, String>> links)
|
||||
private void sendBundlyReplacementEmbed(MessageChannel channel, String title, List<Entry<URL, String>> links)
|
||||
throws IllegalStateException {
|
||||
ArrayDeque<String> linksFormatted = links.stream()
|
||||
.map(p -> (p.getValue() != null && !p.getValue().isEmpty())
|
||||
? ("[" + p.getValue() + "](" + p.getKey() + ")") : p.getKey().toString())
|
||||
? ("[" + p.getValue() + "](" + p.getKey() + ")")
|
||||
: p.getKey().toString())
|
||||
.collect(Collectors.toCollection(ArrayDeque::new));
|
||||
while (!linksFormatted.isEmpty()) {
|
||||
EmbedBuilder builder = new EmbedBuilder();
|
||||
@ -765,9 +766,8 @@ public class BlueprintBotDiscordService extends AbstractIdleService {
|
||||
|
||||
public void sendReport(MessageReceivedEvent event, TaskReporting reporting) {
|
||||
if (!reporting.getExceptions().isEmpty()) {
|
||||
event.getChannel()
|
||||
.sendMessage(
|
||||
"There was a problem completing your request. I have contacted my programmer to fix it for you!")
|
||||
event.getChannel().sendMessage(
|
||||
"There was a problem completing your request. I have contacted my programmer to fix it for you!")
|
||||
.complete();
|
||||
}
|
||||
|
||||
|
@ -3,8 +3,10 @@ package com.demod.fbsr.app;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.AbstractMap.SimpleEntry;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.json.JSONObject;
|
||||
@ -22,8 +24,6 @@ import com.demod.fbsr.TaskReporting;
|
||||
import com.demod.fbsr.WebUtils;
|
||||
import com.google.common.util.concurrent.AbstractIdleService;
|
||||
|
||||
import javafx.util.Pair;
|
||||
|
||||
public class BlueprintBotIRCService extends AbstractIdleService {
|
||||
|
||||
private static final String IRC_AUTHOR_URL = "http://peterbjornx.nl/wp-content/uploads/2013/08/irc_icon.png";
|
||||
@ -51,10 +51,10 @@ public class BlueprintBotIRCService extends AbstractIdleService {
|
||||
reporting.addInfo(WebUtils.uploadToHostingService("blueprint.png", image).toString());
|
||||
|
||||
} else {
|
||||
List<Pair<URL, String>> links = new ArrayList<>();
|
||||
List<Entry<URL, String>> links = new ArrayList<>();
|
||||
for (Blueprint blueprint : blueprintString.getBlueprints()) {
|
||||
BufferedImage image = FBSR.renderBlueprint(blueprint, reporting);
|
||||
links.add(new Pair<>(WebUtils.uploadToHostingService("blueprint.png", image),
|
||||
links.add(new SimpleEntry<>(WebUtils.uploadToHostingService("blueprint.png", image),
|
||||
blueprint.getLabel().orElse("")));
|
||||
}
|
||||
|
||||
|
@ -8,10 +8,12 @@ import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.AbstractMap.SimpleEntry;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
@ -29,7 +31,6 @@ import com.demod.fbsr.WebUtils;
|
||||
import com.google.common.util.concurrent.AbstractScheduledService;
|
||||
import com.google.common.util.concurrent.Uninterruptibles;
|
||||
|
||||
import javafx.util.Pair;
|
||||
import net.dean.jraw.ApiException;
|
||||
import net.dean.jraw.RedditClient;
|
||||
import net.dean.jraw.http.NetworkException;
|
||||
@ -157,15 +158,15 @@ public class BlueprintBotRedditService extends AbstractScheduledService {
|
||||
}
|
||||
|
||||
List<String> lines = new ArrayList<>();
|
||||
List<Pair<Optional<String>, String>> images = reporting.getImages();
|
||||
List<Entry<Optional<String>, String>> images = reporting.getImages();
|
||||
if (images.size() > 1) {
|
||||
int id = 1;
|
||||
List<Pair<URL, String>> links = new ArrayList<>();
|
||||
for (Pair<Optional<String>, String> pair : images) {
|
||||
List<Entry<URL, String>> links = new ArrayList<>();
|
||||
for (Entry<Optional<String>, String> pair : images) {
|
||||
Optional<String> label = pair.getKey();
|
||||
String url = pair.getValue();
|
||||
try {
|
||||
links.add(new Pair<>(new URL(url), label.orElse(null)));
|
||||
links.add(new SimpleEntry<>(new URL(url), label.orElse(null)));
|
||||
} catch (MalformedURLException e) {
|
||||
reporting.addException(e);
|
||||
}
|
||||
@ -183,13 +184,13 @@ public class BlueprintBotRedditService extends AbstractScheduledService {
|
||||
} else {
|
||||
lines.add("Blueprint Images:");
|
||||
}
|
||||
for (Pair<Optional<String>, String> pair : images) {
|
||||
for (Entry<Optional<String>, String> pair : images) {
|
||||
Optional<String> label = pair.getKey();
|
||||
String url = pair.getValue();
|
||||
lines.add("[" + (id++) + ": " + label.orElse("Blueprint") + "](" + url + ")");
|
||||
}
|
||||
} else if (!images.isEmpty()) {
|
||||
Pair<Optional<String>, String> pair = images.get(0);
|
||||
Entry<Optional<String>, String> pair = images.get(0);
|
||||
Optional<String> label = pair.getKey();
|
||||
String url = pair.getValue();
|
||||
lines.add("[Blueprint Image" + label.map(s -> " (" + s + ")").orElse("") + "](" + url + ")");
|
||||
@ -224,7 +225,7 @@ public class BlueprintBotRedditService extends AbstractScheduledService {
|
||||
|
||||
int processedCount = 0;
|
||||
long newestMillis = lastProcessedMillis;
|
||||
List<Pair<Comment, String>> pendingReplies = new LinkedList<>();
|
||||
List<Entry<Comment, String>> pendingReplies = new LinkedList<>();
|
||||
paginate: for (Listing<Comment> listing : commentStream) {
|
||||
for (Comment comment : listing) {
|
||||
long createMillis = comment.getCreated().getTime();
|
||||
@ -246,11 +247,11 @@ public class BlueprintBotRedditService extends AbstractScheduledService {
|
||||
Optional<String> response = processContent(comment.getBody(), getPermaLink(comment),
|
||||
comment.getSubredditName(), comment.getAuthor(), watchdog);
|
||||
if (response.isPresent()) {
|
||||
pendingReplies.add(new Pair<>(comment, response.get()));
|
||||
pendingReplies.add(new SimpleEntry<>(comment, response.get()));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Pair<Comment, String> pair : pendingReplies) {
|
||||
for (Entry<Comment, String> pair : pendingReplies) {
|
||||
System.out.println("IM TRYING TO REPLY TO A COMMENT!");
|
||||
while (true) {
|
||||
try {
|
||||
@ -287,7 +288,7 @@ public class BlueprintBotRedditService extends AbstractScheduledService {
|
||||
|
||||
int processedCount = 0;
|
||||
long newestMillis = lastProcessedMillis;
|
||||
List<Pair<Message, String>> pendingReplies = new LinkedList<>();
|
||||
List<Entry<Message, String>> pendingReplies = new LinkedList<>();
|
||||
List<Message> processedMessages = new LinkedList<>();
|
||||
paginate: for (Listing<Message> listing : paginator) {
|
||||
for (Message message : listing) {
|
||||
@ -308,7 +309,7 @@ public class BlueprintBotRedditService extends AbstractScheduledService {
|
||||
Optional<String> response = processContent(message.getBody(), getPermaLink(message), "(Private)",
|
||||
message.getAuthor(), watchdog);
|
||||
if (response.isPresent()) {
|
||||
pendingReplies.add(new Pair<>(message, response.get()));
|
||||
pendingReplies.add(new SimpleEntry<>(message, response.get()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -318,7 +319,7 @@ public class BlueprintBotRedditService extends AbstractScheduledService {
|
||||
processedMessages.stream().skip(1).toArray(Message[]::new));
|
||||
}
|
||||
|
||||
for (Pair<Message, String> pair : pendingReplies) {
|
||||
for (Entry<Message, String> pair : pendingReplies) {
|
||||
System.out.println("IM TRYING TO REPLY TO A MESSAGE!");
|
||||
while (true) {
|
||||
try {
|
||||
@ -354,7 +355,7 @@ public class BlueprintBotRedditService extends AbstractScheduledService {
|
||||
|
||||
int processedCount = 0;
|
||||
long newestMillis = lastProcessedMillis;
|
||||
List<Pair<Submission, String>> pendingReplies = new LinkedList<>();
|
||||
List<Entry<Submission, String>> pendingReplies = new LinkedList<>();
|
||||
paginate: for (Listing<Submission> listing : paginator) {
|
||||
for (Submission submission : listing) {
|
||||
long createMillis = submission.getCreated().getTime();
|
||||
@ -381,11 +382,11 @@ public class BlueprintBotRedditService extends AbstractScheduledService {
|
||||
Optional<String> response = processContent(submission.getSelftext(), submission.getUrl(),
|
||||
submission.getSubredditName(), submission.getAuthor(), watchdog);
|
||||
if (response.isPresent()) {
|
||||
pendingReplies.add(new Pair<>(submission, response.get()));
|
||||
pendingReplies.add(new SimpleEntry<>(submission, response.get()));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Pair<Submission, String> pair : pendingReplies) {
|
||||
for (Entry<Submission, String> pair : pendingReplies) {
|
||||
System.out.println("IM TRYING TO REPLY TO A SUBMISSION!");
|
||||
while (true) {
|
||||
try {
|
||||
|
@ -2,6 +2,7 @@ package com.demod.fbsr.app;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -21,8 +22,6 @@ import com.demod.fbsr.TaskReporting;
|
||||
import com.demod.fbsr.WebUtils;
|
||||
import com.google.common.util.concurrent.AbstractIdleService;
|
||||
|
||||
import javafx.util.Pair;
|
||||
|
||||
public class WebAPIService extends AbstractIdleService {
|
||||
|
||||
private JSONObject configJson;
|
||||
@ -81,7 +80,7 @@ public class WebAPIService extends AbstractIdleService {
|
||||
|
||||
if (!reporting.getImages().isEmpty()) {
|
||||
JSONArray images = new JSONArray();
|
||||
for (Pair<Optional<String>, String> pair : reporting.getImages()) {
|
||||
for (Entry<Optional<String>, String> pair : reporting.getImages()) {
|
||||
JSONObject image = new JSONObject();
|
||||
Utils.terribleHackToHaveOrderedJSONObject(image);
|
||||
pair.getKey().ifPresent(l -> image.put("label", l));
|
||||
|
Loading…
Reference in New Issue
Block a user