List of usage examples for java.util.stream Collectors joining
public static Collector<CharSequence, ?, String> joining(CharSequence delimiter, CharSequence prefix, CharSequence suffix)
From source file:com.diversityarrays.kdxplore.field.CollectionPathPanel.java
public CollectionPathPanel(boolean wantPlotsPerGroup, BiConsumer<VisitOrder2D, PlotsPerGroup> onChoiceChanged, List<? extends OrOrTr> onlyThese) { super(new BorderLayout()); plotsPerGroupChoice.setSelectedItem(plotsPerGroup); odtChoicePanel.setOrOrTr(visitOrder); this.onChoiceChanged = onChoiceChanged; if (wantPlotsPerGroup) { plotsPerGroupChoice.addItemListener(new ItemListener() { @Override//from w w w. j av a 2s. c o m public void itemStateChanged(ItemEvent e) { plotsPerGroup = (PlotsPerGroup) plotsPerGroupChoice.getSelectedItem(); onChoiceChanged.accept(visitOrder, plotsPerGroup); } }); Box top = Box.createHorizontalBox(); top.add(new JLabel("Plots Per Group:")); top.add(plotsPerGroupChoice); top.add(Box.createHorizontalGlue()); add(top, BorderLayout.NORTH); } if (!Check.isEmpty(onlyThese)) { OrOrTr first = onlyThese.get(0); odtChoicePanel.setOnlyAllow(onlyThese.toArray(new OrOrTr[onlyThese.size()])); String msg; if (onlyThese.size() == 1) { msg = "<HTML>For now, only supporting:<BR>" + onlyThese.get(0).toString(); } else { msg = onlyThese.stream().map(oot -> oot.toString()) .collect(Collectors.joining("<BR>", "<HTML>For now, only supporting:<BR>", "")); } JLabel label = new JLabel(msg, JLabel.CENTER); label.setForeground(Color.RED); add(label, BorderLayout.SOUTH); } add(odtChoicePanel, BorderLayout.CENTER); }
From source file:com.github.sevntu.checkstyle.ordering.MethodOrder.java
private static String methodsSignatureList(Collection<Method> methods) { return methods.stream().map(Object::toString).collect(Collectors.joining("; ", "[", "]")); }
From source file:com.evolveum.midpoint.common.LocalizationServiceImpl.java
public String translate(LocalizableMessageList msgList, Locale locale) { String separator = translateIfPresent(msgList.getSeparator(), locale); String prefix = translateIfPresent(msgList.getPrefix(), locale); String suffix = translateIfPresent(msgList.getPostfix(), locale); return msgList.getMessages().stream().map(m -> translate(m, locale)) .collect(Collectors.joining(separator, prefix, suffix)); }
From source file:cop.raml.utils.Utils.java
/** * Converts enum constants as array {@code arr} to enum string without any duplication. * * @param arr array of enum items//from w w w . ja va2 s .co m * @return {@code null} or not empty enum string (e.g. [one,two]) */ public static String toEnumStr(String... arr) { Set<String> res = asSet(arr); return res.isEmpty() ? null : res.stream().collect(Collectors.joining(",", "[", "]")); }
From source file:necauqua.mods.cm.asm.ASM.java
public static byte[] doTransform(String className, byte[] original) { ClassPatcher patcher = patchers.get(className); if (patcher != null) { Log.debug("Patching class: " + className); ClassReader reader = new ClassReader(original); ClassWriter writer = new ClassWriter(reader, ClassWriter.COMPUTE_FRAMES) { @Override/* w w w .j a va 2 s.c o m*/ protected String getCommonSuperClass(String type1, String type2) { // HAX defined Class<?> c, d; ClassLoader classLoader = ChiseledMe.class.getClassLoader(); // this one line was breaking stuff :/ fixed try { c = Class.forName(type1.replace('/', '.'), false, classLoader); d = Class.forName(type2.replace('/', '.'), false, classLoader); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e.toString()); } if (c.isAssignableFrom(d)) { return type1; } if (d.isAssignableFrom(c)) { return type2; } if (c.isInterface() || d.isInterface()) { return "java/lang/Object"; } else { do { c = c.getSuperclass(); } while (!c.isAssignableFrom(d)); return c.getName().replace('.', '/'); } } }; ClassPatchVisitor visitor = new ClassPatchVisitor(writer, patcher); try { reader.accept(visitor, ClassReader.SKIP_FRAMES); } catch (Exception e) { Log.error("Couldn't accept patch visitor!", e); } String cls = className.substring(className.lastIndexOf('.') + 1); String stuff; stuff = visitor.unusedPatches.stream().filter(patch -> { if (patch.optional) { Log.debug("One of patches from " + cls + " wasn't applied but ignoring because it's marked as optional (eg. @SideOnly)"); return false; } else { return true; } }).map(p -> cls + "." + p.getMethodNames()).collect(Collectors.joining("\n ", "\n ", "")); if (!stuff.equals("\n ")) { Log.error("\n*** Those methods were not found:" + stuff); throw new IllegalStateException("Coremod failed!"); } stuff = visitor.modifiers.asMap().entrySet().stream() .flatMap(entry -> entry.getValue().stream() .filter(mod -> mod.code == null || !mod.code.succededOnce()) .map(mod -> mod + " from " + cls + "." + entry.getKey())) .collect(Collectors.joining("\n ", "\n ", "")); if (!stuff.equals("\n ")) { Log.error("\n*** Those modifiers were not applied:" + stuff); throw new IllegalStateException("Coremod failed!"); } try { return writer.toByteArray(); } catch (Exception e) { Log.error("Couldn't write patched class!", e); return original; } } return original; }
From source file:org.apache.james.jmap.methods.integration.cucumber.GetMessagesMethodStepdefs.java
private Function<Set<Entry<String, String>>, String> entriesToString() { return entries -> entries.stream().map(this::entryToPair).map(this::joinKeyValue) .collect(Collectors.joining("\r\n", "", "\r\n")); }
From source file:ddf.catalog.transformer.input.pdf.GeoPdfParser.java
/** * Generates a WKT compliant String from a PDF Document if it contains GeoPDF information. * Currently, only WGS84 Projections are supported (GEOGRAPHIC GeoPDF ProjectionType). * * @param pdfDocument - The PDF document * @return the WKT String/*from ww w . j a va 2 s .co m*/ * @throws IOException */ public String getWktFromPDF(PDDocument pdfDocument) throws IOException { ToDoubleVisitor toDoubleVisitor = new ToDoubleVisitor(); LinkedList<String> polygons = new LinkedList<>(); for (PDPage pdPage : pdfDocument.getPages()) { COSDictionary cosObject = pdPage.getCOSObject(); COSBase lgiDictObject = cosObject.getObjectFromPath(LGIDICT); // Handle Multiple Map Frames if (lgiDictObject instanceof COSArray) { for (int i = 0; i < ((COSArray) lgiDictObject).size(); i++) { COSDictionary lgidict = (COSDictionary) cosObject.getObjectFromPath(LGIDICT + "/[" + i + "]"); COSDictionary projectionArray = (COSDictionary) lgidict.getDictionaryObject(PROJECTION); if (projectionArray != null) { String projectionType = ((COSString) projectionArray.getItem(PROJECTION_TYPE)).getString(); if (GEOGRAPHIC.equals(projectionType)) { COSArray neatlineArray = (COSArray) cosObject .getObjectFromPath(LGIDICT + "/[" + i + "]/" + NEATLINE); String wktString = getWktFromNeatLine(lgidict, neatlineArray, toDoubleVisitor); polygons.add(wktString); } else { LOGGER.debug("Unsupported projection type {}. Map Frame will be skipped.", projectionType); } } else { LOGGER.debug("No projection array found on the map frame. Map Frame will be skipped."); } } // Handle One Map Frame } else if (lgiDictObject instanceof COSDictionary) { COSDictionary lgidict = (COSDictionary) lgiDictObject; COSDictionary projectionArray = (COSDictionary) lgidict.getDictionaryObject(PROJECTION); if (projectionArray != null) { String projectionType = ((COSString) projectionArray.getItem(PROJECTION_TYPE)).getString(); if (GEOGRAPHIC.equals(projectionType)) { COSArray neatlineArray = (COSArray) cosObject.getObjectFromPath(LGIDICT + "/" + NEATLINE); if (neatlineArray == null) { neatlineArray = generateNeatLineFromPDFDimensions(pdPage); } polygons.add(getWktFromNeatLine(lgidict, neatlineArray, toDoubleVisitor)); } else { LOGGER.debug("Unsupported projection type {}. Map Frame will be skipped.", projectionType); } } else { LOGGER.debug("No projection array found on the map frame. Map Frame will be skipped."); } } } if (polygons.size() == 0) { LOGGER.debug( "No GeoPDF information found on PDF during transformation. Metacard location will not be set."); return null; } if (polygons.size() == 1) { return POLYGON + polygons.get(0) + "))"; } else { return polygons.stream().map(polygon -> "((" + polygon + "))") .collect(Collectors.joining(",", MULTIPOLYGON, ")")); } }
From source file:ddf.catalog.transformer.input.pdf.GeoPdfParserImpl.java
/** * Generates a WKT compliant String from a PDF Document if it contains GeoPDF information. * Currently, only WGS84 Projections are supported (GEOGRAPHIC GeoPDF ProjectionType). * * @param pdfDocument - The PDF document * @return the WKT String/* w w w .j a v a 2 s.c o m*/ * @throws IOException */ @Override public String apply(PDDocument pdfDocument) throws IOException { ToDoubleVisitor toDoubleVisitor = new ToDoubleVisitor(); LinkedList<String> polygons = new LinkedList<>(); for (PDPage pdPage : pdfDocument.getPages()) { COSDictionary cosObject = pdPage.getCOSObject(); COSBase lgiDictObject = cosObject.getObjectFromPath(LGIDICT); // Handle Multiple Map Frames if (lgiDictObject instanceof COSArray) { for (int i = 0; i < ((COSArray) lgiDictObject).size(); i++) { COSDictionary lgidict = (COSDictionary) cosObject.getObjectFromPath(LGIDICT + "/[" + i + "]"); COSDictionary projectionArray = (COSDictionary) lgidict.getDictionaryObject(PROJECTION); if (projectionArray != null) { String projectionType = ((COSString) projectionArray.getItem(PROJECTION_TYPE)).getString(); if (GEOGRAPHIC.equals(projectionType)) { COSArray neatlineArray = (COSArray) cosObject .getObjectFromPath(LGIDICT + "/[" + i + "]/" + NEATLINE); getWktFromNeatLine(lgidict, neatlineArray, toDoubleVisitor).ifPresent(polygons::add); } else { LOGGER.debug("Unsupported projection type {}. Map Frame will be skipped.", projectionType); } } else { LOGGER.debug("No projection array found on the map frame. Map Frame will be skipped."); } } // Handle One Map Frame } else if (lgiDictObject instanceof COSDictionary) { COSDictionary lgidict = (COSDictionary) lgiDictObject; COSDictionary projectionArray = (COSDictionary) lgidict.getDictionaryObject(PROJECTION); if (projectionArray != null) { String projectionType = ((COSString) projectionArray.getItem(PROJECTION_TYPE)).getString(); if (GEOGRAPHIC.equals(projectionType)) { COSArray neatlineArray = (COSArray) cosObject.getObjectFromPath(LGIDICT + "/" + NEATLINE); if (neatlineArray == null) { neatlineArray = generateNeatLineFromPDFDimensions(pdPage); } getWktFromNeatLine(lgidict, neatlineArray, toDoubleVisitor).ifPresent(polygons::add); } else { LOGGER.debug("Unsupported projection type {}. Map Frame will be skipped.", projectionType); } } else { LOGGER.debug("No projection array found on the map frame. Map Frame will be skipped."); } } } if (polygons.size() == 0) { LOGGER.debug( "No GeoPDF information found on PDF during transformation. Metacard location will not be set."); return null; } if (polygons.size() == 1) { return POLYGON + polygons.get(0) + "))"; } else { return polygons.stream().map(polygon -> "((" + polygon + "))") .collect(Collectors.joining(",", MULTIPOLYGON, ")")); } }
From source file:net.sf.jabref.importer.fetcher.GoogleScholarFetcher.java
private static void runConfig() throws IOException { try {//from w ww .java 2 s.com new URLDownload("http://scholar.google.com").downloadToString(Globals.prefs.getDefaultEncoding()); //save("setting.html", ud.getStringContent()); String settingsPage = new URLDownload(GoogleScholarFetcher.URL_SETTING) .downloadToString(Globals.prefs.getDefaultEncoding()); // Get the form items and their values from the page: Map<String, String> formItems = GoogleScholarFetcher.getFormElements(settingsPage); // Override the important ones: formItems.put("scis", "yes"); formItems.put("scisf", "4"); formItems.put("num", String.valueOf(GoogleScholarFetcher.MAX_ENTRIES_TO_LOAD)); String request = formItems.entrySet().stream().map(Object::toString) .collect(Collectors.joining("&", GoogleScholarFetcher.URL_SETPREFS + "?", "&submit=")); // Download the URL to set preferences: new URLDownload(request).downloadToString(Globals.prefs.getDefaultEncoding()); } catch (UnsupportedEncodingException ex) { LOGGER.error("Unsupported encoding.", ex); } }
From source file:edu.mit.lib.mama.Mama.java
private static String jsonObject(List<Mdv> props) { return props.stream().map(p -> jsonValue(p.field, p.value, true)) .collect(Collectors.joining(",", "{", "}")); }