Java Code Examples for java.util.StringJoiner#length()
The following examples show how to use
java.util.StringJoiner#length() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IncomingInvoice.java From estatio with Apache License 2.0 | 6 votes |
@Programmatic private String mismatchedTypesOnLinkedItemsCheck() { StringJoiner sj = new StringJoiner("; "); getItems().stream() .filter(IncomingInvoiceItem.class::isInstance) .map(IncomingInvoiceItem.class::cast) .map(item -> notificationService.findLinkForInvoiceItemIfAny(item)) .filter(Optional::isPresent) .map(Optional::get) .filter(orderItemInvoiceItemLink -> { IncomingInvoiceType orderItemType = orderItemInvoiceItemLink.getOrderItem().getOrdr().getType(); IncomingInvoiceType invoiceItemType = orderItemInvoiceItemLink.getInvoiceItem().getIncomingInvoiceType(); return (orderItemType != null && invoiceItemType != null) && !orderItemType.equals(invoiceItemType); }) .forEach(link -> sj.add(String.format("an invoice item of type %s is linked to an order item of type %s", link.getInvoiceItem().getIncomingInvoiceType().toString(), link.getOrderItem().getOrdr().getType().toString())) ); return sj.length() != 0 ? new StringJoiner("").add("WARNING: mismatched types between linked items: ").merge(sj).toString() : null; }
Example 2
Source File: RegistryBasedOccurrenceMutator.java From occurrence with Apache License 2.0 | 6 votes |
/** * Generates a message about what changed in the mutation. Mostly use for logging. * * @param currentOrg * @param newOrg * @param currentDataset * @param newDataset * @return */ public Optional<String> generateUpdateMessage(Organization currentOrg, Organization newOrg, Dataset currentDataset, Dataset newDataset) { StringJoiner joiner = new StringJoiner(","); if(requiresUpdate(currentOrg, newOrg)) { joiner.add(MessageFormat.format("Publishing Organization [{0}]: Country [{1}] -> [{2}]", currentOrg.getKey(), currentOrg.getCountry(), newOrg.getCountry())); } if(requiresUpdate(currentDataset, newDataset)) { joiner.add(MessageFormat.format("Dataset [{0}]: Publishing Organization [{1}] -> [{2}], " + "License [{3}] -> [{4}]", currentDataset.getKey(), currentDataset.getPublishingOrganizationKey(), newDataset.getPublishingOrganizationKey(), currentDataset.getLicense(), newDataset.getLicense())); } return joiner.length() > 0 ? Optional.of(joiner.toString()) : Optional.empty(); }
Example 3
Source File: KafkaSpanStore.java From zipkin-storage-kafka with Apache License 2.0 | 5 votes |
@Override public Call<List<List<Span>>> getTraces(Iterable<String> traceIds) { if (traceByIdQueryEnabled) { StringJoiner joiner = new StringJoiner(","); for (String traceId : traceIds) { joiner.add(Span.normalizeTraceId(traceId)); } if (joiner.length() == 0) return Call.emptyList(); return new GetTraceManyCall(storage.getTraceStorageStream(), httpBaseUrl, joiner.toString()); } else { return Call.emptyList(); } }
Example 4
Source File: TROView.java From megamek with GNU General Public License v2.0 | 5 votes |
protected void addBasicData(Entity entity) { model.put("formatBasicDataRow", new FormatTableRowMethod(new int[] { 30, 20, 5 }, new Justification[] { Justification.LEFT, Justification.LEFT, Justification.RIGHT })); model.put("fullName", entity.getShortNameRaw()); model.put("chassis", entity.getChassis()); model.put("techBase", formatTechBase(entity)); model.put("tonnage", NumberFormat.getInstance().format(entity.getWeight())); model.put("battleValue", NumberFormat.getInstance().format(entity.calculateBattleValue())); model.put("cost", NumberFormat.getInstance().format(entity.getCost(false))); final StringJoiner quirksList = new StringJoiner(", "); final Quirks quirks = entity.getQuirks(); for (final Enumeration<IOptionGroup> optionGroups = quirks.getGroups(); optionGroups.hasMoreElements();) { final IOptionGroup group = optionGroups.nextElement(); if (quirks.count(group.getKey()) > 0) { for (final Enumeration<IOption> options = group.getOptions(); options.hasMoreElements();) { final IOption option = options.nextElement(); if ((option != null) && option.booleanValue()) { quirksList.add(option.getDisplayableNameWithValue()); } } } } if (quirksList.length() > 0) { model.put("quirks", quirksList.toString()); } }
Example 5
Source File: TechAdvancement.java From megamek with GNU General Public License v2.0 | 5 votes |
/** * Formats the date at an index for display in a table, showing DATE_NONE as "-" and prepending * "~" to approximate dates. * * @param index PROTOTYPE, PRODUCTION, COMMON, EXTINCT, or REINTRODUCED * @param clan Use the Clan progression * @param factions A list of factions to include in parentheses after the date. * @return */ private String formatDate(int index, boolean clan, int[] factions) { int date = clan? clanAdvancement[index] : isAdvancement[index]; if (date == DATE_NONE) { return "-"; } StringBuilder sb = new StringBuilder(); if (clan? clanApproximate[index] : isApproximate[index]) { sb.append("~"); } if (date == DATE_PS) { sb.append("PS"); } else if (date == DATE_ES) { sb.append("ES"); } else { sb.append(date); } if (factions != null && factions.length > 0) { StringJoiner sj = new StringJoiner(","); for (int f : factions) { if ((clan && f >= F_CLAN) || (!clan && f < F_CLAN)) { sj.add(IO_FACTION_CODES[f]); } } if (sj.length() > 0) { sb.append("(").append(sj.toString()).append(")"); } } return sb.toString(); }
Example 6
Source File: Util.java From importer-exporter with Apache License 2.0 | 5 votes |
public static <T> String collection2string(Collection<T> list, String delimiter) { StringJoiner joiner = new StringJoiner(delimiter); for (T item : list) joiner.add(item != null ? item.toString() : ""); return joiner.length() != 0 ? joiner.toString() : null; }
Example 7
Source File: PaginatedResultsRetrievedDiscoverabilityListener.java From tutorials with MIT License | 5 votes |
final void addLinkHeaderOnPagedResourceRetrieval(final UriComponentsBuilder uriBuilder, final HttpServletResponse response, final Class clazz, final int page, final int totalPages, final int pageSize) { plural(uriBuilder, clazz); final StringJoiner linkHeader = new StringJoiner(", "); if (hasNextPage(page, totalPages)) { final String uriForNextPage = constructNextPageUri(uriBuilder, page, pageSize); linkHeader.add(LinkUtil.createLinkHeader(uriForNextPage, LinkUtil.REL_NEXT)); } if (hasPreviousPage(page)) { final String uriForPrevPage = constructPrevPageUri(uriBuilder, page, pageSize); linkHeader.add(LinkUtil.createLinkHeader(uriForPrevPage, LinkUtil.REL_PREV)); } if (hasFirstPage(page)) { final String uriForFirstPage = constructFirstPageUri(uriBuilder, pageSize); linkHeader.add(LinkUtil.createLinkHeader(uriForFirstPage, LinkUtil.REL_FIRST)); } if (hasLastPage(page, totalPages)) { final String uriForLastPage = constructLastPageUri(uriBuilder, totalPages, pageSize); linkHeader.add(LinkUtil.createLinkHeader(uriForLastPage, LinkUtil.REL_LAST)); } if (linkHeader.length() > 0) { response.addHeader(HttpHeaders.LINK, linkHeader.toString()); } }
Example 8
Source File: MultiException.java From crate with Apache License 2.0 | 5 votes |
@Override public String getMessage() { StringJoiner joiner = new StringJoiner("\n"); for (Throwable e : exceptions) { joiner.add(e.getMessage()); // Reduce the amount of characters returned to consume less memory // this could escalate on a huge amount of exceptions that are raised by affected shards in the cluster if (joiner.length() > MAX_EXCEPTION_LENGTH) { joiner.add("too much output. output truncated."); break; } } return joiner.toString(); }
Example 9
Source File: RegistryBasedOccurrenceMutator.java From occurrence with Apache License 2.0 | 5 votes |
/** * Generates a message about what changed in the mutation. Mostly use for logging. * * @param currentOrg * @param newOrg * @return */ public Optional<String> generateUpdateMessage(Organization currentOrg, Organization newOrg) { StringJoiner joiner = new StringJoiner(","); if(requiresUpdate(currentOrg, newOrg)) { joiner.add(MessageFormat.format("Publishing Organization [{0}]: Country [{1}] -> [{2}]", currentOrg.getKey(), currentOrg.getCountry(), newOrg.getCountry())); } return joiner.length() > 0 ? Optional.of(joiner.toString()) : Optional.empty(); }
Example 10
Source File: RegistryBasedOccurrenceMutator.java From occurrence with Apache License 2.0 | 5 votes |
/** * Generates a message about what changed in the mutation. Mostly use for logging. * * @param currentDataset * @param newDataset * @param currentDataset * @param newDataset * @return */ public Optional<String> generateUpdateMessage(Dataset currentDataset, Dataset newDataset) { StringJoiner joiner = new StringJoiner(","); if(requiresUpdate(currentDataset, newDataset)) { joiner.add(MessageFormat.format("Dataset [{0}]: Publishing Organization [{1}] -> [{2}], " + "License [{3}] -> [{4}]", currentDataset.getKey(), currentDataset.getPublishingOrganizationKey(), newDataset.getPublishingOrganizationKey(), currentDataset.getLicense(), newDataset.getLicense())); } return joiner.length() > 0 ? Optional.of(joiner.toString()) : Optional.empty(); }
Example 11
Source File: AbstractRenditionTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
private void assertRenditionsOkayFromSourceExtension(List<String> sourceExtensions, List<String> excludeList, List<String> expectedToFail, int expectedRenditionCount, int expectedFailedCount) throws Exception { int renditionCount = 0; int failedCount = 0; int successCount = 0; int excludedCount = 0; RenditionDefinitionRegistry2 renditionDefinitionRegistry2 = renditionService2.getRenditionDefinitionRegistry2(); StringJoiner failures = new StringJoiner("\n"); StringJoiner successes = new StringJoiner("\n"); for (String sourceExtension : sourceExtensions) { String sourceMimetype = mimetypeMap.getMimetype(sourceExtension); String testFileName = getTestFileName(sourceMimetype); if (testFileName != null) { Set<String> renditionNames = renditionDefinitionRegistry2.getRenditionNamesFrom(sourceMimetype, -1); List<ThumbnailDefinition> thumbnailDefinitions = thumbnailRegistry.getThumbnailDefinitions(sourceMimetype, -1); Set<String> thumbnailNames = getThumbnailNames(thumbnailDefinitions); assertEquals("There should be the same renditions ("+renditionNames+") as deprecated thumbnails ("+thumbnailNames+")", thumbnailNames, renditionNames); renditionCount += renditionNames.size(); for (String renditionName : renditionNames) { RenditionDefinition2 renditionDefinition = renditionDefinitionRegistry2.getRenditionDefinition(renditionName); String targetMimetype = renditionDefinition.getTargetMimetype(); String targetExtension = mimetypeMap.getExtension(targetMimetype); String sourceTragetRendition = sourceExtension + ' ' + targetExtension + ' ' + renditionName; if (excludeList.contains(sourceTragetRendition)) { excludedCount++; } else { try { checkRendition(testFileName, renditionName, !expectedToFail.contains(sourceTragetRendition)); successes.add(sourceTragetRendition); successCount++; } catch (AssertionFailedError e) { failures.add(sourceTragetRendition + " " + e.getMessage()); failedCount++; } } } } } int expectedSuccessCount = expectedRenditionCount - excludedCount - expectedFailedCount; System.out.println("FAILURES:\n"+failures+"\n"); System.out.println("SUCCESSES:\n"+successes+"\n"); System.out.println("renditionCount: "+renditionCount+" expected "+expectedRenditionCount); System.out.println(" failedCount: "+failedCount+" expected "+expectedFailedCount); System.out.println(" successCount: "+successCount+" expected "+expectedSuccessCount); assertEquals("Rendition count has changed", expectedRenditionCount, renditionCount); assertEquals("Failed rendition count has changed", expectedFailedCount, failedCount); assertEquals("Successful rendition count has changed", expectedSuccessCount, successCount); if (failures.length() > 0) { fail(failures.toString()); } }