Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: LGPL 

import java.awt.image.BufferedImage;

import java.lang.ref.Reference;
import java.lang.ref.SoftReference;

import java.util.HashMap;

import java.util.Map;

public class Main {
    private static final Map<String, Reference<BufferedImage>> imagePool = new HashMap();

    private static BufferedImage getPooledImage(int width, int height, int index) {
        String key = String.format("%dx%d#%d",
                new Object[] { Integer.valueOf(width), Integer.valueOf(height), Integer.valueOf(index) });
        Reference ref = (Reference) imagePool.get(key);
        BufferedImage image = ref == null ? null : (BufferedImage) ref.get();

        if (image == null) {
            image = new BufferedImage(width, height, 2);
            imagePool.put(key, new SoftReference(image));
        }

        return image;
    }
}