Example usage for java.util ArrayDeque ArrayDeque

List of usage examples for java.util ArrayDeque ArrayDeque

Introduction

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

Prototype

public ArrayDeque(Collection<? extends E> c) 

Source Link

Document

Constructs a deque containing the elements of the specified collection, in the order they are returned by the collection's iterator.

Usage

From source file:org.wso2.andes.task.TaskExecutorService.java

/**
 * Create a Task manager with a given number of threads to process the tasks
 *
 * @param workerCount maximum number of threads spawned to process the tasks
 * @param idleTaskDelayMillis delay set for processing a task with IDLE {@link org.wso2.andes.task.Task.TaskHint}
 * @param threadFactory  thread factory to be used for processing the tasks
 *//*from   www.  ja  v  a 2  s .  c  om*/
public TaskExecutorService(int workerCount, long idleTaskDelayMillis, ThreadFactory threadFactory) {

    taskExecutorPool = Executors.newFixedThreadPool(workerCount, threadFactory);
    this.workerCount = workerCount;
    taskProcessorQueue = new ArrayDeque<>(workerCount);
    taskUpdateExecutorService = Executors.newSingleThreadExecutor(threadFactory);
    taskExceptionHandler = new DefaultExceptionHandler();
    taskHolderDelayQueue = new DelayQueue<>();
    taskHolderRegistry = new ConcurrentHashMap<>();
    this.idleTaskDelayMillis = idleTaskDelayMillis;
}

From source file:com.l2jfree.network.mmocore.ReadWriteThread.java

public ReadWriteThread(MMOController<T, RP, SP> mmoController, MMOConfig config,
        PacketHandler<T, RP, SP> packetHandler) throws IOException {
    super(mmoController, config);

    _bufferSize = config.getBufferSize();
    _helperBufferCount = config.getHelperBufferCount();
    _maxOutgoingPacketsPerPass = config.getMaxOutgoingPacketsPerPass();
    _maxIncomingPacketsPerPass = config.getMaxIncomingPacketsPerPass();
    _maxOutgoingBytesPerPass = config.getMaxOutgoingBytesPerPass();
    _maxIncomingBytesPerPass = config.getMaxIncomingBytesPerPass();
    _byteOrder = config.getByteOrder();/* w  w  w . j ava 2 s .com*/

    _directWriteBuffer = ByteBuffer.allocateDirect(getBufferSize()).order(getByteOrder());
    _writeBuffer = ByteBuffer.allocate(getBufferSize()).order(getByteOrder());
    _readBuffer = ByteBuffer.allocate(getBufferSize()).order(getByteOrder());

    _bufferPool = new ArrayDeque<ByteBuffer>(getHelperBufferCount());
    for (int i = 0; i < getHelperBufferCount(); i++)
        getFreeBuffers().addLast(ByteBuffer.allocate(getBufferSize()).order(getByteOrder()));
    _mmoBuffer = new MMOBuffer();
    _dataSizeHolder = new DataSizeHolder();

    _packetHandler = packetHandler;
    _pendingClose = FastList.newInstance();
}

From source file:edu.odu.cs.cs350.yellow1.jar.ExecuteJar.java

/**
 * Construct a new instance of ExecuteJar
 * @param jar the file object representing the mutant jar to run tests on
 * @param pathToGold the absolutepath to the gold output
 * @param pathToOutputDir the path to output directory
 * @param tests List of file objects reprenting the tests to run on the mutant jar
 *//* w  w  w  . j  a  va  2s  . c om*/
public ExecuteJar(File jar, String pathToGold, String pathToOutputDir, List<File> tests) {
    this.jar = jar;
    this.pathToOutputDir = pathToOutputDir;
    this.pathToGold = pathToGold;
    this.tests = new ArrayDeque<>(tests);
    this.jarName = jar.getName().substring(0, jar.getName().indexOf("."));
    this.didNotExecute = new ArrayList<>();
    this.errFiles = new ArrayList<>();
    this.outFiles = new ArrayList<>();
}

From source file:com.google.gwt.emultest.java.util.ArrayDequeTest.java

public void testConstructorFromCollection() {
    assertEquals(0, new ArrayDeque<>(new ArrayList<>()).size());
    try {//from  w  ww. j  av a 2 s  . co  m
        new ArrayDeque<>(null);
        fail();
    } catch (NullPointerException expected) {
        // expected
    } catch (JavaScriptException expected) {
        // expected
    }

    try {
        new ArrayDeque<>(asList(new Object(), null, new Object()));
        fail();
    } catch (NullPointerException expected) {
    }

    Collection<Object> collection = new ArrayList<>(asList(getFullNonNullElements()));
    checkDequeSizeAndContent(new ArrayDeque<>(collection), getFullNonNullElements());
}

