All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nl.pvanassen.steam.store.helper.AmountHelper Maven / Gradle / Ivy

Go to download

A Java API to access the Steam community market through the HTTP interface. This may be against the TOS so be careful using it!

There is a newer version: 3.0.8
Show newest version
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