Example usage for com.google.common.collect Queues newArrayDeque

List of usage examples for com.google.common.collect Queues newArrayDeque

Introduction

In this page you can find the example usage for com.google.common.collect Queues newArrayDeque.

Prototype

public static <E> ArrayDeque<E> newArrayDeque() 

Source Link

Document

Creates an empty ArrayDeque .

Usage

From source file:core.ConjunctionAgent.java

public ConjunctionAgent(String info, String IDinputTerminalL, String IDinputTerminalR,
        String IDoutputTerminal) {

    super();/*from w  w w . j  av a 2s. c o m*/
    this.setName(this.getName() + "@" + Relayer.getInstance().getAddress().toString());
    this._info = info;
    this._type = "Conjunction";
    this._receivers[0] = new TopicReceiver();
    this._receivers[1] = new TopicReceiver();
    inputTerminalL = new IOTerminal(IDinputTerminalL, "input channel " + _type, _receivers[0], this);
    inputTerminalR = new IOTerminal(IDinputTerminalR, "input channel " + _type, _receivers[1], this);
    outputTerminal = new IOTerminal(IDoutputTerminal, "output channel " + _type, this);
    _outputNotifier = new OQNotifier(this, QoSTuner.NOTIFICATION_PRIORITY);
    Queue<EventBean> selectedL = Queues.newArrayDeque();
    _selectedEvents[0] = selectedL;
    Queue<EventBean> selectedR = Queues.newArrayDeque();
    _selectedEvents[1] = selectedR;
    logger = new MyLogger("ConjunctionMeasures", ConjunctionAgent.class.getName());
    logger.log("Operator, isProduced, Processing Time, InputQ Size, OutputQ Size ");
}

From source file:com.james.codelib.algorithms.graph.directed.BFSPaths.java

private void bfs(int s) {
    ///*  w  w  w .j a  va 2 s .  c  om*/
    marked[s] = true;
    Queue<Integer> queue = Queues.newArrayDeque();
    //
    queue.add(s);
    while (!queue.isEmpty()) {
        //
        int v = queue.remove();
        for (int w : graph.adj(v)) {
            //?
            if (!marked[w]) {
                //???
                edgeTo[w] = v;
                //
                marked[w] = true;
                //
                queue.add(w);
            }
        }
    }

}

From source file:core.DisjunctionAgent.java

public DisjunctionAgent(String info, String IDinputTerminalL, String IDinputTerminalR,
        String IDoutputTerminal) {
    super();/*from  w  ww  .j  a  v a2 s.co  m*/
    this.setName(this.getName() + "@" + Relayer.getInstance().getAddress().toString());
    this._info = info;
    this._type = "Disjunction";
    this._receivers[0] = new TopicReceiver();
    this._receivers[1] = new TopicReceiver();
    inputTerminalL = new IOTerminal(IDinputTerminalL, "input channel " + _type, _receivers[0], this);
    inputTerminalR = new IOTerminal(IDinputTerminalR, "input channel " + _type, _receivers[1], this);
    outputTerminal = new IOTerminal(IDoutputTerminal, "output channel " + _type, this);
    _outputNotifier = new OQNotifier(this, QoSTuner.NOTIFICATION_PRIORITY);
    Queue<EventBean> selectedL = Queues.newArrayDeque();
    _selectedEvents[0] = selectedL;
    Queue<EventBean> selectedR = Queues.newArrayDeque();
    _selectedEvents[1] = selectedR;
    logger = new MyLogger("DisjunctionMeasures", DisjunctionAgent.class.getName());
    logger.log("Operator, isProduced, Processing Time, InputQ Size, OutputQ Size ");
}

From source file:cuchaz.enigma.gui.GuiController.java

public GuiController(Gui gui) {
    this.gui = gui;
    this.deobfuscator = null;
    this.index = null;
    this.currentObfClass = null;
    this.isDirty = false;
    this.referenceStack = Queues.newArrayDeque();
}

From source file:com.voxelplugineering.voxelsniper.brush.BrushChain.java

/**
 * Creates a new {@link BrushChain}.// www  .  j  a v a 2  s  .  c  o  m
 * 
 * @param cmd The command
 * @param brushes The brushes to see the chain with
 */
