List of usage examples for java.util Queue size
int size();
From source file:org.jboss.aerogear.sync.jsonmergepatch.server.JsonPatchInMemoryDataStoreTest.java
@Test public void getEdits() { final String documentId = "12345"; final String clientId = "client1"; final ServerInMemoryDataStore<JsonNode, JsonMergePatchEdit> dataStore = new ServerInMemoryDataStore<JsonNode, JsonMergePatchEdit>(); final JsonMergePatchEdit editOne = JsonMergePatchEdit.withChecksum("bogus").clientVersion(0).build(); final JsonMergePatchEdit editTwo = JsonMergePatchEdit.withChecksum("bogus").clientVersion(1).build(); dataStore.saveEdits(editOne, documentId, clientId); dataStore.saveEdits(editTwo, documentId, clientId); final Queue<JsonMergePatchEdit> edits = dataStore.getEdits(documentId, clientId); assertThat(edits.size(), is(2)); final Iterator<JsonMergePatchEdit> iterator = edits.iterator(); assertThat(iterator.next().clientVersion(), is(0L)); assertThat(iterator.next().clientVersion(), is(1L)); }
From source file:org.opentestsystem.airose.docquality.processors.PassiveSentencesQualityProcessor.java
private boolean checkPassive(AbstractDocument doc, Parse p) { Queue<Parse> queue = new LinkedList<Parse>(); queue.add(p);/*from w ww. j ava2 s . c o m*/ while (queue.size() > 0) { p = queue.remove(); String parseType = p.getType(); if ((parseType.length() >= 2) && StringUtils.equalsIgnoreCase(parseType.substring(0, 2), "VB")) { String word = p.getText().substring(p.getSpan().getStart(), p.getSpan().getStart() + p.getSpan().length()); List<String> roots = wordnet.getBaseWords(word, EnumPOS.VERB); if ((roots.size() > 0) && (StringUtils.endsWithIgnoreCase(roots.get(0), "be"))) { return true; } else return false; } else { for (Parse child : p.getChildren()) queue.add(child); } } return false; }
From source file:io.netty.handler.codec.compression.JdkZlibTest.java
@Test // verifies backward compatibility public void testConcatenatedStreamsReadFirstOnly() throws IOException { EmbeddedChannel chDecoderGZip = new EmbeddedChannel(createDecoder(ZlibWrapper.GZIP)); try {//from w ww. j av a2 s.co m byte[] bytes = IOUtils.toByteArray(getClass().getResourceAsStream("/multiple.gz")); assertTrue(chDecoderGZip.writeInbound(Unpooled.copiedBuffer(bytes))); Queue<Object> messages = chDecoderGZip.inboundMessages(); assertEquals(1, messages.size()); ByteBuf msg = (ByteBuf) messages.poll(); assertEquals("a", msg.toString(CharsetUtil.UTF_8)); ReferenceCountUtil.release(msg); } finally { assertFalse(chDecoderGZip.finish()); chDecoderGZip.close(); } }
From source file:com.github.rvesse.airline.model.MetadataLoader.java
/** * Loads global meta-data// w w w.ja va 2s .c o m * * @param name * CLI name * @param description * CLI description * @param defaultCommand * Default Command * @param defaultGroupCommands * Default Group Commands * @param groups * Command Groups * @param parserConfig * Parser Configuration * @param restrictions * Restrictions * @return Global meta-data */ public static <C> GlobalMetadata<C> loadGlobal(String name, String description, CommandMetadata defaultCommand, Iterable<CommandMetadata> defaultGroupCommands, Iterable<CommandGroupMetadata> groups, Iterable<GlobalRestriction> restrictions, ParserMetadata<C> parserConfig) { List<OptionMetadata> globalOptions = new ArrayList<>(); if (defaultCommand != null) { globalOptions.addAll(defaultCommand.getGlobalOptions()); } for (CommandMetadata command : defaultGroupCommands) { globalOptions.addAll(command.getGlobalOptions()); } for (CommandGroupMetadata group : groups) { for (CommandMetadata command : group.getCommands()) { globalOptions.addAll(command.getGlobalOptions()); } // Remember to also search sub-groups for global options Queue<CommandGroupMetadata> subGroups = new LinkedList<CommandGroupMetadata>(); subGroups.addAll(group.getSubGroups()); while (subGroups.size() > 0) { CommandGroupMetadata subGroup = subGroups.poll(); for (CommandMetadata command : subGroup.getCommands()) { globalOptions.addAll(command.getGlobalOptions()); } subGroups.addAll(subGroup.getSubGroups()); } } globalOptions = ListUtils.unmodifiableList(mergeOptionSet(globalOptions)); return new GlobalMetadata<C>(name, description, globalOptions, defaultCommand, defaultGroupCommands, groups, restrictions, parserConfig); }
From source file:io.netty.handler.codec.compression.JdkZlibTest.java
@Test public void testConcatenatedStreamsReadFully() throws IOException { EmbeddedChannel chDecoderGZip = new EmbeddedChannel(new JdkZlibDecoder(true)); try {/* w ww .j a v a2s.c o m*/ byte[] bytes = IOUtils.toByteArray(getClass().getResourceAsStream("/multiple.gz")); assertTrue(chDecoderGZip.writeInbound(Unpooled.copiedBuffer(bytes))); Queue<Object> messages = chDecoderGZip.inboundMessages(); assertEquals(2, messages.size()); for (String s : Arrays.asList("a", "b")) { ByteBuf msg = (ByteBuf) messages.poll(); assertEquals(s, msg.toString(CharsetUtil.UTF_8)); ReferenceCountUtil.release(msg); } } finally { assertFalse(chDecoderGZip.finish()); chDecoderGZip.close(); } }
From source file:org.openmrs.module.kenyaemr.converter.StringToRegimenConverter.java
/** * @see org.springframework.core.convert.converter.Converter#convert(Object) */// w w w. jav a 2 s. co m @Override public Regimen convert(String source) { String[] tokens = source.split("\\|", -1); Queue<String> tokenQueue = new LinkedList<String>(Arrays.asList(tokens)); Regimen regimen = new Regimen(); while (tokenQueue.size() >= 4) { String drugRefStr = tokenQueue.remove().trim(); String doseStr = tokenQueue.remove().trim(); String units = tokenQueue.remove().trim(); String frequency = tokenQueue.remove().trim(); DrugReference drugRef = StringUtils.isNotEmpty(drugRefStr) ? drugReferenceConverter.convert(drugRefStr) : null; Double dose = StringUtils.isNotEmpty(doseStr) ? Double.parseDouble(doseStr) : null; units = StringUtils.isNotEmpty(units) ? units : null; frequency = StringUtils.isNotEmpty(frequency) ? frequency : null; regimen.getComponents().add(new RegimenComponent(drugRef, dose, units, frequency)); } return regimen; }
From source file:br.com.i9torpedos.model.service.sms.DServiceModem1.java
/** * @param fila//from w ww . j a v a 2 s.c o m */ public void setFilaSMS(Queue<SendSMSMessage> fila) { System.err.println("Vindo: " + fila.size()); this.filaSMS.addAll(filaSMS); System.err.println("Depois: " + filaSMS.size()); }
From source file:org.kuali.kfs.module.purap.document.validation.impl.PurchasingAccountsPayableObjectCodeOverrideBranchingValidation.java
/** * Recursively refreshes a property given by the queue path * @param bo the business object to refresh * @param path the path, in Queue form, of properties to refresh *//*from w w w . ja va 2 s . c o m*/ protected void refreshByQueue(PersistableBusinessObject bo, Queue<String> path) { if (path.size() > 1) { // we know that the last thing on our list is a code. why refresh that? String currentProperty = path.remove(); bo.refreshReferenceObject(currentProperty); PersistableBusinessObject childBO = (PersistableBusinessObject) ObjectUtils.getPropertyValue(bo, currentProperty); if (!ObjectUtils.isNull(childBO)) { refreshByQueue(childBO, path); } } }
From source file:com.github.rvesse.airline.model.MetadataLoader.java
public static <C> GlobalMetadata<C> loadGlobal(Class<?> cliClass) { Annotation annotation = cliClass.getAnnotation(com.github.rvesse.airline.annotations.Cli.class); if (annotation == null) throw new IllegalArgumentException( String.format("Class %s does not have the @Cli annotation", cliClass)); com.github.rvesse.airline.annotations.Cli cliConfig = (com.github.rvesse.airline.annotations.Cli) annotation; // Prepare commands CommandMetadata defaultCommand = null; if (!cliConfig.defaultCommand().equals(com.github.rvesse.airline.annotations.Cli.NO_DEFAULT.class)) { defaultCommand = loadCommand(cliConfig.defaultCommand()); }/* w w w .j av a 2 s .c om*/ List<CommandMetadata> defaultGroupCommands = new ArrayList<CommandMetadata>(); for (Class<?> cls : cliConfig.commands()) { defaultGroupCommands.add(loadCommand(cls)); } // Prepare parser configuration ParserMetadata<C> parserConfig = cliConfig.parserConfiguration() != null ? MetadataLoader.<C>loadParser(cliConfig.parserConfiguration()) : MetadataLoader.<C>loadParser(cliClass); // Prepare restrictions // We find restrictions in the following order: // 1 - Those declared via annotations // 2 - Those declared via the restrictions field of the @Cli annotation // 3 - Standard restrictions if the includeDefaultRestrctions field of // the @Cli annotation is true List<GlobalRestriction> restrictions = new ArrayList<GlobalRestriction>(); for (Class<? extends Annotation> annotationClass : RestrictionRegistry .getGlobalRestrictionAnnotationClasses()) { annotation = cliClass.getAnnotation(annotationClass); if (annotation == null) continue; GlobalRestriction restriction = RestrictionRegistry.getGlobalRestriction(annotationClass, annotation); if (restriction != null) restrictions.add(restriction); } for (Class<? extends GlobalRestriction> cls : cliConfig.restrictions()) { restrictions.add(ParserUtil.createInstance(cls)); } if (cliConfig.includeDefaultRestrictions()) { restrictions.addAll(AirlineUtils.arrayToList(GlobalRestriction.DEFAULTS)); } // Prepare groups // We sort sub-groups by name length then lexically // This means that when we build the groups hierarchy we'll ensure we // build the parent groups first wherever possible Map<String, CommandGroupMetadata> subGroups = new TreeMap<String, CommandGroupMetadata>( new StringHierarchyComparator()); List<CommandGroupMetadata> groups = new ArrayList<CommandGroupMetadata>(); for (Group groupAnno : cliConfig.groups()) { String groupName = groupAnno.name(); String subGroupPath = null; if (StringUtils.containsWhitespace(groupName)) { // Normalize the path subGroupPath = StringUtils.join(StringUtils.split(groupAnno.name()), ' '); } // Maybe a top level group we've already seen CommandGroupMetadata group = CollectionUtils.find(groups, new GroupFinder(groupName)); if (group == null) { // Maybe a sub-group we've already seen group = subGroups.get(subGroupPath); } List<CommandMetadata> groupCommands = new ArrayList<CommandMetadata>(); for (Class<?> cls : groupAnno.commands()) { groupCommands.add(loadCommand(cls)); } if (group == null) { // Newly discovered group //@formatter:off group = loadCommandGroup(subGroupPath != null ? subGroupPath : groupName, groupAnno.description(), groupAnno.hidden(), Collections.<CommandGroupMetadata>emptyList(), !groupAnno.defaultCommand().equals(Group.NO_DEFAULT.class) ? loadCommand(groupAnno.defaultCommand()) : null, groupCommands); //@formatter:on if (subGroupPath == null) { groups.add(group); } else { // Remember sub-groups for later subGroups.put(subGroupPath, group); } } else { for (CommandMetadata cmd : groupCommands) { group.addCommand(cmd); } } } // Build sub-group hierarchy buildGroupsHierarchy(groups, subGroups); // Find all commands List<CommandMetadata> allCommands = new ArrayList<CommandMetadata>(); allCommands.addAll(defaultGroupCommands); if (defaultCommand != null && !defaultGroupCommands.contains(defaultCommand)) { allCommands.add(defaultCommand); } for (CommandGroupMetadata group : groups) { allCommands.addAll(group.getCommands()); if (group.getDefaultCommand() != null) { allCommands.add(group.getDefaultCommand()); } Queue<CommandGroupMetadata> subGroupsQueue = new LinkedList<CommandGroupMetadata>(); subGroupsQueue.addAll(group.getSubGroups()); while (subGroupsQueue.size() > 0) { CommandGroupMetadata subGroup = subGroupsQueue.poll(); allCommands.addAll(subGroup.getCommands()); if (subGroup.getDefaultCommand() != null) allCommands.add(subGroup.getDefaultCommand()); subGroupsQueue.addAll(subGroup.getSubGroups()); } } // Post-process to find possible further group assignments loadCommandsIntoGroupsByAnnotation(allCommands, groups, defaultGroupCommands); return loadGlobal(cliConfig.name(), cliConfig.description(), defaultCommand, defaultGroupCommands, groups, restrictions, parserConfig); }
From source file:org.apache.camel.component.aws.sqs.SqsConsumer.java
public int processBatch(Queue<Object> exchanges) throws Exception { int total = exchanges.size(); for (int index = 0; index < total && isBatchAllowed(); index++) { // only loop if we are started (allowed to run) Exchange exchange = ObjectHelper.cast(Exchange.class, exchanges.poll()); // add current index and total as properties exchange.setProperty(Exchange.BATCH_INDEX, index); exchange.setProperty(Exchange.BATCH_SIZE, total); exchange.setProperty(Exchange.BATCH_COMPLETE, index == total - 1); // update pending number of exchanges pendingExchanges = total - index - 1; // add on completion to handle after work when the exchange is done exchange.addOnCompletion(new Synchronization() { public void onComplete(Exchange exchange) { processCommit(exchange); }//from w ww. j av a 2 s . c om public void onFailure(Exchange exchange) { processRollback(exchange); } @Override public String toString() { return "SqsConsumerOnCompletion"; } }); if (LOG.isTraceEnabled()) { LOG.trace("Processing exchange [" + exchange + "]..."); } getProcessor().process(exchange); } return total; }