com.fasterxml.jackson.databind.ser.impl.JsonSerializerMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of swagger-all Show documentation
Show all versions of swagger-all Show documentation
swagger-all is a rebundled verison of Swagger as one OSGi bundle.
The newest version!
package com.fasterxml.jackson.databind.ser.impl;
import java.util.Map;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ser.SerializerCache.TypeKey;
/**
* Specialized read-only map used for storing and accessing serializers by type.
*/
public class JsonSerializerMap
{
private final Bucket[] _buckets;
private final int _size;
public JsonSerializerMap(Map> serializers)
{
int size = findSize(serializers.size());
_size = size;
int hashMask = (size-1);
Bucket[] buckets = new Bucket[size];
for (Map.Entry> entry : serializers.entrySet()) {
TypeKey key = entry.getKey();
int index = key.hashCode() & hashMask;
buckets[index] = new Bucket(buckets[index], key, entry.getValue());
}
_buckets = buckets;
}
private final static int findSize(int size)
{
// For small enough results (64 or less), we'll require <= 50% fill rate; otherwise 80%
int needed = (size <= 64) ? (size + size) : (size + (size >> 2));
int result = 8;
while (result < needed) {
result += result;
}
return result;
}
/*
/**********************************************************
/* Public API
/**********************************************************
*/
public int size() { return _size; }
public JsonSerializer