class AbstractResourceIconProvider implements IconProvider {

    @Override
    public @Nullable InputStream getIcon(String category, String iconSetId, @Nullable String state, Format format) {
        String resourceWithoutState = category.toLowerCase() + "." + format.toString().toLowerCase();
        if (state == null) {
            return getResource(iconSetId, resourceWithoutState);
        }

        String iconState;
        if (state.contains(" ")) {
            try {
                String firstPart = state.substring(0, state.indexOf(" "));
                Double.valueOf(firstPart);
                iconState = firstPart;
            } catch (NumberFormatException e) {
                // firstPart is not a number, pass on the full state
                iconState = state;
            }
        } else {
            iconState = state;
        }

        String resourceWithState = category.toLowerCase() + "-" + iconState.toLowerCase() + "."
                + format.toString().toLowerCase();
        if (hasResource(iconSetId, resourceWithState)) {
            return getResource(iconSetId, resourceWithState);
        } else {
            // let's treat all percentage-based categories
            try {
                Double stateAsDouble = Double.valueOf(iconState);
                if (stateAsDouble >= 0 && stateAsDouble <= 100) {
                    for (int i = stateAsDouble.intValue(); i >= 0; i--) {
                        String resourceWithNumberState = category.toLowerCase() + "-" + i + "."
                                + format.toString().toLowerCase();
                        if (hasResource(iconSetId, resourceWithNumberState)) {
                            return getResource(iconSetId, resourceWithNumberState);
                        }
                    }
                }
            } catch (NumberFormatException e) {
                // does not seem to be a number, so ignore it
            }
            logger.debug("Use icon {} as {} is not found", resourceWithoutState, resourceWithState);
            return getResource(iconSetId, resourceWithoutState);
        }
    }

    public  AbstractResourceIconProvider(final TranslationProvider i18nProvider);

}