List of usage examples for com.google.common.collect ImmutableList isEmpty
boolean isEmpty();
From source file:com.google.jimfs.FileTree.java
private static boolean isEmpty(ImmutableList<Name> names) { // the empty path (created by FileSystem.getPath("")), has no root and a single name, "" return names.isEmpty() || names.size() == 1 && names.get(0).toString().isEmpty(); }
From source file:com.facebook.buck.apple.toolchain.impl.AppleSdkDiscovery.java
private static ImmutableList<String> validArchitecturesForPlatform(ApplePlatform platform, Path sdkDir) throws IOException { ImmutableList<String> architectures = platform.getArchitectures(); try (DirectoryStream<Path> sdkFiles = Files.newDirectoryStream(sdkDir)) { ImmutableList.Builder<String> architectureSubdirsBuilder = ImmutableList.builder(); for (Path path : sdkFiles) { if (Files.isDirectory(path)) { String directoryName = path.getFileName().toString(); // Default Apple SDKs contain fat binaries and have no architecture subdirectories, // but custom SDKs might. if (architectures.contains(directoryName)) { architectureSubdirsBuilder.add(directoryName); }//ww w . j a v a 2 s. c o m } } ImmutableList<String> architectureSubdirs = architectureSubdirsBuilder.build(); if (!architectureSubdirs.isEmpty()) { architectures = architectureSubdirs; } } return architectures; }
From source file:cz.cuni.mff.ms.brodecva.botnicek.ide.translate.Stack.java
/** * Vrt strukturu, kter pid slova na uvolnn vrchol zsobnku, pokud je * provedena./* ww w. j a v a 2 s .c o m*/ * * @param words * normln slova * @return strom prvk ablony, kter provede pidn slov na zsobnk */ public static TemplateElement popAndPushWords(final List<? extends NormalWord> words) { Preconditions.checkNotNull(words); final ImmutableList<NormalWord> wordsCopy = ImmutableList.copyOf(words); if (wordsCopy.isEmpty()) { return popAndPush(ImmutableList.<TemplateElement>of()); } else { return popAndPush(Text.create(joinWithSpaces(wordsCopy))); } }
From source file:com.facebook.buck.android.exopackage.RealExopackageDevice.java
/** * Breaks a list of strings into groups whose total size is within some limit. Kind of like the * xargs command that groups arguments to avoid maximum argument length limits. Except that the * limit in adb is about 1k instead of 512k or 2M on Linux. *///from www. jav a 2s .com @VisibleForTesting public static ImmutableList<ImmutableList<String>> chunkArgs(Iterable<String> args, int sizeLimit) { ImmutableList.Builder<ImmutableList<String>> topLevelBuilder = ImmutableList.builder(); ImmutableList.Builder<String> chunkBuilder = ImmutableList.builder(); int chunkSize = 0; for (String arg : args) { if (chunkSize + arg.length() > sizeLimit) { topLevelBuilder.add(chunkBuilder.build()); chunkBuilder = ImmutableList.builder(); chunkSize = 0; } // We don't check for an individual arg greater than the limit. // We just put it in its own chunk and hope for the best. chunkBuilder.add(arg); chunkSize += arg.length(); } ImmutableList<String> tail = chunkBuilder.build(); if (!tail.isEmpty()) { topLevelBuilder.add(tail); } return topLevelBuilder.build(); }
From source file:dagger.internal.codegen.SourceFiles.java
static TypeName parameterizedGeneratedTypeNameForBinding(Binding binding) { ClassName className = generatedClassNameForBinding(binding); ImmutableList<TypeVariableName> typeParameters = bindingTypeElementTypeVariableNames(binding); return typeParameters.isEmpty() ? className : ParameterizedTypeName.get(className, Iterables.toArray(typeParameters, TypeName.class)); }
From source file:com.opengamma.strata.loader.csv.SwapTradeCsvLoader.java
private static SwapTrade parseVariableRates(SwapTrade trade, List<CsvRow> variableRows) { ImmutableList.Builder<ValueStep> stepBuilder = ImmutableList.builder(); for (CsvRow row : variableRows) { LocalDate date = LoaderUtils.parseDate(row.getValue(START_DATE_FIELD)); row.findValue(FIXED_RATE_FIELD).map(str -> LoaderUtils.parseDoublePercent(str)).ifPresent( fixedRate -> stepBuilder.add(ValueStep.of(date, ValueAdjustment.ofReplace(fixedRate)))); }/*from w ww. j a va2 s . c o m*/ ImmutableList<ValueStep> varRates = stepBuilder.build(); if (varRates.isEmpty()) { return trade; } // adjust the trade, inserting the variable rates ImmutableList.Builder<SwapLeg> legBuilder = ImmutableList.builder(); for (SwapLeg swapLeg : trade.getProduct().getLegs()) { RateCalculationSwapLeg leg = (RateCalculationSwapLeg) swapLeg; if (leg.getCalculation() instanceof FixedRateCalculation) { FixedRateCalculation baseCalc = (FixedRateCalculation) leg.getCalculation(); FixedRateCalculation calc = baseCalc.toBuilder() .rate(ValueSchedule.of(baseCalc.getRate().getInitialValue(), varRates)).build(); legBuilder.add(leg.toBuilder().calculation(calc).build()); } else { legBuilder.add(leg); } } return replaceLegs(trade, legBuilder.build()); }
From source file:com.opengamma.strata.loader.csv.SwapTradeCsvLoader.java
private static SwapTrade parseVariableNotional(SwapTrade trade, List<CsvRow> variableRows) { // parse notionals ImmutableList.Builder<ValueStep> stepBuilder = ImmutableList.builder(); for (CsvRow row : variableRows) { LocalDate date = LoaderUtils.parseDate(row.getValue(START_DATE_FIELD)); row.findValue(NOTIONAL_FIELD).map(str -> LoaderUtils.parseDouble(str)).ifPresent( notional -> stepBuilder.add(ValueStep.of(date, ValueAdjustment.ofReplace(notional)))); }/*from ww w. ja v a2 s. c om*/ ImmutableList<ValueStep> varNotionals = stepBuilder.build(); if (varNotionals.isEmpty()) { return trade; } // adjust the trade, inserting the variable notionals ImmutableList.Builder<SwapLeg> legBuilder = ImmutableList.builder(); for (SwapLeg swapLeg : trade.getProduct().getLegs()) { RateCalculationSwapLeg leg = (RateCalculationSwapLeg) swapLeg; NotionalSchedule notionalSchedule = leg.getNotionalSchedule().toBuilder() .amount(ValueSchedule.of(leg.getNotionalSchedule().getAmount().getInitialValue(), varNotionals)) .build(); legBuilder.add(leg.toBuilder().notionalSchedule(notionalSchedule).build()); } return replaceLegs(trade, legBuilder.build()); }
From source file:com.opengamma.strata.collect.io.XmlFile.java
/** * Parses the tree from the StAX stream reader, capturing references. * <p>/*from www. j a va2 s.co m*/ * The reader should be created using the factory returned from {@link #xmlInputFactory()}. * <p> * This method supports capturing attribute references, such as an id/href pair. * Wherever the parser finds an attribute with the specified name, the element is added * to the specified map. Note that the map is mutated. * * @param reader the StAX stream reader, positioned at or before the element to be parsed * @param refAttr the attribute name that should be parsed as a reference, null if not applicable * @param refs the mutable map of references to update, null if not applicable * @return the parsed element * @throws IllegalArgumentException if the input cannot be parsed */ private static XmlElement parse(XMLStreamReader reader, String refAttr, Map<String, XmlElement> refs) { try { // parse start element String elementName = parseElementName(reader); ImmutableMap<String, String> attrs = parseAttributes(reader); // parse children or content ImmutableList.Builder<XmlElement> childBuilder = ImmutableList.builder(); String content = ""; int event = reader.next(); while (event != XMLStreamConstants.END_ELEMENT) { switch (event) { // parse child when start element found case XMLStreamConstants.START_ELEMENT: childBuilder.add(parse(reader, refAttr, refs)); break; // append content when characters found // since XMLStreamReader has IS_COALESCING=true means there should only be one content call case XMLStreamConstants.CHARACTERS: case XMLStreamConstants.CDATA: content += reader.getText(); break; default: break; } event = reader.next(); } ImmutableList<XmlElement> children = childBuilder.build(); XmlElement parsed = children.isEmpty() ? XmlElement.ofContent(elementName, attrs, content) : XmlElement.ofChildren(elementName, attrs, children); String ref = attrs.get(refAttr); if (ref != null) { refs.put(ref, parsed); } return parsed; } catch (XMLStreamException ex) { throw new IllegalArgumentException(ex); } }
From source file:org.eigenbase.relopt.RelOptPredicateList.java
public static RelOptPredicateList of(Iterable<RexNode> pulledUpPredicates, Iterable<RexNode> leftInferredPredicates, Iterable<RexNode> rightInferredPredicates) { final ImmutableList<RexNode> pulledUpPredicatesList = ImmutableList.copyOf(pulledUpPredicates); final ImmutableList<RexNode> leftInferredPredicateList = ImmutableList.copyOf(leftInferredPredicates); final ImmutableList<RexNode> rightInferredPredicatesList = ImmutableList.copyOf(rightInferredPredicates); if (pulledUpPredicatesList.isEmpty() && leftInferredPredicateList.isEmpty() && rightInferredPredicatesList.isEmpty()) { return EMPTY; }/*from w ww. j a v a 2 s .c o m*/ return new RelOptPredicateList(pulledUpPredicatesList, leftInferredPredicateList, rightInferredPredicatesList); }
From source file:com.isotrol.impe3.api.content.ContentCriteriaTransformer.java
/** * Transformer to adds a set of sort specifications. * @param fields Sort field specifications. * @return The requested transformer.// w w w . j a v a 2 s . co m */ public static ContentCriteriaTransformer sort(Iterable<NRSortField> fields) { if (fields == null) { return identity(); } final ImmutableList<NRSortField> list = ImmutableList.copyOf(filter(fields, notNull())); if (list.isEmpty()) { return identity(); } return new AddSort(list); }