Diff
checker
Text
Text
Bilder
Dokumente
Excel
Ordner
Legal
Enterprise
Desktop-App
Preise
Einloggen
Diffchecker Desktop herunterladen
Texte vergleichen
Finde den Unterschied zwischen zwei Textdateien
Werkzeuge
Verlauf
Live-Editor
Gleiches ausblenden
Zeilenumbruch aus
Ansicht
Zweispaltig
Einspaltig
Vergleichsgenauigkeit
Intelligent
Wort
Zeichen
Syntaxhervorhebung
Syntax auswählen
Ignorieren
Text umwandeln
Zur ersten Änderung
Eingabe bearbeiten
Diffchecker Desktop
Der sicherste Weg, Diffchecker zu nutzen. Hol dir die Desktop-App: Deine Diffs verlassen nie deinen Computer!
Desktop holen
Untitled diff
Erstellt
vor 10 Jahren
Diff läuft nie ab
Löschen
Exportieren
Teilen
Erklären
5 Entfernungen
Zeilen
Gesamt
Entfernt
Zeichen
Gesamt
Entfernt
Um diese Funktion weiterhin zu nutzen, aktualisiere auf
Diff
checker
Pro
Preise anzeigen
145 Zeilen
Kopieren
9 Hinzufügungen
Zeilen
Gesamt
Hinzugefügt
Zeichen
Gesamt
Hinzugefügt
Um diese Funktion weiterhin zu nutzen, aktualisiere auf
Diff
checker
Pro
Preise anzeigen
149 Zeilen
Kopieren
package BotFarmServer;
package BotFarmServer;
import java.io.IOException;
import java.io.IOException;
import java.net.URL;
import java.net.URL;
import java.util.HashMap;
import java.util.HashMap;
import java.util.Map;
import java.util.Map;
import java.util.Scanner;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.Pattern;
/**
/**
* Utility class for access to the Grand Exchange API.
* Utility class for access to the Grand Exchange API.
*/
*/
public class GrandExchangeApi {
public class GrandExchangeApi {
private static final String API_LOCATION = "http://services.runescape.com/m=itemdb_oldschool" +
private static final String API_LOCATION = "http://services.runescape.com/m=itemdb_oldschool" +
"/api/catalogue/detail.json?item=%d";
"/api/catalogue/detail.json?item=%d";
private static final long TEN_MINUTES = 600000;
private static final long TEN_MINUTES = 600000;
private final Map<Integer, GELookupResult> cache;
private final Map<Integer, GELookupResult> cache;
private long startTime;
private long startTime;
/**
/**
* Caching-enabled default constructor
* Caching-enabled default constructor
*/
*/
public GrandExchangeApi() {
public GrandExchangeApi() {
this(true);
this(true);
}
}
/**
/**
* Creates a new Grand Exchange API instance. Starts cache-refresh timer.
* Creates a new Grand Exchange API instance. Starts cache-refresh timer.
* @[member='param'] cache Whether to enable caching of results.
* @[member='param'] cache Whether to enable caching of results.
*/
*/
public GrandExchangeApi(boolean cache) {
public GrandExchangeApi(boolean cache) {
startTime = System.currentTimeMillis();
startTime = System.currentTimeMillis();
this.cache = cache ? new HashMap<>() : null;
this.cache = cache ? new HashMap<>() : null;
}
}
/**
/**
* If caching is enabled, clears the cache so that new results are fetched on lookup.
* If caching is enabled, clears the cache so that new results are fetched on lookup.
*/
*/
public void flushCache() {
public void flushCache() {
Kopieren
Kopiert
Kopieren
Kopiert
long currentTime = System.currentTimeMillis();
if(cache != null) {
if(cache != null) {
Kopieren
Kopiert
Kopieren
Kopiert
cache.clear();
for (Map.Entry<int,GELookupResult>> entry : cache) {
if (currentTime - TEN_MINUTES) > entry.getValue().lastUpdatedAt) {
cache.remove(entry.getKey()); // item is old. it needs to be refreshed
}
}
}
}
}
}
/**
/**
* Looks up an item using the Grand Exchange API. This method blocks while waiting for the API result.
* Looks up an item using the Grand Exchange API. This method blocks while waiting for the API result.
* @[member='param'] itemId the id to look up.
* @[member='param'] itemId the id to look up.
* @return the result returned by the api. May be null if an error has occurred.
* @return the result returned by the api. May be null if an error has occurred.
*/
*/
public GELookupResult lookup(int itemId) {
public GELookupResult lookup(int itemId) {
Kopieren
Kopiert
Kopieren
Kopiert
if((System.currentTimeMillis() - TEN_MINUTES) > startTime){ //Flush cache after 10 minutes. Auto-update prices.
flushCache();
flushCache();
startTime = System.currentTimeMillis();
}
if(cache != null && !cache.isEmpty()) {
if(cache != null && !cache.isEmpty()) {
GELookupResult result = cache.get(itemId);
GELookupResult result = cache.get(itemId);
if(result != null) {
if(result != null) {
return result;
return result;
}
}
}
}
String json;
String json;
try {
try {
URL url = new URL(String.format(API_LOCATION, itemId));
URL url = new URL(String.format(API_LOCATION, itemId));
Scanner scan = new Scanner(url.openStream()).useDelimiter("\\A");
Scanner scan = new Scanner(url.openStream()).useDelimiter("\\A");
json = scan.next();
json = scan.next();
scan.close();
scan.close();
} catch(IOException e) {
} catch(IOException e) {
return null;
return null;
}
}
GELookupResult result = parse(itemId, json);
GELookupResult result = parse(itemId, json);
if(cache != null) {
if(cache != null) {
cache.put(itemId, result);
cache.put(itemId, result);
}
}
return result;
return result;
}
}
/**
/**
* Parses a GELookupResult from the JSON returned by the API.
* Parses a GELookupResult from the JSON returned by the API.
* @[member='param'] itemId The item ID.
* @[member='param'] itemId The item ID.
* @[member='param'] json The JSON returned by the RuneScape's API.
* @[member='param'] json The JSON returned by the RuneScape's API.
* @return The serialized result.
* @return The serialized result.
*/
*/
private static GELookupResult parse(int itemId, String json) {
private static GELookupResult parse(int itemId, String json) {
Pattern pattern = Pattern.compile("\"(?<key>[^\"]+)\":\"(?<value>[^\"]+)\"");
Pattern pattern = Pattern.compile("\"(?<key>[^\"]+)\":\"(?<value>[^\"]+)\"");
Matcher m = pattern.matcher(json);
Matcher m = pattern.matcher(json);
Map<String, String> results = new HashMap<>();
Map<String, String> results = new HashMap<>();
while(m.find()) {
while(m.find()) {
results.put(m.group("key"), m.group("value"));
results.put(m.group("key"), m.group("value"));
}
}
int price = 0;
int price = 0;
Matcher priceMatcher = Pattern.compile("\"price\":(?<price>\\d+)").matcher(json);
Matcher priceMatcher = Pattern.compile("\"price\":(?<price>\\d+)").matcher(json);
if (priceMatcher.find()) {
if (priceMatcher.find()) {
price = Integer.parseInt(priceMatcher.group("price"));
price = Integer.parseInt(priceMatcher.group("price"));
}
}
return new GELookupResult(
return new GELookupResult(
results.get("icon"),
results.get("icon"),
results.get("icon_large"),
results.get("icon_large"),
results.get("type"),
results.get("type"),
results.get("typeIcon"),
results.get("typeIcon"),
results.get("name"),
results.get("name"),
results.get("description"),
results.get("description"),
Boolean.parseBoolean(results.get("members")),
Boolean.parseBoolean(results.get("members")),
itemId,
itemId,
price
price
);
);
}
}
/**
/**
* A class representing a result from an API lookup.
* A class representing a result from an API lookup.
*/
*/
public static final class GELookupResult {
public static final class GELookupResult {
public final String smallIconUrl, largeIconUrl, type, typeIcon, name, itemDescription;
public final String smallIconUrl, largeIconUrl, type, typeIcon, name, itemDescription;
public final boolean isMembers;
public final boolean isMembers;
public final int id, price;
public final int id, price;
Kopieren
Kopiert
Kopieren
Kopiert
public final long lastUpdatedAt;
private GELookupResult(String smallIconUrl,
private GELookupResult(String smallIconUrl,
String largeIconUrl,
String largeIconUrl,
String type,
String type,
String typeIcon,
String typeIcon,
String name,
String name,
String itemDescription,
String itemDescription,
boolean isMembers,
boolean isMembers,
int id,
int id,
int price) {
int price) {
this.smallIconUrl = smallIconUrl;
this.smallIconUrl = smallIconUrl;
this.largeIconUrl = largeIconUrl;
this.largeIconUrl = largeIconUrl;
this.type = type;
this.type = type;
this.typeIcon = typeIcon;
this.typeIcon = typeIcon;
this.name = name;
this.name = name;
this.itemDescription = itemDescription;
this.itemDescription = itemDescription;
this.isMembers = isMembers;
this.isMembers = isMembers;
this.id = id;
this.id = id;
this.price = price;
this.price = price;
Kopieren
Kopiert
Kopieren
Kopiert
this.lastUpdatedAt = System.currentTimeMillis();
}
}
}
}
}
}
Gespeicherte Diffs
Originaltext
Datei öffnen
package BotFarmServer; import java.io.IOException; import java.net.URL; import java.util.HashMap; import java.util.Map; import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * Utility class for access to the Grand Exchange API. */ public class GrandExchangeApi { private static final String API_LOCATION = "http://services.runescape.com/m=itemdb_oldschool" + "/api/catalogue/detail.json?item=%d"; private static final long TEN_MINUTES = 600000; private final Map<Integer, GELookupResult> cache; private long startTime; /** * Caching-enabled default constructor */ public GrandExchangeApi() { this(true); } /** * Creates a new Grand Exchange API instance. Starts cache-refresh timer. * @[member='param'] cache Whether to enable caching of results. */ public GrandExchangeApi(boolean cache) { startTime = System.currentTimeMillis(); this.cache = cache ? new HashMap<>() : null; } /** * If caching is enabled, clears the cache so that new results are fetched on lookup. */ public void flushCache() { if(cache != null) { cache.clear(); } } /** * Looks up an item using the Grand Exchange API. This method blocks while waiting for the API result. * @[member='param'] itemId the id to look up. * @return the result returned by the api. May be null if an error has occurred. */ public GELookupResult lookup(int itemId) { if((System.currentTimeMillis() - TEN_MINUTES) > startTime){ //Flush cache after 10 minutes. Auto-update prices. flushCache(); startTime = System.currentTimeMillis(); } if(cache != null && !cache.isEmpty()) { GELookupResult result = cache.get(itemId); if(result != null) { return result; } } String json; try { URL url = new URL(String.format(API_LOCATION, itemId)); Scanner scan = new Scanner(url.openStream()).useDelimiter("\\A"); json = scan.next(); scan.close(); } catch(IOException e) { return null; } GELookupResult result = parse(itemId, json); if(cache != null) { cache.put(itemId, result); } return result; } /** * Parses a GELookupResult from the JSON returned by the API. * @[member='param'] itemId The item ID. * @[member='param'] json The JSON returned by the RuneScape's API. * @return The serialized result. */ private static GELookupResult parse(int itemId, String json) { Pattern pattern = Pattern.compile("\"(?<key>[^\"]+)\":\"(?<value>[^\"]+)\""); Matcher m = pattern.matcher(json); Map<String, String> results = new HashMap<>(); while(m.find()) { results.put(m.group("key"), m.group("value")); } int price = 0; Matcher priceMatcher = Pattern.compile("\"price\":(?<price>\\d+)").matcher(json); if (priceMatcher.find()) { price = Integer.parseInt(priceMatcher.group("price")); } return new GELookupResult( results.get("icon"), results.get("icon_large"), results.get("type"), results.get("typeIcon"), results.get("name"), results.get("description"), Boolean.parseBoolean(results.get("members")), itemId, price ); } /** * A class representing a result from an API lookup. */ public static final class GELookupResult { public final String smallIconUrl, largeIconUrl, type, typeIcon, name, itemDescription; public final boolean isMembers; public final int id, price; private GELookupResult(String smallIconUrl, String largeIconUrl, String type, String typeIcon, String name, String itemDescription, boolean isMembers, int id, int price) { this.smallIconUrl = smallIconUrl; this.largeIconUrl = largeIconUrl; this.type = type; this.typeIcon = typeIcon; this.name = name; this.itemDescription = itemDescription; this.isMembers = isMembers; this.id = id; this.price = price; } } }
Bearbeitung
Datei öffnen
package BotFarmServer; import java.io.IOException; import java.net.URL; import java.util.HashMap; import java.util.Map; import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * Utility class for access to the Grand Exchange API. */ public class GrandExchangeApi { private static final String API_LOCATION = "http://services.runescape.com/m=itemdb_oldschool" + "/api/catalogue/detail.json?item=%d"; private static final long TEN_MINUTES = 600000; private final Map<Integer, GELookupResult> cache; private long startTime; /** * Caching-enabled default constructor */ public GrandExchangeApi() { this(true); } /** * Creates a new Grand Exchange API instance. Starts cache-refresh timer. * @[member='param'] cache Whether to enable caching of results. */ public GrandExchangeApi(boolean cache) { startTime = System.currentTimeMillis(); this.cache = cache ? new HashMap<>() : null; } /** * If caching is enabled, clears the cache so that new results are fetched on lookup. */ public void flushCache() { long currentTime = System.currentTimeMillis(); if(cache != null) { for (Map.Entry<int,GELookupResult>> entry : cache) { if (currentTime - TEN_MINUTES) > entry.getValue().lastUpdatedAt) { cache.remove(entry.getKey()); // item is old. it needs to be refreshed } } } } /** * Looks up an item using the Grand Exchange API. This method blocks while waiting for the API result. * @[member='param'] itemId the id to look up. * @return the result returned by the api. May be null if an error has occurred. */ public GELookupResult lookup(int itemId) { flushCache(); if(cache != null && !cache.isEmpty()) { GELookupResult result = cache.get(itemId); if(result != null) { return result; } } String json; try { URL url = new URL(String.format(API_LOCATION, itemId)); Scanner scan = new Scanner(url.openStream()).useDelimiter("\\A"); json = scan.next(); scan.close(); } catch(IOException e) { return null; } GELookupResult result = parse(itemId, json); if(cache != null) { cache.put(itemId, result); } return result; } /** * Parses a GELookupResult from the JSON returned by the API. * @[member='param'] itemId The item ID. * @[member='param'] json The JSON returned by the RuneScape's API. * @return The serialized result. */ private static GELookupResult parse(int itemId, String json) { Pattern pattern = Pattern.compile("\"(?<key>[^\"]+)\":\"(?<value>[^\"]+)\""); Matcher m = pattern.matcher(json); Map<String, String> results = new HashMap<>(); while(m.find()) { results.put(m.group("key"), m.group("value")); } int price = 0; Matcher priceMatcher = Pattern.compile("\"price\":(?<price>\\d+)").matcher(json); if (priceMatcher.find()) { price = Integer.parseInt(priceMatcher.group("price")); } return new GELookupResult( results.get("icon"), results.get("icon_large"), results.get("type"), results.get("typeIcon"), results.get("name"), results.get("description"), Boolean.parseBoolean(results.get("members")), itemId, price ); } /** * A class representing a result from an API lookup. */ public static final class GELookupResult { public final String smallIconUrl, largeIconUrl, type, typeIcon, name, itemDescription; public final boolean isMembers; public final int id, price; public final long lastUpdatedAt; private GELookupResult(String smallIconUrl, String largeIconUrl, String type, String typeIcon, String name, String itemDescription, boolean isMembers, int id, int price) { this.smallIconUrl = smallIconUrl; this.largeIconUrl = largeIconUrl; this.type = type; this.typeIcon = typeIcon; this.name = name; this.itemDescription = itemDescription; this.isMembers = isMembers; this.id = id; this.price = price; this.lastUpdatedAt = System.currentTimeMillis(); } } }
Unterschied finden