public BrushChain(String cmd, Brush... brushes) {
    this.cmd = checkNotNull(cmd);
    this.brushes = Queues.newArrayDeque();
    if (brushes != null) {
        for (Brush b : brushes) {
            this.brushes.add(b);
        }
    }
}

From source file:org.decojer.cavaj.utils.SwitchTypes.java

/**
 * Is used for string-switches. Execute switch case BB to create the case value map: string to
 * BB.// w  ww. jav  a  2s.  c o m
 *
 * @param caseBb
 *            case BB
 * @param stringReg
 *            string register
 * @param hash
 *            hash for string
 * @param defaultCase
 *            default case
 * @param string2bb
 *            case value map: string to BB
 * @return {@code true} - success
 */
private static boolean executeBbStringHashCond(final BB caseBb, final int stringReg, final int hash,
        final BB defaultCase, final Map<String, BB> string2bb) {
    final Deque<Object> stack = Queues.newArrayDeque();
    String str = null;
    for (int i = 0; i < caseBb.getOps(); ++i) {
        final Op op = caseBb.getOp(i);
        switch (op.getOptype()) {
        case LOAD:
            stack.push(((LOAD) op).getReg());
            break;
        case PUSH:
            stack.push(((PUSH) op).getValue());
            break;
        case INVOKE:
            final M m = ((INVOKE) op).getM();
            if (!"equals".equals(m.getName()) || !"(Ljava/lang/Object;)Z".equals(m.getDescriptor())) {
                return false;
            }
            final Object value = stack.pop();
            if (!(value instanceof String)) {
                return false;
            }
            if (value.hashCode() != hash) {
                return false;
            }
            final Object reg = stack.pop();
            if ((Integer) reg != stringReg) {
                return false;
            }
            stack.push(true);
            str = (String) value;
            break;
        case JCND:
            final Object equalsResult = stack.pop();
            if (!(equalsResult instanceof Boolean)) {
                return false;
            }
            boolean dir = ((Boolean) equalsResult).booleanValue();
            if (((JCND) op).getCmpType() == CmpType.T_EQ) {
                dir = !dir;
            }
            string2bb.put(str, dir ? caseBb.getTrueSucc() : caseBb.getFalseSucc());
            final E out = dir ? caseBb.getFalseOut() : caseBb.getTrueOut();
            if (out == null) {
                assert false;
                return false;
            }
            if (out.getRelevantEnd() == defaultCase) {
                return true;
            }
            return executeBbStringHashCond(out.getEnd(), stringReg, hash, defaultCase, string2bb);
        default:
            return false;
        }
    }
    return false;
}

From source file:com.palantir.common.base.PrefetchingBatchingVisitable.java

