Example usage for java.util Vector trimToSize

List of usage examples for java.util Vector trimToSize

Introduction

In this page you can find the example usage for java.util Vector trimToSize.

Prototype

public synchronized void trimToSize() 

Source Link

Document

Trims the capacity of this vector to be the vector's current size.

Usage

From source file:org.apache.usergrid.apm.util.GenerateSimulatedMobileData.java

public synchronized static void expireSessions(Vector<MobileSession> sessions, int numSessionsToExpire) {
    int currentNumberOfSessions = sessions.size();
    System.out.println("Expiring " + numSessionsToExpire + " old sessions");
    int index;//from ww  w  .  j  a  v  a2  s  . c  om
    for (int i = 0; i < numSessionsToExpire; i++) {
        index = generator.nextInt(currentNumberOfSessions - i);
        MobileSession s = sessions.get(index);
        Device d = s.getDevice();
        d.setInUse(false);
        sessions.remove(index);
        s = null;
    }
    sessions.trimToSize();
}

From source file:org.apache.usergrid.apm.util.GenerateSimulatedMobileData.java

public synchronized static void addNewSessions(Vector<MobileSession> sessions, Vector<Device> devices,
        int numSessionToAdd) {

    int numDevices = devices.size();
    int j = 0;//from   w w w. j a v a 2 s  . co  m
    System.out.println("Adding " + numSessionToAdd + " new sessions");
    Device d;
    while (j < numSessionToAdd) {
        d = devices.get(generator.nextInt(numDevices));
        if (!d.isInUse()) {
            d.setInUse(true);
            MobileSession s = new MobileSession();
            s.setDevice(d);
            sessions.add(s);
            j++;
        }
    }
    sessions.trimToSize();

}