
nl.pvanassen.steam.store.helper.AmountHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of steam-api Show documentation
Show all versions of steam-api Show documentation
A Java API to access the Steam community market through the HTTP interface. This may be against the TOS so be careful using it!
package nl.pvanassen.steam.store.helper;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
/**
* Amount helper
*
* @author Paul van Assen
*/
public final class AmountHelper {
/**
* Convert the html amount string to the amount in cents
*
* @param html Html text
* @return Amount in cents
*/
public static int getAmount(String html) {
return fastAmountCache.getUnchecked(html);
}
private static final LoadingCache fastAmountCache = CacheBuilder.newBuilder().concurrencyLevel(32).maximumSize(4096).build(new CacheLoader() {
@Override
public Integer load(String html) throws Exception {
String amount = html;
int idx = html.indexOf('(');
if (idx != -1) {
amount = html.substring(idx + 1, html.indexOf(')') - 1);
}
return Integer.parseInt(amount.replace("€", "").replace("€", "").replace(",", "").replace("-", "0").trim());
}
});
private AmountHelper() {
super();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy