Example usage for java.util Queue add

List of usage examples for java.util Queue add

Introduction

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

Prototype

boolean add(E e);

Source Link

Document

Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions, returning true upon success and throwing an IllegalStateException if no space is currently available.

Usage

From source file:com.stehno.sanctuary.core.archive.DefaultFileArchiver.java

@Override
public MessageSet archiveChanges(final ChangeSet changeSet) {
    if (log.isDebugEnabled())
        log.debug("Archiving changes for " + changeSet.getRootDirectory() + "...");

    final MessageSet messageSet = new MessageSet(changeSet.getRootDirectory().getPath());

    final Queue<Future> futures = new LinkedList<Future>();

    int count = 0;
    for (final File file : changeSet.listFiles(FileStatus.NEW)) {
        futures.add(executor.submit(new Runnable() {
            @Override/*  w  w  w .  j a va 2  s  .c o  m*/
            public void run() {
                try {
                    remoteStore.addFile(changeSet.getRootDirectory(), file);
                    localStore.storeFile(file);
                    messageSet.addMessage(file.getPath(), "Added successfully");

                } catch (Exception ex) {
                    messageSet.addError(file.getPath(), "Add failed: " + ex.getMessage());
                }
            }
        }));
        count++;
    }
    if (log.isDebugEnabled())
        log.debug("Scheduled Adds: " + count);

    count = 0;
    for (final File file : changeSet.listFiles(FileStatus.MODIFIED)) {
        futures.add(executor.submit(new Runnable() {
            @Override
            public void run() {
                try {
                    remoteStore.updateFile(changeSet.getRootDirectory(), file);
                    localStore.storeFile(file);
                    messageSet.addMessage(file.getPath(), "Updated successfully");

                } catch (Exception ex) {
                    messageSet.addError(file.getPath(), "Update failed: " + ex.getMessage());
                }

            }
        }));
        count++;
    }
    if (log.isDebugEnabled())
        log.debug("Scheduled Updates: " + count);

    count = 0;
    for (final File file : changeSet.listFiles(FileStatus.DELETED)) {
        futures.add(executor.submit(new Runnable() {
            @Override
            public void run() {
                try {
                    remoteStore.deleteFile(changeSet.getRootDirectory(), file);
                    localStore.removeFile(file);
                    messageSet.addMessage(file.getPath(), "Deleted successfully");

                } catch (Exception ex) {
                    messageSet.addError(file.getPath(), "Delete failed: " + ex.getMessage());
                }

            }
        }));
        count++;
    }
    if (log.isDebugEnabled())
        log.debug("Scheduled Deletes: " + count);

    do {
        while (!futures.isEmpty()) {
            if (futures.peek().isDone()) {
                futures.poll();
            }
        }

        if (collectionWaitTime > 0) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException ie) {
            }
        }

    } while (!futures.isEmpty());

    return messageSet;
}

From source file:objects.PatternEntry.java

public PatternEntry[] segment(Ruleset rule) {
    if (cells.getW() == 0 || cells.getH() == 0) {
        PatternEntry[] returnArray = {};
        return returnArray;
    }/*  w w  w  . j a v a  2 s  .  c om*/
    int startX = 0;
    int startY = 0;
    for (int x = 0; x < cells.getW(); x++)
        for (int y = 0; y < cells.getH(); y++)
            if (cells.pattern[x][y] != 0) {
                startX = x;
                startY = y;
                break;
            }
    boolean[][] isPart = new boolean[cells.getW()][cells.getH()];
    Queue<int[]> knownPoints = new LinkedList<int[]>();
    int[] starterPoint = { startX, startY };
    knownPoints.add(starterPoint);
    isPart[startX][startY] = true;
    while (!knownPoints.isEmpty()) {
        int[] pt = knownPoints.poll();
        for (int[] dP : rule.getNeighborField()) {
            int[] thispt = { pt[0] + dP[0], pt[1] + dP[1] };
            if (Engine.getByte(cells.pattern, thispt[0], thispt[1]) != 0
                    && !Engine.isActive(isPart, thispt[0], thispt[1])) {
                knownPoints.add(thispt);
                isPart[thispt[0]][thispt[1]] = true;
            }
        }
    }

    boolean canSplit = false;
    for (int x = 0; x < cells.getW(); x++)
        for (int y = 0; y < cells.getH(); y++)
            if (cells.pattern[x][y] != 0 && !isPart[x][y])
                canSplit = true;

    if (canSplit) {
        byte[][] cellsOne = new byte[cells.getW()][cells.getH()];
        byte[][] cellsTwo = new byte[cells.getW()][cells.getH()];
        for (int x = 0; x < cells.getW(); x++)
            for (int y = 0; y < cells.getH(); y++) {
                if (isPart[x][y])
                    cellsOne[x][y] = cells.pattern[x][y];
                else
                    cellsTwo[x][y] = cells.pattern[x][y];
            }
        PatternEntry componentPatternOne = new PatternEntry(cellsOne);
        PatternEntry[] getOtherParts = new PatternEntry(cellsTwo).segment(rule);
        return ArrayUtils.addAll(getOtherParts, componentPatternOne);
    }

    PatternEntry[] returnArray = { this };
    return returnArray;

}

From source file:com.feilong.commons.core.util.CollectionsUtilTest.java

/**
 * TestCollectionsUtilTest./* w w w . j  a  va 2 s .c  o m*/
 */
@Test
public void testCollectionsUtilTest33() {
    Queue<Object> queue = new PriorityQueue<Object>();

    queue.add(1);
    queue.add(2);
    queue.add(3);
    queue.add(4);
    queue.add(5);
    queue.add(6);

    if (log.isDebugEnabled()) {
        log.debug(JsonUtil.format(queue));
        log.debug("" + queue.peek());

    }

}

