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

com.fasterxml.cachemate.converters.StringKeyConverter Maven / Gradle / Ivy

There is a newer version: 0.5.0
Show newest version
package com.fasterxml.cachemate.converters;

import com.fasterxml.cachemate.KeyConverter;
import com.fasterxml.cachemate.PlatformConstants;

public class StringKeyConverter extends KeyConverter
{
    private final static int BASE_MEM_USAGE = PlatformConstants.BASE_OBJECT_MEMORY_USAGE 
        + (2 * PlatformConstants.BASE_FIELD_MEMORY_USAGE);

    public final static StringKeyConverter instance = new StringKeyConverter();
    
    @Override
    public int keyHash(String key) {
        return key.hashCode();
    }

    @Override
    public int keyWeight(String key)
    {
        // chars take 2 bytes, so:
        return BASE_MEM_USAGE + (key.length() << 1);
    }

    @Override
    public boolean keysEqual(String key1, String key2) {
        return (key1 == key2) || key1.equals(key2);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy