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() 

Source Link

Document

Constructs an empty array deque with an initial capacity sufficient to hold 16 elements.

Usage

From source file:org.apache.metron.profiler.client.window.WindowProcessor.java

public WindowProcessor() {
    this.stack = new ArrayDeque<>();
    this.window = new Window();
}

From source file:com.grepcurl.random.ObjectGenerator.java

public <T> T generate(Class<T> klass) {
    Validate.notNull(klass);//from   w ww .  j a v a 2  s .  c o  m
    if (verbose) {
        log(String.format("generating object of type: %s", klass));
    }
    try {
        Deque<Object> objectStack = new ArrayDeque<>();
        T t;
        if (klass.isEnum()) {
            int randomOrdinal = randomInt(0, klass.getEnumConstants().length - 1);
            t = klass.getEnumConstants()[randomOrdinal];
        } else {
            t = klass.getConstructor().newInstance();
        }
        objectStack.push(t);
        Method[] methods = klass.getMethods();
        for (Method method : methods) {
            _processMethod(method, null, t, objectStack);
        }
        objectStack.pop();
        return t;
    } catch (Exception e) {
        throw new FailedRandomObjectGenerationException(e);
    }
}

From source file:com.endpoint.lg.media.service.MPlayerFifoManagedResource.java

/**
 * Construct the resource./* w  ww.java  2 s  . c o m*/
 * 
 * @param config
 *          the configuration
 * @param log
 *          the logger to use
 */
public MPlayerFifoManagedResource(String id, Configuration config, ExecutorService executorService, Log log,
        String tmpdir) {
    this.executorService = executorService;
    this.log = log;

    printBuffer = new ArrayDeque<String>();
    mplayerFifo = new File(String.format("%s/%s.fifo", tmpdir, id));
}

From source file:gobblin.ingestion.google.webmaster.CollectionEquals.java

/**
 * Test the GoogleWebmasterExtractorIterator to make sure that it first gets all pages based on the filters
 * and then for each page, it asks for the queries.
 * @throws IOException/*from   ww w  . jav  a 2s . co m*/
 */
@Test
public void testIterator() throws IOException {
    GoogleWebmasterDataFetcher client = Mockito.mock(GoogleWebmasterDataFetcher.class);
    String country = "USA";
    String date = "2016-11-01";
    ArrayList<GoogleWebmasterFilter.Dimension> requestedDimensions = new ArrayList<>();
    ArrayList<GoogleWebmasterDataFetcher.Metric> requestedMetrics = new ArrayList<>();

    ArrayDeque<ProducerJob> allJobs = new ArrayDeque<>();
    String page1 = siteProperty + "a/1";
    String page2 = siteProperty + "b/1";
    allJobs.add(new SimpleProducerJob(page1, date, date));
    allJobs.add(new SimpleProducerJob(page2, date, date));
    Mockito.when(client.getAllPages(eq(date), eq(date), eq(country), eq(GoogleWebmasterClient.API_ROW_LIMIT)))
            .thenReturn(allJobs);

    //Set performSearchAnalyticsQuery Mock1
    String[] a1 = { "r1-c1", "r1-c2" };
    List<String[]> results1 = new ArrayList<>();
    results1.add(a1);
    List<ApiDimensionFilter> filters1 = new ArrayList<>();
    filters1.add(GoogleWebmasterFilter.countryEqFilter(country));
    filters1.add(GoogleWebmasterFilter.pageFilter(GoogleWebmasterFilter.FilterOperator.EQUALS, page1));
    Mockito.when(client.performSearchAnalyticsQuery(eq(date), eq(date), eq(GoogleWebmasterClient.API_ROW_LIMIT),
            eq(requestedDimensions), eq(requestedMetrics), argThat(new CollectionEquals(filters1))))
            .thenReturn(results1);

    //Set performSearchAnalyticsQuery Mock2
    String[] a2 = { "r2-c1", "r2-c2" };
    List<String[]> results2 = new ArrayList<>();
    results2.add(a2);
    List<ApiDimensionFilter> filters2 = new ArrayList<>();
    filters2.add(GoogleWebmasterFilter.countryEqFilter(country));
    filters2.add(GoogleWebmasterFilter.pageFilter(GoogleWebmasterFilter.FilterOperator.EQUALS, page2));
    Mockito.when(client.performSearchAnalyticsQuery(eq(date), eq(date), eq(5000), eq(requestedDimensions),
            eq(requestedMetrics), argThat(new CollectionEquals(filters2)))).thenReturn(results2);

    Map<GoogleWebmasterFilter.Dimension, ApiDimensionFilter> map = new HashMap<>();
    map.put(GoogleWebmasterFilter.Dimension.COUNTRY, GoogleWebmasterFilter.countryEqFilter(country));
    WorkUnitState defaultState = GoogleWebmasterExtractorTest.getWorkUnitState1();
    defaultState.setProp(GoogleWebMasterSource.KEY_QUERIES_TUNING_BATCH_SIZE, 1);
    GoogleWebmasterExtractorIterator iterator = new GoogleWebmasterExtractorIterator(client, date, date,
            requestedDimensions, requestedMetrics, map, defaultState);

    List<String[]> response = new ArrayList<>();
    response.add(iterator.next());
    response.add(iterator.next());
    Assert.assertTrue(!iterator.hasNext());
    Assert.assertTrue(response.contains(a1));
    Assert.assertTrue(response.contains(a2));

    Mockito.verify(client, Mockito.times(1)).getAllPages(eq(date), eq(date), eq(country), eq(5000));
    Mockito.verify(client, Mockito.times(1)).performSearchAnalyticsQuery(eq(date), eq(date), eq(5000),
            eq(requestedDimensions), eq(requestedMetrics), argThat(new CollectionEquals(filters1)));
    Mockito.verify(client, Mockito.times(1)).performSearchAnalyticsQuery(eq(date), eq(date), eq(5000),
            eq(requestedDimensions), eq(requestedMetrics), argThat(new CollectionEquals(filters2)));
}

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

public void testAddAll() throws Exception {
    Object o1 = new Object();
    Object o2 = new Object();

    ArrayDeque<Object> deque = new ArrayDeque<>();
    assertTrue(deque.addAll(asList(o1, o2)));
    checkDequeSizeAndContent(deque, o1, o2);

    try {/*from   w ww.j a  v  a  2s.  com*/
        deque = new ArrayDeque<>();
        deque.addAll(asList(o1, null, o2));
        fail();
    } catch (NullPointerException expected) {
    }
}

From source file:co.turnus.analysis.profiler.dynamic.FifoDataBox.java

public FifoDataBox(Fifo fifo, int size) {
    this.fifo = fifo;
    this.size = size;
    tokenProducers = new ArrayDeque<Step>();

    readTokens = new SummaryStatistics();
    writeTokens = new SummaryStatistics();
    occupancy = new SummaryStatistics();

    readMiss = HashMultiset.create();//  w  ww.  j  a v a2  s . c  o m
    writeMiss = HashMultiset.create();
    peeks = HashMultiset.create();

    actionReadTokens = new HashMap<Action, SummaryStatistics>();
    actionWriteTokens = new HashMap<Action, SummaryStatistics>();
}

From source file:com.google.uzaygezen.core.Pow2LengthBitSetRangeFactory.java