From source file:org.apache.hadoop.tools.rumen.HistoryEventEmitter.java

final Pair<Queue<HistoryEvent>, PostEmitAction> emitterCore(ParsedLine line, String name) {
    Queue<HistoryEvent> results = new LinkedList<HistoryEvent>();
    PostEmitAction removeEmitter = PostEmitAction.NONE;
    for (SingleEventEmitter see : nonFinalSEEs()) {
        HistoryEvent event = see.maybeEmitEvent(line, name, this);
        if (event != null) {
            results.add(event);
        }// w w w.  j a va2  s  .  c om
    }
    for (SingleEventEmitter see : finalSEEs()) {
        HistoryEvent event = see.maybeEmitEvent(line, name, this);
        if (event != null) {
            results.add(event);
            removeEmitter = PostEmitAction.REMOVE_HEE;
            break;
        }
    }
    return new Pair<Queue<HistoryEvent>, PostEmitAction>(results, removeEmitter);
}

From source file:io.fabric8.mockwebserver.internal.InlineWebSocketSessionBuilder.java

private void enqueue(Object req, WebSocketMessage resp) {
    Queue<WebSocketMessage> queuedResponses = session.getRequestEvents().get(req);
    if (queuedResponses == null) {
        queuedResponses = new ArrayDeque<>();
        session.getRequestEvents().put(req, queuedResponses);
    }// w  w  w.ja  v  a2  s.  co m
    queuedResponses.add(resp);
}

From source file:com.qrmedia.commons.persistence.hibernate.clone.HibernateEntityGraphClonerTest.java

/**
 * Checks that the originally specified parameter is used in constructing new 
 * entity/preserve ID flag pairs./*from w  w w.  j a v a  2 s  .c  om*/
 */
@Test
public void addNode() throws IllegalAccessException {
    boolean preserveId = true;
    ReflectionUtils.setValue(entityGraphCloner, "preserveId", preserveId);

    StubHibernateEntity entity = new StubHibernateEntity();
    entityGraphCloner.addEntity(entity);

    Queue<EntityPreserveIdFlagPair> expectedQueue = new LinkedList<EntityPreserveIdFlagPair>();
    expectedQueue.add(new EntityPreserveIdFlagPair(entity, preserveId));
    assertEquals(expectedQueue, ReflectionUtils.getValue(entityGraphCloner, "nodeQueue"));
}

From source file:com.android.pwdhashandroid.pwdhash.PasswordHasher.java

private char[] rotate(char[] arr, int amount) {
    //      Log.d(tag, amount + "x:\t");

    Queue<Character> q = CreateQueue(arr);

    while (amount-- != 0) {
        q.add(q.remove());
        Log.d(tag, q.toString());/*  w ww.  jav  a2  s  . com*/
    }

    Character[] chars = (Character[]) q.toArray(new Character[0]);
    return CharacterToCharArray(chars);

    //      return new char[10]; 

    //      CSQueue q = new CSQueue(arr);
    //      while (amount-- != 0) {
    //         q.put(q.get());
    //         Log.d(tag, new String(q.toArray()));
    //      }
    //
    //      return q.toArray();
}

From source file:org.protempa.backend.ksb.SimpleKnowledgeSourceBackend.java

private Collection<PropositionDefinition> collectSubtreePropositionDefinitionsInt(String[] propIds,
        boolean narrower, boolean inDataSource) {
    ProtempaUtil.checkArray(propIds, "propDefs");
    Set<PropositionDefinition> propResult = new HashSet<>();
    Queue<String> queue = new LinkedList<>();
    for (String pd : propIds) {
        queue.add(pd);
    }// w  ww  . j a va  2s . co m
    while (!queue.isEmpty()) {
        String propId = queue.poll();
        PropositionDefinition pd = this.propDefsMap.get(propId);
        if (!inDataSource || pd.getInDataSource()) {
            propResult.add(pd);
        }
        if (narrower) {
            Arrays.addAll(queue, pd.getChildren());
        } else {
            Arrays.addAll(queue, pd.getInverseIsA());
        }
    }
    return propResult;
}

From source file:org.apache.camel.component.aws.sqs.SqsConsumer.java

protected Queue<Exchange> createExchanges(List<Message> messages) {
    if (LOG.isTraceEnabled()) {
        LOG.trace("Received " + messages.size() + " messages in this poll");
    }/*from  www .j  a v a  2s.c om*/

    Queue<Exchange> answer = new LinkedList<Exchange>();
    for (Message message : messages) {
        Exchange exchange = getEndpoint().createExchange(message);
        answer.add(exchange);
    }

    return answer;
}

From source file:tasly.greathealth.thirdparty.order.OrderCommandsStorage.java

public void addOrderCommand(final ChannelSource channelSource, final EventType eventType,
        final OrderCommand orderCommand) {
    Map<EventType, Queue<OrderCommand>> sourceCmds = commands.get(channelSource);
    if (sourceCmds == null) {
        sourceCmds = new ConcurrentHashMap<EventType, Queue<OrderCommand>>();
        commands.put(channelSource, sourceCmds);
    }/*ww  w  . j  av a  2 s . co  m*/

    Queue<OrderCommand> eventCmds = sourceCmds.get(eventType);
    if (eventCmds == null) {
        eventCmds = new LinkedList<OrderCommand>();
        sourceCmds.put(eventType, eventCmds);
    }

    final Queue<OrderCommand> cmds = sourceCmds.get(eventType);
    if (cmds != null) {
        synchronized (cmds) {
            cmds.add(orderCommand);
            final StoragePara para = new StoragePara();
            para.eventType = eventType;
            para.channelSource = channelSource;
            this.setChanged();
            this.notifyObservers(para);
        }
    }
}