From source file:org.apache.sling.etcd.testing.tree.Node.java

@Nonnull
public static Deque<String> names(@Nonnull String key) {
    Deque<String> names = new ArrayDeque<String>(Arrays.asList(key.split("/")));
    if (!names.isEmpty()) {
        names.removeFirst();/*from   www .  j  av  a2  s.co  m*/
    }
    return names;
}

From source file:edu.byu.nlp.al.EmpiricalAnnotationLayersInstanceManager.java

@VisibleForTesting
EmpiricalAnnotationLayersInstanceManager(Iterable<FlatInstance<D, L>> instances,
        EmpiricalAnnotations<D, L> annotations, AnnotationRecorder<D, L> annotationRecorder,
        int maxNumAnnotations, int maxNumMeasurements, boolean prioritizeLabelProportions,
        RandomGenerator rnd) {//  w  w  w .  j ava2s.co m
    super(annotationRecorder);

    // make a mutable collection of all annotations for each instance
    List<FlatInstance<D, L>> sortedAnnotations = Lists.newArrayList();
    Map<String, Deque<FlatInstance<D, L>>> perInstanceAnnotationLists = Maps.newIdentityHashMap();
    for (FlatInstance<D, L> inst : instances) {
        // find all annotations associated with this item
        Collection<FlatInstance<D, L>> anns = annotations.getAnnotationsFor(inst.getSource(), inst.getData())
                .values();
        perInstanceAnnotationLists.put(inst.getSource(), Deques.randomizedDeque(anns, rnd));
    }

    // grab one annotation for each instance until they are gone
    // (annotate the whole corpus 1-deep before starting on 2-deep, and so on)
    while (perInstanceAnnotationLists.size() > 0) {
        Set<String> toRemove = Sets.newHashSet();

        for (String src : Iterables2.shuffled(perInstanceAnnotationLists.keySet(), rnd)) {
            Deque<FlatInstance<D, L>> anns = perInstanceAnnotationLists.get(src);
            if (anns.size() > 0) {
                // add 1 to the queue for this instance
                sortedAnnotations.add(anns.pop());
            }
            if (anns.size() == 0) {
                toRemove.add(src);
            }
        }

        for (String src : toRemove) {
            perInstanceAnnotationLists.remove(src);
        }
    }

    // interleave measurements and annotations in the final queue
    Deque<FlatInstance<D, L>> measurementDeque = Deques.randomizedDeque(annotations.getMeasurements(), rnd);
    prioritizeMeasurements(measurementDeque, prioritizeLabelProportions);
    Deque<FlatInstance<D, L>> annotationDeque = new ArrayDeque<FlatInstance<D, L>>(sortedAnnotations);
    queue = Lists.newLinkedList(); // better queueing behavior

    // add measurements 
    int numMeasurements = 0;
    while (measurementDeque.size() > 0 && numMeasurements < maxNumMeasurements) {
        numMeasurements += 1;
        queue.add(measurementDeque.pop());
    }

    // add annotations 
    int numAnnotations = 0;
    while (annotationDeque.size() > 0 && numAnnotations < maxNumAnnotations) {
        numAnnotations += 1;
        queue.add(annotationDeque.pop());
    }

}

From source file:com.joliciel.talismane.parser.ParseConfigurationImpl.java

public ParseConfigurationImpl(PosTagSequence posTagSequence) {
    super();/*from  w  ww . j  av  a2  s .co  m*/
    this.posTagSequence = posTagSequence;
    PosTaggedToken rootToken = posTagSequence.prependRoot();
    this.underlyingSolutions.add(this.posTagSequence);

    this.buffer = new ArrayDeque<PosTaggedToken>(posTagSequence.size());
    for (PosTaggedToken posTaggedToken : posTagSequence)
        this.buffer.add(posTaggedToken);
    this.buffer.remove(rootToken);

    this.stack = new ArrayDeque<PosTaggedToken>();
    this.stack.push(rootToken);

    this.dependencies = new TreeSet<DependencyArc>();
    this.transitions = new ArrayList<Transition>();
    this.scoringStrategy = new GeometricMeanScoringStrategy<Transition>();
}

From source file:eu.stratosphere.nephele.services.memorymanager.spi.DefaultMemoryManager.java

