List of usage examples for com.google.common.collect ImmutableList size
int size();
From source file:com.google.template.soy.shared.internal.MainEntryPointUtils.java
/** * Maps output paths to indices of inputs that should be emitted to them. * * @param locale The locale for the file path, or null if not applicable. * @param outputPathFormat The format string defining how to format output file paths. * @param inputPathsPrefix The input path prefix, or empty string if none. * @param fileNodes A list of the SoyFileNodes being written. * @return A map of output file paths to their respective input indicies. *//* w w w. j av a 2 s . c om*/ public static Multimap<String, Integer> mapOutputsToSrcs(@Nullable String locale, String outputPathFormat, String inputPathsPrefix, ImmutableList<SoyFileNode> fileNodes) { Multimap<String, Integer> outputs = ArrayListMultimap.create(); // First, check that the parent directories for all output files exist, and group the output // files by the inputs that go there. // This means that the compiled source from multiple input files might be written to a single // output file, as is the case when there are multiple inputs, and the output format string // contains no wildcards. for (int i = 0; i < fileNodes.size(); ++i) { SoyFileNode inputFile = fileNodes.get(i); String inputFilePath = inputFile.getFilePath(); String outputFilePath = MainEntryPointUtils.buildFilePath(outputPathFormat, locale, inputFilePath, inputPathsPrefix); BaseUtils.ensureDirsExistInPath(outputFilePath); outputs.put(outputFilePath, i); } return outputs; }
From source file:org.eclipse.sw360.commonIO.TypeMappings.java
@NotNull public static Map<Integer, Todo> getTodoMapAndWriteMissingToDatabase(LicenseService.Iface licenseClient, Map<Integer, Obligation> obligationMap, Map<Integer, Set<Integer>> obligationTodoMapping, InputStream in, User user) throws TException { List<CSVRecord> todoRecords = ImportCSV.readAsCSVRecords(in); final List<Todo> todos = CommonUtils.nullToEmptyList(licenseClient.getTodos()); Map<Integer, Todo> todoMap = Maps.newHashMap(Maps.uniqueIndex(todos, getTodoIdentifier())); final List<Todo> todosToAdd = ConvertRecord.convertTodos(todoRecords); final ImmutableList<Todo> filteredTodos = getElementsWithIdentifiersNotInMap(getTodoIdentifier(), todoMap, todosToAdd);/*from w ww.ja v a2s. c o m*/ final ImmutableMap<Integer, Todo> filteredMap = Maps.uniqueIndex(filteredTodos, getTodoIdentifier()); putToTodos(obligationMap, filteredMap, obligationTodoMapping); //insertCustomProperties if (filteredTodos.size() > 0) { final List<Todo> addedTodos = licenseClient.addTodos(filteredTodos, user); if (addedTodos != null) { final ImmutableMap<Integer, Todo> addedTodoMap = Maps.uniqueIndex(addedTodos, getTodoIdentifier()); todoMap.putAll(addedTodoMap); } } return todoMap; }
From source file:com.facebook.presto.sql.planner.iterative.rule.ExtractSpatialJoins.java
private static QualifiedObjectName toQualifiedObjectName(String name, String catalog, String schema) { ImmutableList<String> ids = ImmutableList.copyOf(Splitter.on('.').split(name)); if (ids.size() == 3) { return new QualifiedObjectName(ids.get(0), ids.get(1), ids.get(2)); }/* ww w . j a v a 2 s. c o m*/ if (ids.size() == 2) { return new QualifiedObjectName(catalog, ids.get(0), ids.get(1)); } if (ids.size() == 1) { return new QualifiedObjectName(catalog, schema, ids.get(0)); } throw new PrestoException(INVALID_SPATIAL_PARTITIONING, format("Invalid name: %s", name)); }
From source file:org.locationtech.geogig.plumbing.merge.DiffMergeFeaturesOp.java
static RevFeature merge(FeatureDiff mergeIntoDiff, FeatureDiff toMergeDiff) { if (!mergeIntoDiff.getNewFeatureType().equals(toMergeDiff.getNewFeatureType())) { throw new IllegalArgumentException( String.format("Non-matching feature types. Cannot merge. Left: %s, right: %s", mergeIntoDiff.getNewFeatureType().getId(), toMergeDiff.getNewFeatureType().getId())); }/* w ww . j av a 2s.c o m*/ RevFeatureType featureType = mergeIntoDiff.getNewFeatureType(); Map<PropertyDescriptor, AttributeDiff> leftDiffs = mergeIntoDiff.getDiffs(); Map<PropertyDescriptor, AttributeDiff> rightDiffs = toMergeDiff.getDiffs(); ImmutableList<PropertyDescriptor> descriptors; descriptors = ImmutableList.copyOf(featureType.type().getDescriptors()); final List<Object> ancestorValues; ancestorValues = getAncestorValues(mergeIntoDiff, toMergeDiff, descriptors); RevFeatureBuilder mergedValues = RevFeatureBuilder.builder(); for (int i = 0; i < descriptors.size(); i++) { final PropertyDescriptor descriptor = descriptors.get(i); final boolean isGeom = descriptor instanceof GeometryDescriptor; @Nullable Object ancestorValue = ancestorValues.get(i); @Nullable AttributeDiff leftAttDiff = leftDiffs.get(descriptor); @Nullable AttributeDiff rightAttDiff = rightDiffs.get(descriptor); Object valueA = leftAttDiff == null ? null : leftAttDiff.getNewValue(); Object valueB = rightAttDiff == null ? null : rightAttDiff.getNewValue(); Object merged; if (leftAttDiff == null) { merged = rightAttDiff == null ? ancestorValue : valueB; } else if (rightAttDiff == null) { merged = valueA; } else if (valueEquals(isGeom, valueA, valueB)) { merged = valueA; } else { // both modified the attribute and didn't set the same value merged = valueA; } mergedValues.addValue(merged); } return mergedValues.build(); }
From source file:org.ow2.authzforce.core.pdp.api.io.BaseXacmlJaxbResultPostprocessor.java
/** * Convert AuthzForce-specific {@link DecisionResult} to XACML {@link Result} * //from ww w . j av a 2s .c o m * @param request * request corresponding to result; iff null, some content from it, esp. the list of {@link oasis.names.tc.xacml._3_0.core.schema.wd_17.Attributes}, is included in {@code result} * @param result * @return XACML Result */ public static final Result convert(final IndividualXacmlJaxbRequest request, final DecisionResult result) { final ImmutableList<PepAction> pepActions = result.getPepActions(); assert pepActions != null; final List<Obligation> xacmlObligations; final List<Advice> xacmlAdvices; if (pepActions.isEmpty()) { xacmlObligations = null; xacmlAdvices = null; } else { xacmlObligations = new ArrayList<>(pepActions.size()); xacmlAdvices = new ArrayList<>(pepActions.size()); pepActions.forEach(pepAction -> { final String pepActionId = pepAction.getId(); final List<AttributeAssignment> xacmlAttAssignments = convert(pepAction.getAttributeAssignments()); if (pepAction.isMandatory()) { xacmlObligations.add(new Obligation(xacmlAttAssignments, pepActionId)); } else { xacmlAdvices.add(new Advice(xacmlAttAssignments, pepActionId)); } }); } final ImmutableList<PrimaryPolicyMetadata> applicablePolicies = result.getApplicablePolicies(); final PolicyIdentifierList jaxbPolicyIdentifiers; if (applicablePolicies == null || applicablePolicies.isEmpty()) { jaxbPolicyIdentifiers = null; } else { final List<JAXBElement<IdReferenceType>> jaxbPolicyIdRefs = new ArrayList<>(applicablePolicies.size()); for (final PrimaryPolicyMetadata applicablePolicy : applicablePolicies) { final IdReferenceType jaxbIdRef = new IdReferenceType(applicablePolicy.getId(), applicablePolicy.getVersion().toString(), null, null); final JAXBElement<IdReferenceType> jaxbPolicyIdRef = applicablePolicy .getType() == TopLevelPolicyElementType.POLICY ? Xacml3JaxbHelper.XACML_3_0_OBJECT_FACTORY.createPolicyIdReference(jaxbIdRef) : Xacml3JaxbHelper.XACML_3_0_OBJECT_FACTORY.createPolicySetIdReference(jaxbIdRef); jaxbPolicyIdRefs.add(jaxbPolicyIdRef); } jaxbPolicyIdentifiers = new PolicyIdentifierList(jaxbPolicyIdRefs); } return new Result(result.getDecision(), result.getStatus(), xacmlObligations == null || xacmlObligations.isEmpty() ? null : new Obligations(xacmlObligations), xacmlAdvices == null || xacmlAdvices.isEmpty() ? null : new AssociatedAdvice(xacmlAdvices), request == null ? null : request.getAttributesToBeReturned(), jaxbPolicyIdentifiers); }
From source file:com.google.errorprone.bugpatterns.TypeParameterNaming.java
private static String suggestedNameFollowedWithT(String identifier) { Preconditions.checkArgument(!identifier.isEmpty()); // Some early checks: // TFoo => FooT if (identifier.length() > 2 && identifier.charAt(0) == 'T' && Ascii.isUpperCase(identifier.charAt(1)) && Ascii.isLowerCase(identifier.charAt(2))) { // splitToLowercaseTerms thinks "TFooBar" is ["tfoo", "bar"], so we remove "t", have it parse // as ["foo", "bar"], then staple "t" back on the end. ImmutableList<String> tokens = NamingConventions.splitToLowercaseTerms(identifier.substring(1)); return Streams.concat(tokens.stream(), Stream.of("T")).map(TypeParameterNaming::upperCamelToken) .collect(Collectors.joining()); }/* w w w. j a v a 2 s . co m*/ ImmutableList<String> tokens = NamingConventions.splitToLowercaseTerms(identifier); // UPPERCASE => UppercaseT if (tokens.size() == 1) { String token = tokens.get(0); if (Ascii.toUpperCase(token).equals(identifier)) { return upperCamelToken(token) + "T"; } } // FooType => FooT if (Iterables.getLast(tokens).equals("type")) { return Streams.concat(tokens.subList(0, tokens.size() - 1).stream(), Stream.of("T")) .map(TypeParameterNaming::upperCamelToken).collect(Collectors.joining()); } return identifier + "T"; }
From source file:co.jirm.orm.builder.ConditionVisitors.java
public static ConditionVisitor conditionVisitor(final Appendable appendable) { final SafeAppendable sb = new SafeAppendable(appendable); ConditionVisitor v = new ConditionVisitor() { private int depth = 0; @Override/*from www. j ava2 s .co m*/ public void visitAnd(ImmutableList<ImmutableCondition> conditions, Parameters parameters) { depth++; doCondition(" AND ", conditions, parameters); } @Override public void visitOr(ImmutableList<ImmutableCondition> conditions, Parameters parameters) { depth++; doCondition(" OR ", conditions, parameters); } private void doCondition(String op, ImmutableList<ImmutableCondition> conditions, Parameters parameters) { if (conditions.size() == 1) { sb.append(op); conditions.get(0).accept(this); } else { boolean top = depth == 1; if (!top) sb.append("( "); boolean first = true; for (ImmutableCondition c : conditions) { if (first) { first = false; c.accept(this); } else { sb.append(op); c.accept(this); } } if (!top) sb.append(" )"); } } @Override public void visitSql(String sql, Parameters parameters) { sb.append(sql); } }; return v; }
From source file:com.analog.lyric.collect.Supers.java
/** * Returns a new array containing {@code elements}, which must be a subclass of {@code rootClass}, * with component type set to nearest common superclass ({@link #nearestCommonSuperClass(Object...)}) * of the objects it contains that is no deeper than {@code maxClassDepthBelowRoot} below {@code rootClass}. * /*from ww w . ja v a 2s . co m*/ * @see #narrowArrayOf(Object...) * @see #copyOf(Class, Object...) */ public static <T> T[] narrowArrayOf(Class<? extends Object> rootClass, int maxRelativeClassDepth, T[] elements) { if (elements.length == 0) { if (rootClass.equals(elements.getClass().getComponentType())) { return elements; } else { @SuppressWarnings("unchecked") final T[] array = (T[]) Array.newInstance(rootClass, 0); return array; } } Class<?> c = nearestCommonSuperClass(elements); if (maxRelativeClassDepth < 500) { ImmutableList<Class<?>> supers = superClasses(c); final int maxClassDepth = numberOfSuperClasses(rootClass) + maxRelativeClassDepth; if (maxClassDepth < supers.size()) { c = supers.get(maxClassDepth); } } return copyOf(c, elements); }
From source file:com.palantir.common.base.BatchingVisitables.java
public static <T, TOKEN> TokenBackedBasicResultsPage<T, TOKEN> getFirstPage(BatchingVisitable<T> v, int numToVisitArg, Function<T, TOKEN> tokenExtractor) { Preconditions.checkArgument(numToVisitArg >= 0, "numToVisit cannot be negative. Value was: " + numToVisitArg); if (numToVisitArg == Integer.MAX_VALUE) { // prevent issue with overflow numToVisitArg--;//from ww w . java 2 s. c om } final int numToVisit = numToVisitArg + 1; ImmutableList<T> list = BatchingVisitableView.of(v).limit(numToVisit).immutableCopy(); Preconditions.checkState(list.size() <= numToVisit); if (list.size() >= numToVisit) { TOKEN token = tokenExtractor.apply(list.get(list.size() - 1)); list = list.subList(0, numToVisit - 1); return new SimpleTokenBackedResultsPage<T, TOKEN>(token, list, true); } return new SimpleTokenBackedResultsPage<T, TOKEN>(null, list, false); }
From source file:com.google.devtools.build.lib.skyframe.AspectFunction.java
private static SkyValue createAliasAspect(Environment env, Target originalTarget, Aspect aspect, AspectKey originalKey, ConfiguredTarget configuredTarget) throws InterruptedException { ImmutableList<Label> aliasChain = configuredTarget.getProvider(AliasProvider.class).getAliasChain(); // Find the next alias in the chain: either the next alias (if there are two) or the name of // the real configured target. Label aliasLabel = aliasChain.size() > 1 ? aliasChain.get(1) : configuredTarget.getLabel(); SkyKey depKey = ActionLookupValue.key(originalKey.withLabel(aliasLabel)); // Compute the AspectValue of the target the alias refers to (which can itself be either an // alias or a real target) AspectValue real = (AspectValue) env.getValue(depKey); if (env.valuesMissing()) { return null; }//from www . j a v a 2 s .c o m NestedSet<Package> transitivePackages = NestedSetBuilder.<Package>stableOrder() .addTransitive(real.getTransitivePackages()).add(originalTarget.getPackage()).build(); return new AspectValue(originalKey, aspect, originalTarget.getLabel(), originalTarget.getLocation(), ConfiguredAspect.forAlias(real.getConfiguredAspect()), ImmutableList.<ActionAnalysisMetadata>of(), transitivePackages); }