@Override
public <K extends Exception> boolean batchAccept(final int batchSize, AbortingVisitor<? super List<T>, K> v)
        throws K {
    final Queue<List<T>> queue = Queues.newArrayDeque();
    final Lock lock = new ReentrantLock();
    final Condition itemAvailable = lock.newCondition();
    final Condition spaceAvailable = lock.newCondition();
    final AtomicBoolean futureIsDone = new AtomicBoolean(false);
    final AtomicReference<Throwable> exception = new AtomicReference<Throwable>();
    final Stopwatch fetchTime = Stopwatch.createUnstarted();
    final Stopwatch fetchBlockedTime = Stopwatch.createUnstarted();
    final Stopwatch visitTime = Stopwatch.createUnstarted();
    final Stopwatch visitBlockedTime = Stopwatch.createUnstarted();

    Future<?> future = exec.submit(new Runnable() {
        @Override/*from w  ww.j  a v  a2 s.c om*/
        public void run() {
            try {
                fetchTime.start();
                delegate.batchAccept(batchSize, new AbortingVisitor<List<T>, InterruptedException>() {
                    @Override
                    public boolean visit(List<T> item) throws InterruptedException {
                        fetchTime.stop();
                        fetchBlockedTime.start();
                        lock.lock();
                        try {
                            while (queue.size() >= capacity) {
                                spaceAvailable.await();
                            }
                            fetchBlockedTime.stop();
                            queue.add(item);
                            itemAvailable.signalAll();
                        } finally {
                            lock.unlock();
                        }
                        fetchTime.start();
                        return true;
                    }
                });
                fetchTime.stop();
            } catch (InterruptedException e) {
                // shutting down
            } catch (Throwable t) {
                exception.set(t);
            } finally {
                if (fetchTime.isRunning()) {
                    fetchTime.stop();
                }
                if (fetchBlockedTime.isRunning()) {
                    fetchBlockedTime.stop();
                }
                lock.lock();
                try {
                    futureIsDone.set(true);
                    itemAvailable.signalAll();
                } finally {
                    lock.unlock();
                }
            }
        }
    });

    try {
        while (true) {
            List<T> batch;
            visitBlockedTime.start();
            lock.lock();
            try {
                while (queue.isEmpty()) {
                    if (futureIsDone.get()) {
                        if (exception.get() != null) {
                            throw Throwables.rewrapAndThrowUncheckedException(exception.get());
                        }
                        return true;
                    }
                    itemAvailable.await();
                }
                batch = queue.poll();
                spaceAvailable.signalAll();
            } finally {
                lock.unlock();
            }
            visitBlockedTime.stop();
            visitTime.start();
            boolean proceed = v.visit(batch);
            visitTime.stop();
            if (!proceed) {
                return false;
            }
        }
    } catch (InterruptedException e) {
        throw Throwables.rewrapAndThrowUncheckedException(e);
    } finally {
        log.debug("{} timings: fetch {}, fetchBlocked {}, visit {}, visitBlocked {}", name, fetchTime,
                fetchBlockedTime, visitTime, visitBlockedTime);
        future.cancel(true);
    }
}

From source file:core.TimeWindowAgentBase.java

public TimeWindowAgentBase(String info, String IDinputTerminal, String IDoutputTerminal) {
    super();/* ww  w  .  ja  va  2  s  .  c o  m*/
    this.setName(this.getName() + "@" + Relayer.getInstance().getAddress().toString());
    //_sourceStream = new DefaultObservable<EventBean>();
    this._info = info;
    this._type = "Window";
    this._receivers[0] = new TopicReceiver();
    inputTerminal = new IOTerminal(IDinputTerminal, "input channel " + _type, _receivers[0], this);
    outputTerminal = new IOTerminal(IDoutputTerminal, "output channel " + _type, this);
    _outputNotifier = new OQNotifier(this, QoSTuner.NOTIFICATION_PRIORITY);
    Queue<EventBean> selected1 = Queues.newArrayDeque();
    _selectedEvents[0] = selected1;
    activeWindows = ArrayListMultimap.create();
    //activeWindows = Multimaps.synchronizedListMultimap(activeWindows);
    //scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
    timer = new Timer();
    logger = new MyLogger("WindowsMeasures", WindowAgent.class.getName());
    logger.log("Operator, isProduced, Processing Time, InputQ Size, OutputQ Size ");
    r = new TimerHandler(this);
    lock = new ReentrantLock();
}

From source file:org.obm.servlet.filter.qos.util.SuspendingServletUtils.java

public SuspendingServletUtils(SuspendingServlet suspendingServlet) {
    this.suspendingServlet = suspendingServlet;
    continuationQueue = Queues.newArrayDeque();
}

From source file:org.terasology.monitoring.impl.PerformanceMonitorImpl.java

public PerformanceMonitorImpl() {
    timer = (EngineTime) CoreRegistry.get(Time.class);
    activityStack = Queues.newArrayDeque();
    metricData = Lists.newLinkedList();//w  ww.j  av a  2s .  com
    allocationData = Lists.newLinkedList();
    runningTotals = new TObjectLongHashMap<>();
    runningAllocationTotals = new TObjectLongHashMap<>();
    timerTicksPerSecond = 1000;
    currentData = new TObjectLongHashMap<>();
    currentMemData = new TObjectLongHashMap<>();
    spikeData = new TObjectDoubleHashMap<>();
    timeFactor = 1000.0 / timerTicksPerSecond;
    mainThread = Thread.currentThread();

}