Search in sources :

Example 56 with ArrayDeque

use of java.util.ArrayDeque in project mapdb by jankotek.

the class ArrayDequeTest method testEmpty.

/**
     * isEmpty is true before add, false after
     */
public void testEmpty() {
    ArrayDeque q = new ArrayDeque();
    assertTrue(q.isEmpty());
    q.add(new Integer(1));
    assertFalse(q.isEmpty());
    q.add(new Integer(2));
    q.removeFirst();
    q.removeFirst();
    assertTrue(q.isEmpty());
}
Also used : ArrayDeque(java.util.ArrayDeque)

Example 57 with ArrayDeque

use of java.util.ArrayDeque in project mapdb by jankotek.

the class ArrayDequeTest method testRemoveLastOccurrence.

/**
     * removeLastOccurrence(x) removes x and returns true if present
     */
public void testRemoveLastOccurrence() {
    ArrayDeque q = populatedDeque(SIZE);
    for (int i = 1; i < SIZE; i += 2) {
        assertTrue(q.removeLastOccurrence(new Integer(i)));
    }
    for (int i = 0; i < SIZE; i += 2) {
        assertTrue(q.removeLastOccurrence(new Integer(i)));
        assertFalse(q.removeLastOccurrence(new Integer(i + 1)));
    }
    assertTrue(q.isEmpty());
}
Also used : ArrayDeque(java.util.ArrayDeque)

Example 58 with ArrayDeque

use of java.util.ArrayDeque in project mapdb by jankotek.

the class ArrayDequeTest method testRetainAll.

/**
     * retainAll(c) retains only those elements of c and reports true if changed
     */
public void testRetainAll() {
    ArrayDeque q = populatedDeque(SIZE);
    ArrayDeque p = populatedDeque(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        boolean changed = q.retainAll(p);
        assertEquals(changed, (i > 0));
        assertTrue(q.containsAll(p));
        assertEquals(SIZE - i, q.size());
        p.removeFirst();
    }
}
Also used : ArrayDeque(java.util.ArrayDeque)

Example 59 with ArrayDeque

use of java.util.ArrayDeque in project hbase by apache.

the class StochasticLoadBalancer method updateRegionLoad.

/**
   * Store the current region loads.
   */
private synchronized void updateRegionLoad() {
    // We create a new hashmap so that regions that are no longer there are removed.
    // However we temporarily need the old loads so we can use them to keep the rolling average.
    Map<String, Deque<BalancerRegionLoad>> oldLoads = loads;
    loads = new HashMap<>();
    for (ServerName sn : clusterStatus.getServers()) {
        ServerLoad sl = clusterStatus.getLoad(sn);
        if (sl == null) {
            continue;
        }
        for (Entry<byte[], RegionLoad> entry : sl.getRegionsLoad().entrySet()) {
            Deque<BalancerRegionLoad> rLoads = oldLoads.get(Bytes.toString(entry.getKey()));
            if (rLoads == null) {
                // There was nothing there
                rLoads = new ArrayDeque<>();
            } else if (rLoads.size() >= numRegionLoadsToRemember) {
                rLoads.remove();
            }
            rLoads.add(new BalancerRegionLoad(entry.getValue()));
            loads.put(Bytes.toString(entry.getKey()), rLoads);
        }
    }
    for (CostFromRegionLoadFunction cost : regionLoadFunctions) {
        cost.setLoads(loads);
    }
}
Also used : ServerLoad(org.apache.hadoop.hbase.ServerLoad) RegionLoad(org.apache.hadoop.hbase.RegionLoad) ServerName(org.apache.hadoop.hbase.ServerName) Deque(java.util.Deque) ArrayDeque(java.util.ArrayDeque)

Example 60 with ArrayDeque

use of java.util.ArrayDeque in project flink by apache.

the class SerializedCheckpointData method toDeque.

// ------------------------------------------------------------------------
//  De-Serialize from Checkpoint
// ------------------------------------------------------------------------
/**
	 * De-serializes an array of SerializedCheckpointData back into an ArrayDeque of element checkpoints.
	 * 
	 * @param data The data to be deserialized.
	 * @param serializer The serializer used to deserialize the data.
	 * @param <T> The type of the elements.
	 * @return An ArrayDeque of element checkpoints.
	 * 
	 * @throws IOException Thrown, if the serialization fails.
	 */
public static <T> ArrayDeque<Tuple2<Long, List<T>>> toDeque(SerializedCheckpointData[] data, TypeSerializer<T> serializer) throws IOException {
    ArrayDeque<Tuple2<Long, List<T>>> deque = new ArrayDeque<>(data.length);
    DataInputDeserializer deser = null;
    for (SerializedCheckpointData checkpoint : data) {
        byte[] serializedData = checkpoint.getSerializedData();
        if (deser == null) {
            deser = new DataInputDeserializer(serializedData, 0, serializedData.length);
        } else {
            deser.setBuffer(serializedData, 0, serializedData.length);
        }
        final List<T> ids = new ArrayList<>(checkpoint.getNumIds());
        final int numIds = checkpoint.getNumIds();
        for (int i = 0; i < numIds; i++) {
            ids.add(serializer.deserialize(deser));
        }
        deque.addLast(new Tuple2<Long, List<T>>(checkpoint.checkpointId, ids));
    }
    return deque;
}
Also used : ArrayList(java.util.ArrayList) ArrayDeque(java.util.ArrayDeque) Tuple2(org.apache.flink.api.java.tuple.Tuple2) List(java.util.List) ArrayList(java.util.ArrayList) DataInputDeserializer(org.apache.flink.runtime.util.DataInputDeserializer)

Aggregations

ArrayDeque (java.util.ArrayDeque)217 ArrayList (java.util.ArrayList)36 Test (org.junit.Test)36 IOException (java.io.IOException)27 HashMap (java.util.HashMap)23 List (java.util.List)20 HashSet (java.util.HashSet)19 Map (java.util.Map)17 Deque (java.util.Deque)11 Iterator (java.util.Iterator)10 NoSuchElementException (java.util.NoSuchElementException)8 AtomicLong (java.util.concurrent.atomic.AtomicLong)8 File (java.io.File)7 Path (java.nio.file.Path)7 Random (java.util.Random)7 ByteBuffer (java.nio.ByteBuffer)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 HttpFields (org.eclipse.jetty.http.HttpFields)5 Name (com.github.anba.es6draft.ast.scope.Name)4 ExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext)4