org.hibernate.bytecode.enhance.internal.tracker.SimpleCollectionTracker Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hibernate-core Show documentation
Show all versions of hibernate-core Show documentation
Hibernate's core ORM functionality
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or .
*/
package org.hibernate.bytecode.enhance.internal.tracker;
import java.util.Arrays;
import org.hibernate.bytecode.enhance.spi.CollectionTracker;
/**
* small low memory class to keep track of the number of elements in a collection
*
* @author Ståle W. Pedersen
*/
public final class SimpleCollectionTracker implements CollectionTracker {
private String[] names;
private int[] sizes;
public SimpleCollectionTracker() {
names = new String[0];
sizes = new int[0];
}
@Override
public void add(String name, int size) {
for ( int i = 0; i < names.length; i++ ) {
if ( names[i].equals( name ) ) {
sizes[i] = size;
return;
}
}
names = Arrays.copyOf( names, names.length + 1 );
names[names.length - 1] = name;
sizes = Arrays.copyOf( sizes, sizes.length + 1 );
sizes[sizes.length - 1] = size;
}
@Override
public int getSize(String name) {
for ( int i = 0; i < names.length; i++ ) {
if ( name.equals( names[i] ) ) {
return sizes[i];
}
}
return -1;
}
}