Example usage for java.util Queue contains

List of usage examples for java.util Queue contains

Introduction

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

Prototype

boolean contains(Object o);

Source Link

Document

Returns true if this collection contains the specified element.

Usage

From source file:au.org.ala.delta.editor.EditorPreferences.java

/**
 * Adds the supplied filename to the top of the most recently used files.
 * /* www. j a v  a2s .  c  o  m*/
 * @param filename
 */
public static void addFileToMRU(String filename) {

    Queue<String> q = new LinkedList<String>();

    q.add(filename);

    String[] existingFiles = getPreviouslyUsedFiles();
    if (existingFiles != null) {
        for (String existingFile : existingFiles) {
            if (!q.contains(existingFile)) {
                q.add(existingFile);
            }
        }
    }

    StringBuilder b = new StringBuilder();
    for (int i = 0; i < MAX_SIZE_MRU && q.size() > 0; ++i) {
        if (i > 0) {
            b.append(MRU_SEPARATOR);
        }
        b.append(q.poll());
    }

    Preferences prefs = Preferences.userNodeForPackage(DeltaEditor.class);
    prefs.put(MRU_PREF_KEY, b.toString());
    try {
        prefs.sync();
    } catch (BackingStoreException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.clustercontrol.jobmanagement.util.JobMultiplicityCache.java

/**
 * status?100(StatusConstant.TYPE_RUNNING)?????????????
 *
 * ???waitQueue???//from www.  j  a va  2 s  .  c  o m
 * ???waitQueue????????kick??
 * ?????waitQueue???
 *   ??????waitQueue???runningQueue?
 * @param facilityId
 */
public static boolean toRunning(JobSessionNodeEntityPK pk) {
    m_log.info("toRunning " + pk);

    String facilityId = pk.getFacilityId();

    try {
        _lock.writeLock();

        HashMap<String, Queue<JobSessionNodeEntityPK>> waitingCache = getWaitingCache();
        HashMap<String, Queue<JobSessionNodeEntityPK>> runningCache = getRunningCache();

        Queue<JobSessionNodeEntityPK> waitingQueue = waitingCache.get(facilityId);
        Queue<JobSessionNodeEntityPK> runningQueue = runningCache.get(facilityId);

        if (waitingQueue == null) {
            waitingQueue = new LinkedList<JobSessionNodeEntityPK>();
            waitingCache.put(facilityId, waitingQueue);
        }

        if (runningQueue == null) {
            runningQueue = new LinkedList<JobSessionNodeEntityPK>();
            runningCache.put(facilityId, runningQueue);
        }

        if ((runningQueue == null || !runningQueue.contains(pk)) && !waitingQueue.contains(pk)) {
            m_log.debug("toRunning add waitQueue : " + pk);
            waitingQueue.offer(pk);
        }

        storeWaitingCache(waitingCache);
        storeRunningCache(runningCache);

        if (m_log.isDebugEnabled()) {
            for (JobSessionNodeEntityPK q : runningQueue) {
                m_log.debug("toRunning runningQueue : " + q);
            }
            for (JobSessionNodeEntityPK q : waitingQueue) {
                m_log.debug("toRunning waitQueue : " + q);
            }
        }

        // ?waitQueue???
        kick(facilityId);
    } finally {
        _lock.writeUnlock();
    }
    return true;
}

From source file:de.berlios.jhelpdesk.web.ticket.UploadFileController.java

private synchronized void addPathToSession(HttpSession session, String path) {
    Queue<String> paths = (Queue<String>) session.getAttribute("paths");
    if (!paths.contains(path)) {
        paths.add(path);/*from w  w w .j a  v  a 2s  .c  o  m*/
    }
}

From source file:au.org.ala.delta.intkey.ui.UIUtils.java

/**
 * Adds the supplied filename to the top of the most recently used files.
 * //from www . j  ava  2s.  c o  m
 * @param filename
 */
public static void addFileToMRU(String filename, String title, List<Pair<String, String>> existingFiles) {
    // Strip any RTF formatting, and characters used as separators in the MRU text from the title.
    title = RTFUtils.stripFormatting(title);
    title = title.replace(MRU_ITEM_SEPARATOR, " ");
    title = title.replace(MRU_FILES_SEPARATOR, " ");

    Queue<String> q = new LinkedList<String>();

    String newFilePathAndTitle;
    if (StringUtils.isEmpty(title)) {
        newFilePathAndTitle = filename + MRU_ITEM_SEPARATOR + filename;
    } else {
        newFilePathAndTitle = filename + MRU_ITEM_SEPARATOR + title;
    }
    q.add(newFilePathAndTitle);

    if (existingFiles != null) {
        for (Pair<String, String> existingFile : existingFiles) {
            String existingFilePathAndTitle = existingFile.getFirst() + MRU_ITEM_SEPARATOR
                    + existingFile.getSecond();
            if (!q.contains(existingFilePathAndTitle)) {
                q.add(existingFilePathAndTitle);
            }
        }
    }

    StringBuilder b = new StringBuilder();
    for (int i = 0; i < MAX_SIZE_MRU && q.size() > 0; ++i) {
        if (i > 0) {
            b.append(MRU_FILES_SEPARATOR);
        }
        b.append(q.poll());
    }

    Preferences prefs = Preferences.userNodeForPackage(Intkey.class);
    prefs.put(MRU_FILES_PREF_KEY, b.toString());
    try {
        prefs.sync();
    } catch (BackingStoreException e) {
        throw new RuntimeException(e);
    }
}

From source file:asia.stampy.server.listener.subscription.AbstractAcknowledgementListenerAndInterceptor.java

private void startTimerTask(final HostPort hostPort, final String ack) {
    TimerTask task = new TimerTask() {

        @Override/*from w  ww  .ja v  a2 s .c  o  m*/
        public void run() {
            Queue<String> q = messages.get(hostPort);
            if (q == null || !q.contains(ack))
                return;

            getHandler().noAcknowledgementReceived(ack);
            q.remove(ack);
        }
    };

    ackTimer.schedule(task, getAckTimeoutMillis());
}

From source file:asia.stampy.server.listener.subscription.AbstractAcknowledgementListenerAndInterceptor.java

private boolean hasMessageAck(String messageId, HostPort hostPort) {
    Queue<String> ids = messages.get(hostPort);
    if (ids == null || ids.isEmpty())
        return false;

    return ids.contains(messageId);
}

From source file:com.baidu.rigel.biplatform.ac.util.DataModelUtils.java

/**
 * DataModel??//ww  w .  jav  a2s  .co  m
 * 
 * @param dataModel DataModel
 * @throws IllegalAccessException 
 */
private static void buildSortSummary(DataModel dataModel) throws IllegalAccessException {
    List<HeadField> rowLeafs = getLeafNodeList(dataModel.getRowHeadFields());
    if (CollectionUtils.isNotEmpty(rowLeafs)) {
        if (dataModel.getOperateIndex() > rowLeafs.get(0).getCompareDatas().size()) {
            throw new IllegalAccessException("can not access operate index:" + dataModel.getOperateIndex());
        }
        for (HeadField rowHeadField : dataModel.getRowHeadFields()) {
            List<HeadField> leafFileds = rowHeadField.getLeafFileds(true);
            if (CollectionUtils.isNotEmpty(leafFileds)) {

                Queue<HeadField> queue = new LinkedList<HeadField>(leafFileds);
                while (!queue.isEmpty()) {
                    HeadField leafFiled = queue.remove();
                    if (CollectionUtils.isNotEmpty(leafFiled.getCompareDatas())) {
                        leafFiled
                                .setSummarizeData(leafFiled.getCompareDatas().get(dataModel.getOperateIndex()));
                    }
                    HeadField parent = null;
                    if (leafFiled.getParent() != null) {
                        parent = leafFiled.getParent();
                    } else if (leafFiled.getParentLevelField() != null) {
                        parent = leafFiled.getParentLevelField();
                        if (!queue.contains(parent)) {
                            queue.add(parent);
                        }
                    }

                    if (parent != null && CollectionUtils.isEmpty(parent.getCompareDatas())) {
                        parent.setSummarizeData(BigDecimalUtils.addBigDecimal(parent.getSummarizeData(),
                                leafFiled.getSummarizeData()));
                    }
                }
            }

        }
    }
}

From source file:Graph.java

public void bfs(Queue<Node> q) {
    clearState();//  w w w .j a v a  2 s. com
    for (Node n : nodes) {
        n.setState(q.contains(n) ? GRAY : WHITE);
    }
    for (Edge e : edges) {
        e.setMode(UNKNOWN);
    }
    for (Node n : q) {
        n.setDistance(0);
        n.setPredecessor(null);
    }
    while (!q.isEmpty()) {
        Node n = q.remove();
        List<Node> out = findNextNodes(n);
        for (Node m : out) {
            Edge e = findEdge(n, m);
            if (e != null) {
                if (m.getState() == WHITE) {
                    e.setMode(TREE);
                } else if (m.getState() == GRAY) {
                    e.setMode(BACK);
                }
            }
            if (!m.isVisited()) {
                m.setDistance(n.getDistance() + 1);
                m.setPredecessor(n);
                m.setState(GRAY);
                q.offer(m);
            }
        }
        n.setState(BLACK);
    }
    searchState = STATE_BFS;
}

From source file:com.barchart.http.server.TestHttpServer.java

@Test
public void testTooManyConnections() throws Exception {

    final Queue<Integer> status = new LinkedBlockingQueue<Integer>();

    final Runnable r = new Runnable() {
        @Override//from ww w  .  j a v a  2 s .c  o  m
        public void run() {
            try {
                final HttpResponse response = client
                        .execute(new HttpGet("http://localhost:" + port + "/client-disconnect"));
                status.add(response.getStatusLine().getStatusCode());
            } catch (final Exception e) {
                e.printStackTrace();
            }
        }
    };

    final Thread t1 = new Thread(r);
    t1.start();

    final Thread t2 = new Thread(r);
    t2.start();

    t1.join();
    t2.join();

    assertEquals(2, status.size());
    assertTrue(status.contains(200));
    assertTrue(status.contains(503));

}

From source file:com.core.controller.AlgoritmoController.java

public static Solucion busquedaAmplitud(Grafo g, String nodoInicioNombre, String nodoFinNombre) { //funcionna bien
    Solucion result = new Solucion();
    result.setPasos("Algoritmo de Busqueda Primero en Amplitud");
    result.agregarPaso("Cantidad de nodos: " + g.getNodos().size());
    result.agregarPaso("Cantidad de aristas: " + g.getAristas().size());
    Queue<String> cola = new LinkedList<>();
    Queue<String> padresCola = new LinkedList<>();
    List<String> explorados = new ArrayList<>(); //LISTA-NODOS
    List<String> padresExplorados = new ArrayList<>();
    String nodoActual, nodoPadre;
    cola.add(nodoInicioNombre);//w ww  .ja  v a  2s  .  c o  m
    padresCola.add("#");
    while (true) {
        System.out.println(cola);
        if (cola.isEmpty()) {
            result.agregarPaso("No se encontro el nodo destino");
            break;
        }
        nodoActual = cola.poll();
        nodoPadre = padresCola.poll();
        explorados.add(nodoActual);
        padresExplorados.add(nodoPadre);
        if (nodoActual.equals(nodoFinNombre)) {
            result.agregarPaso("Nodo fin alcanzado"); //Mostrar camino
            String nodo = nodoActual;
            String secuenciaResultado = "";
            while (nodo != "#") {
                secuenciaResultado = nodo + " " + secuenciaResultado;
                nodo = padresExplorados.get(explorados.indexOf(nodo));
            }
            result.agregarPaso("Camino solucion: " + secuenciaResultado);
            break;
        }
        List<String> vecinos = g.nodosVecinos(nodoActual);
        Iterator<String> i = vecinos.iterator();
        while (i.hasNext()) {
            String a = i.next();
            if (!explorados.contains(a) && !cola.contains(a)) {
                cola.add(a);
                padresCola.add(nodoActual);
            }
        }
    }
    //Verifico la solucion y la guardo en Solucion
    if (result.getPasos().contains("Nodo fin alcanzado")) {
        String solucion = result.getPasos().split("Nodo fin alcanzado\n")[1];
        String[] array = solucion.split(" ");
        //            ArrayUtils.reverse(array);
        for (String nombreNodo : array) {
            System.out.println("--------------------------------------");
            for (Map.Entry<String, Nodo> n : g.getNodos().entrySet()) {
                System.out.println("Comparando " + n.getKey() + " con " + nombreNodo);
                if (n.getKey().equals(nombreNodo)) {
                    System.out.println("Son iguales! Agregando " + nombreNodo + " a la lista");
                    result.getNodos().add(n.getValue());
                }
            }
        }

        System.out.println(
                "Nodos del resultado final en la lista: " + Arrays.toString(result.getNodos().toArray()));
    }
    return result;
}