<commit_before>package com.nullprogram.chess.pieces;

import java.util.WeakHashMap;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;

import javax.imageio.ImageIO;

/**
 * Serves cached images of requsted size.
 *
 * This will cache the recent requests so it's not hitting the disk
 * every time the display needs an image.
 */
public class ImageServer {

    /**
     * Hidden constructor.
     */
    protected ImageServer() {
    }

    /** The image cache. */
    private static WeakHashMap<CacheKey, BufferedImage> cache
    = new WeakHashMap<CacheKey, BufferedImage>();

    /**
     * A key to an image in the cache.
     */
    private static class CacheKey {

        /**
         * File name of the image.
         */
        private String filename;

        /**
         * Requested size of the image.
         */
        private int size;

        /**
         * Create a new key with given name and size.
         *
         * @param name    filename
         * @param reqSize requested size
         */
        public CacheKey(final String name, final int reqSize) {
            filename = name;
            size = size;
        }

        /** {@inheritDoc} */
        public int hashCode() {
            return filename.hashCode() ^ size;
        }

        /** {@inheritDoc} */
        public final boolean equals(final Object that) {
            if (this == that) {
                return true;
            }
            if (!(that instanceof CacheKey)) {
                return false;
            }
            CacheKey key = (CacheKey) that;
            return key.hashCode() == hashCode();
        }
    }

    /**
     * Return named image scaled to given size.
     *
     * @param name name of the image
     * @param size size of the returned image
     * @return     the requested image
     */
    public static BufferedImage getTile(final String name, final int size) {
        CacheKey key = new CacheKey(name, size);
        BufferedImage cached = cache.get(key);
        if (cached != null) {
            return cached;
        }

        BufferedImage orig = null, image = null;
        try {
            orig = ImageIO.read(ImageServer.class.getResource(name + ".png"));<commit_msg>Make CacheKey in ImageServer work better.<commit_after>package com.nullprogram.chess.pieces;

import java.util.WeakHashMap;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;

import javax.imageio.ImageIO;

/**
 * Serves cached images of requsted size.
 *
 * This will cache the recent requests so it's not hitting the disk
 * every time the display needs an image.
 */
public class ImageServer {

    /**
     * Hidden constructor.
     */
    protected ImageServer() {
    }

    /** The image cache. */
    private static WeakHashMap<CacheKey, BufferedImage> cache
    = new WeakHashMap<CacheKey, BufferedImage>();

    /**
     * A key to an image in the cache.
     */
    private static final class CacheKey {

        /** File name of the image. */
        private String filename;

        /** Requested size of the image. */
        private int size;

        /** Seed for the hashCode() function. */
        static final int SEED = 0xc54c8016;

        /**
         * Create a new key with given name and size.
         *
         * @param name    filename
         * @param reqSize requested size
         */
        private CacheKey(final String name, final int reqSize) {
            filename = name;
            size = reqSize;
        }

        /** {@inheritDoc} */
        public int hashCode() {
            return filename.hashCode()
                ^ (SEED * (size << (size % (2 * 2))));
        }

        /** {@inheritDoc} */
        public boolean equals(final Object that) {
            if (this == that) {
                return true;
            }
            if (!(that instanceof CacheKey)) {
                return false;
            }
            CacheKey key = (CacheKey) that;
            return filename.equals(key.filename) && (size == key.size);
        }
    }

    /**
     * Return named image scaled to given size.
     *
     * @param name name of the image
     * @param size size of the returned image
     * @return     the requested image
     */
    public static BufferedImage getTile(final String name, final int size) {
        CacheKey key = new CacheKey(name, size);
        BufferedImage cached = cache.get(key);
        if (cached != null) {
            return cached;
        }

        BufferedImage orig = null, image = null;
        try {
            orig = ImageIO.read(ImageServer.class.getResource(name + ".png"));
{'fraction_non_alphanumeric': 0.09867577958137548, 'fraction_numerical': 0.002349423323366083, 'mean_word_length': 1.7644628099173554, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1209864', 'n_tokens_mistral': 1267, 'n_tokens_neox': 1228, 'n_words': 413}