@Override
public Map<Pow2LengthBitSetRange, NodeValue<V>> apply(MapNode<BitVector, V> from) {
    if (from == null) {
        return ImmutableMap.of();
    }/*from   w w  w .  j  ava 2s.  c  om*/
    Deque<MapNode<BitVector, V>> inputStack = new ArrayDeque<MapNode<BitVector, V>>();
    Deque<BitVectorWithIterationLevelAndValue> outputStack = new ArrayDeque<BitVectorWithIterationLevelAndValue>();
    inputStack.push(from);
    int n = elementLengthSums.length;
    int bitCount = n == 0 ? 0 : elementLengthSums[n - 1];
    outputStack.push(new BitVectorWithIterationLevelAndValue(BitVectorFactories.OPTIMAL.apply(bitCount), n,
            from.getValue()));
    MapNode<BitVector, V> inputNode;
    Map<Pow2LengthBitSetRange, NodeValue<V>> map = Maps.newHashMap();
    while ((inputNode = inputStack.poll()) != null) {
        BitVectorWithIterationLevelAndValue outputElement = outputStack.poll();
        map.put(new Pow2LengthBitSetRange(outputElement.bitVector,
                outputElement.level == 0 ? 0 : elementLengthSums[outputElement.level - 1]),
                NodeValue.of(outputElement.value, inputNode.getChildren().isEmpty()));
        Preconditions.checkArgument(
                outputElement.level > 0 || (inputNode.getChildren().isEmpty() && outputElement.level >= 0));
        for (Entry<BitVector, MapNode<BitVector, V>> entry : inputNode.getChildren().entrySet()) {
            inputStack.push(entry.getValue());
            BitVector childBitSet = outputElement.bitVector.clone();
            BitVector key = entry.getKey();
            for (int i = key.size() == 0 ? -1 : key.nextSetBit(0); i != -1; i = i == key.size() - 1 ? -1
                    : key.nextSetBit(i + 1)) {
                int bitIndex = (outputElement.level == 1 ? 0 : elementLengthSums[outputElement.level - 2]) + i;
                Preconditions.checkState(bitIndex < bitCount, "bitIndex is too high");
                Preconditions.checkState(!childBitSet.get(bitIndex));
                childBitSet.set(bitIndex);
            }
            outputStack.push(new BitVectorWithIterationLevelAndValue(childBitSet, outputElement.level - 1,
                    entry.getValue().getValue()));
        }
    }
    Preconditions.checkState(outputStack.isEmpty() & !map.isEmpty());
    return map;
}

From source file:com.espertech.esper.view.std.MergeView.java

/**
 * Constructor.// ww w . j av  a 2s  .c om
 * @param groupCriteria is the fields from which to pull the value to group by
 * @param resultEventType is passed by the factory as the factory adds the merged fields to an event type
 */
public MergeView(AgentInstanceViewFactoryChainContext agentInstanceContext, ExprNode[] groupCriteria,
        EventType resultEventType, boolean removable) {
    this.removable = removable;
    if (!removable) {
        parentViews = new ArrayDeque<View>();
    } else {
        parentViews = new HashSet<View>();
    }
    this.agentInstanceContext = agentInstanceContext;
    this.groupFieldNames = groupCriteria;
    this.eventType = resultEventType;
}

From source file:uniol.apt.analysis.isomorphism.IsomorphismLogic.java

private static BidiMap<State, State> checkViaDepthSearch(TransitionSystem lts1, TransitionSystem lts2) {
    BidiMap<State, State> result = new DualHashBidiMap<>();
    Set<String> alphabet = lts1.getAlphabet();
    if (!alphabet.equals(lts2.getAlphabet()))
        // Not isomorphic, there is an arc with a label not occurring in the other lts
        return result;

    Queue<Pair<State, State>> unhandled = new ArrayDeque<>();
    visit(result, unhandled, lts1.getInitialState(), lts2.getInitialState());

    while (!unhandled.isEmpty()) {
        InterrupterRegistry.throwIfInterruptRequestedForCurrentThread();

        Pair<State, State> pair = unhandled.remove();
        State state1 = pair.getFirst();
        State state2 = pair.getSecond();

        for (String label : alphabet) {
            State follow1 = follow(state1, label);
            State follow2 = follow(state2, label);

            if (!visit(result, unhandled, follow1, follow2))
                // Not isomorphic
                return new DualHashBidiMap<>();
        }/*from w w w  .jav  a 2 s.  co  m*/
    }

    return result;
}

From source file:com.espertech.esper.epl.property.PropertyEvaluatorNested.java

public EventBean[] getProperty(EventBean theEvent, ExprEvaluatorContext exprEvaluatorContext) {
    ArrayDeque<EventBean> resultEvents = new ArrayDeque<EventBean>();
    eventsPerStream[0] = theEvent;/*from   w  w  w  .j  a v  a 2s.c  o  m*/
    populateEvents(theEvent, 0, resultEvents, exprEvaluatorContext);
    if (resultEvents.isEmpty()) {
        return null;
    }
    return resultEvents.toArray(new EventBean[resultEvents.size()]);
}