Jump to content

What means


Recommended Posts

Posted
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?

Posted
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
Posted

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;
Posted

 

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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