List of usage examples for java.util Deque stream
default Stream<E> stream()
From source file:com.yahoo.elide.core.EntityBinding.java
/** * Convert a deque to a list.//from ww w.j a v a2 s .c o m * * @param deque Deque to convert * @return Deque as a list */ private static List<String> dequeToList(final Deque<String> deque) { ArrayList<String> result = new ArrayList<>(); deque.stream().forEachOrdered(result::add); result.sort(String.CASE_INSENSITIVE_ORDER); return Collections.unmodifiableList(result); }
From source file:nl.knaw.huc.di.tag.tagml.importer.TAGMLListener.java
private TAGMarkup removeFromOpenMarkup(MarkupNameContext ctx) { String markupName = ctx.name().getText(); String extendedMarkupName = markupName; extendedMarkupName = withPrefix(ctx, extendedMarkupName); extendedMarkupName = withSuffix(ctx, extendedMarkupName); boolean isSuspend = ctx.prefix() != null && ctx.prefix().getText().equals(TAGML.SUSPEND_PREFIX); Set<String> layers = deduceLayers(ctx, markupName, extendedMarkupName); boolean layerSuffixNeeded = !(layers.size() == 1 && layers.iterator().next().equals(TAGML.DEFAULT_LAYER)); String foundLayerSuffix = layerSuffixNeeded ? TAGML.DIVIDER/*from w w w.j av a 2 s . c o m*/ + layers.stream().filter(l -> !TAGML.DEFAULT_LAYER.equals(l)).sorted().collect(joining(",")) : ""; extendedMarkupName += foundLayerSuffix; removeFromMarkupStack2(extendedMarkupName, state.allOpenMarkup); TAGMarkup markup = null; for (String l : layers) { state.openMarkup.putIfAbsent(l, new ArrayDeque<>()); Deque<TAGMarkup> markupStack = state.openMarkup.get(l); markup = removeFromMarkupStack(extendedMarkupName, markupStack); if (markup == null) { AtomicReference<String> emn = new AtomicReference<>(extendedMarkupName); boolean markupIsOpen = markupStack.stream().map(TAGMarkup::getExtendedTag) .anyMatch(et -> emn.get().equals(et)); if (!markupIsOpen) { errorListener.addError("%s Close tag <%s] found without corresponding open tag.", errorPrefix(ctx), extendedMarkupName); return null; } else if (!isSuspend) { TAGMarkup expected = markupStack.peek(); if (expected.hasTag(BRANCH)) { errorListener.addBreakingError( "%s Markup [%s> opened before branch %s, should not be closed in a branch.", errorPrefix(ctx), extendedMarkupName, currentTextVariationState().branch + 1); } String hint = l.isEmpty() ? " Use separate layers to allow for overlap." : ""; errorListener.addBreakingError("%s Close tag <%s] found, expected %s.%s", errorPrefix(ctx), extendedMarkupName, closeTag(expected), hint); return null; } else { markup = removeFromMarkupStack2(extendedMarkupName, markupStack); } } document.closeMarkupInLayer(markup, l); } // for the last closing tag, close the markup for the default layer if (!layers.contains(DEFAULT_LAYER) && markup.getLayers().contains(DEFAULT_LAYER)) { Deque<TAGMarkup> markupDeque = state.openMarkup.get(DEFAULT_LAYER); removeFromMarkupStack(extendedMarkupName, markupDeque); document.closeMarkupInLayer(markup, DEFAULT_LAYER); } PrefixContext prefixNode = ctx.prefix(); if (prefixNode != null) { String prefixNodeText = prefixNode.getText(); if (prefixNodeText.equals(OPTIONAL_PREFIX)) { // optional // TODO } else if (prefixNodeText.equals(SUSPEND_PREFIX)) { // suspend for (String l : layers) { state.suspendedMarkup.putIfAbsent(l, new ArrayDeque<>()); state.suspendedMarkup.get(l).add(markup); } } } state.eof = (markup.getDbId().equals(state.rootMarkupId)); if (isSuspend && state.eof) { TAGMarkup rootMarkup = store.getMarkup(state.rootMarkupId); errorListener.addBreakingError("%s The root markup %s cannot be suspended.", errorPrefix(ctx), rootMarkup); } return markup; }
From source file:org.apache.hadoop.hbase.tool.LoadIncrementalHFiles.java
/** * Checks whether there is any invalid family name in HFiles to be bulk loaded. *//*from ww w. j a v a 2s . c o m*/ private void validateFamiliesInHFiles(Table table, Deque<LoadQueueItem> queue, boolean silence) throws IOException { Set<String> familyNames = Arrays.asList(table.getDescriptor().getColumnFamilies()).stream() .map(f -> f.getNameAsString()).collect(Collectors.toSet()); List<String> unmatchedFamilies = queue.stream().map(item -> Bytes.toString(item.getFamily())) .filter(fn -> !familyNames.contains(fn)).distinct().collect(Collectors.toList()); if (unmatchedFamilies.size() > 0) { String msg = "Unmatched family names found: unmatched family names in HFiles to be bulkloaded: " + unmatchedFamilies + "; valid family names of table " + table.getName() + " are: " + familyNames; LOG.error(msg); if (!silence) { throw new IOException(msg); } } }
From source file:org.opensingular.form.wicket.util.WicketFormUtils.java
public static String generateTitlePath(Component parentContainer, SInstance parentContext, Component childComponent, SInstance childInstance) { List<Component> components = Lists.newArrayList(childComponent); WicketUtils.appendListOfParents(components, childComponent, parentContainer); Deque<String> titles = new LinkedList<>(); SInstance lastInstance = null;/*from w w w .ja v a 2 s. co m*/ String lastTitle = null; for (Component comp : components) { SInstance instance = WicketFormUtils.instanciaIfAware(comp.getDefaultModel()).orElse(null); String title = findTitle(comp); if (title != null && !Objects.equal(title, lastTitle)) { lastTitle = title; addTitle(titles, title, instance, lastInstance); } lastInstance = instance; } if (!titles.isEmpty()) { return titles.stream().collect(Collectors.joining(" > ")); } return null; }