/**
 * Creates a memory manager with the given capacity and given page size.
 * /*from  w ww .  j  a  va  2 s. c  o m*/
 * @param memorySize The total size of the memory to be managed by this memory manager.
 * @param pageSize The size of the pages handed out by the memory manager.
 */
public DefaultMemoryManager(long memorySize, int pageSize) {
    // sanity checks
    if (memorySize <= 0) {
        throw new IllegalArgumentException("Size of total memory must be positive.");
    }
    if (pageSize < MIN_PAGE_SIZE) {
        throw new IllegalArgumentException("The page size must be at least " + MIN_PAGE_SIZE + " bytes.");
    }
    if ((pageSize & (pageSize - 1)) != 0) {
        // not a power of two
        throw new IllegalArgumentException("The given page size is not a power of two.");
    }

    // assign page size and bit utilities
    this.pageSize = pageSize;
    this.roundingMask = ~((long) (pageSize - 1));
    int log = 0;
    while ((pageSize = pageSize >>> 1) != 0) {
        log++;
    }
    this.pageSizeBits = log;

    this.totalNumPages = getNumPages(memorySize);
    if (this.totalNumPages < 1) {
        throw new IllegalArgumentException("The given amount of memory amounted to less than one page.");
    }

    // initialize the free segments and allocated segments tracking structures
    this.freeSegments = new ArrayDeque<byte[]>(this.totalNumPages);
    this.allocatedSegments = new HashMap<AbstractInvokable, Set<DefaultMemorySegment>>();

    // add the full chunks
    for (int i = 0; i < this.totalNumPages; i++) {
        // allocate memory of the specified size
        this.freeSegments.add(new byte[this.pageSize]);
    }
}

From source file:com.amazon.sqs.javamessaging.SQSMessageConsumerPrefetch.java

SQSMessageConsumerPrefetch(SQSSessionCallbackScheduler sqsSessionRunnable, Acknowledger acknowledger,
        NegativeAcknowledger negativeAcknowledger, SQSQueueDestination sqsDestination,
        AmazonSQSMessagingClientWrapper amazonSQSClient, int numberOfMessagesToPrefetch) {
    this.amazonSQSClient = amazonSQSClient;
    this.numberOfMessagesToPrefetch = numberOfMessagesToPrefetch;

    this.acknowledger = acknowledger;
    this.negativeAcknowledger = negativeAcknowledger;
    queueUrl = sqsDestination.getQueueUrl();
    this.sqsDestination = sqsDestination;
    this.sqsSessionRunnable = sqsSessionRunnable;
    messageQueue = new ArrayDeque<MessageManager>(numberOfMessagesToPrefetch);
}

From source file:org.apache.flink.runtime.memorymanager.DefaultMemoryManager.java

/**
 * Creates a memory manager with the given capacity and given page size.
 * /*  ww  w  .j a  v a  2  s  .c o m*/
 * @param memorySize The total size of the memory to be managed by this memory manager.
 * @param pageSize The size of the pages handed out by the memory manager.
 */
public DefaultMemoryManager(long memorySize, int numberOfSlots, int pageSize) {
    // sanity checks
    if (memorySize <= 0) {
        throw new IllegalArgumentException("Size of total memory must be positive.");
    }
    if (pageSize < MIN_PAGE_SIZE) {
        throw new IllegalArgumentException("The page size must be at least " + MIN_PAGE_SIZE + " bytes.");
    }
    if ((pageSize & (pageSize - 1)) != 0) {
        // not a power of two
        throw new IllegalArgumentException("The given page size is not a power of two.");
    }

    this.memorySize = memorySize;

    this.numberOfSlots = numberOfSlots;

    // assign page size and bit utilities
    this.pageSize = pageSize;
    this.roundingMask = ~((long) (pageSize - 1));
    int log = 0;
    while ((pageSize = pageSize >>> 1) != 0) {
        log++;
    }
    this.pageSizeBits = log;

    this.totalNumPages = getNumPages(memorySize);
    if (this.totalNumPages < 1) {
        throw new IllegalArgumentException("The given amount of memory amounted to less than one page.");
    }

    // initialize the free segments and allocated segments tracking structures
    this.freeSegments = new ArrayDeque<byte[]>(this.totalNumPages);
    this.allocatedSegments = new HashMap<AbstractInvokable, Set<DefaultMemorySegment>>();

    // add the full chunks
    for (int i = 0; i < this.totalNumPages; i++) {
        // allocate memory of the specified size
        this.freeSegments.add(new byte[this.pageSize]);
    }
}