Diff
checker
텍스트
텍스트
이미지
문서
Excel
폴더
Legal
Enterprise
데스크톱
요금제
로그인
데스크톱 앱 다운로드
텍스트 비교
두 텍스트 파일의 차이점을 찾아보세요
도구
기록
실시간 편집
변경 없는 행 숨기기
줄바꿈 비활성화
레이아웃
나란히 보기
합쳐 보기
비교 단위
스마트
단어
글자
구문 강조
언어 선택
제외
텍스트 변환
첫 변경으로
수정
Diffchecker Desktop
가장 안전하게 Diffchecker를 사용하는 방법. 데스크톱 앱을 사용하면 비교 데이터가 외부로 전송되지 않습니다!
데스크톱 앱 받기
Untitled diff
생성일
10년 전
비교 결과 만료 없음
초기화
내보내기
공유
설명
5 삭제
행
총
삭제
글자
총
삭제
이 기능을 계속 사용하려면 업그레이드해 주세요
Diff
checker
Pro
요금제 보기
145 행
복사
9 추가
행
총
추가
글자
총
추가
이 기능을 계속 사용하려면 업그레이드해 주세요
Diff
checker
Pro
요금제 보기
149 행
복사
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() {
복사
복사됨
복사
복사됨
long currentTime = System.currentTimeMillis();
if(cache != null) {
if(cache != null) {
복사
복사됨
복사
복사됨
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) {
복사
복사됨
복사
복사됨
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;
복사
복사됨
복사
복사됨
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;
복사
복사됨
복사
복사됨
this.lastUpdatedAt = System.currentTimeMillis();
}
}
}
}
}
}
저장된 비교 결과
원본
파일 열기
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; } } }
수정본
파일 열기
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(); } } }
비교하기