Jump to content

What means


xOx

Recommended Posts

import static BotHoe.GrandExchangeApi.*;

public class Test {
    public static void main(String[] args) {
        GrandExchangeApi exchangeApi = new GrandExchangeApi();
        GELookupResult lookupResult = exchangeApi.lookup(333);
        if(lookupResult != null)
            System.out.println("Item: " + lookupResult.name + " Price: " + lookupResult.price);
    }
}

if

GrandExchangeApi exchangeApi = new GrandExchangeApi(false);
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"));
}

Can someone explain?

Link to comment
Share on other sites

import static BotHoe.GrandExchangeApi.*;

public class Test {
    public static void main(String[] args) {
        GrandExchangeApi exchangeApi = new GrandExchangeApi();
        GELookupResult lookupResult = exchangeApi.lookup(333);
        if(lookupResult != null)
            System.out.println("Item: " + lookupResult.name + " Price: " + lookupResult.price);
    }
}

if

GrandExchangeApi exchangeApi = new GrandExchangeApi(false);

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"));
}

Can someone explain?

 

 

1. Snippet that searches GE data for an object with id 333 and then prints name + price.

2. Part of a JSON parsing method, also for GE data retrieving.

  • Like 1
Link to comment
Share on other sites

1. Snippet that searches GE data for an object with id 333 and then prints name + price.

2. Part of a JSON parsing method, also for GE data retrieving.

 

Thanks.

 

This?

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;
Link to comment
Share on other sites

 

Thanks.

 

This?

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;

 

Ehm...

 

Variables.

 

API_LOCATION -> where the JSON data is retrieved from.

TEN_MINUTES ->  The amount (10 *  60 * 1000 = 600000) of milliseconds contained in 10 minutes.

cache -> A cache, map mapping object ID to GE data.

startTime -> System time when the object was initialized.

 

I'm just guessing from the context, I didn't write this :p

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...