com.google.common.collect.Lists#transform ( )源码实例Demo

下面列出了com.google.common.collect.Lists#transform ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: dremio-oss   文件: SimpleUserService.java
@Override
public Iterable<? extends User> searchUsers(String searchTerm, String sortColumn, SortOrder order,
                                            Integer limit) throws IOException {
  limit = limit == null ? 10000 : limit;

  if (searchTerm == null || searchTerm.isEmpty()) {
    return getAllUsers(limit);
  }

  final SearchQuery query = SearchQueryUtils.or(
    SearchQueryUtils.newContainsTerm(UserIndexKeys.NAME, searchTerm),
    SearchQueryUtils.newContainsTerm(UserIndexKeys.FIRST_NAME, searchTerm),
    SearchQueryUtils.newContainsTerm(UserIndexKeys.LAST_NAME, searchTerm),
    SearchQueryUtils.newContainsTerm(UserIndexKeys.EMAIL, searchTerm));

  final LegacyFindByCondition conditon = new LegacyFindByCondition()
    .setCondition(query)
    .setLimit(limit)
    .addSorting(buildSorter(sortColumn, order));

  return Lists.transform(Lists.newArrayList(KVUtil.values(userStore.find(conditon))), infoConfigTransformer);
}
 
源代码2 项目: incubator-gobblin   文件: PullFileLoader.java
/**
 * Find and load all pull files under a base {@link Path} recursively in an order sorted by last modified date.
 * @param path base {@link Path} where pull files should be found recursively.
 * @param sysProps A {@link Config} used as fallback.
 * @param loadGlobalProperties if true, will also load at most one *.properties file per directory from the
 *          {@link #rootDirectory} to the pull file {@link Path} for each pull file.
 * @return The loaded {@link Config}s.
 */
public List<Config> loadPullFilesRecursively(Path path, Config sysProps, boolean loadGlobalProperties) {
  return Lists.transform(this.fetchJobFilesRecursively(path), new Function<Path, Config>() {
    @Nullable
    @Override
    public Config apply(@Nullable Path jobFile) {
      if (jobFile == null) {
        return null;
      }

      try {
        return PullFileLoader.this.loadPullFile(jobFile,
            sysProps, loadGlobalProperties);
      } catch (IOException e) {
        log.error("Cannot load job from {} due to {}", jobFile, ExceptionUtils.getFullStackTrace(e));
        return null;
      }
    }
  });
}
 
源代码3 项目: mamute   文件: SolrQuestionIndex.java
private SolrInputDocument toDoc(Question q) {
	List<String> tagNames = Lists.transform(q.getTags(), new Function<Tag, String>() {
		@Nullable
		@Override
		public String apply(@Nullable Tag tag) {
			return tag.getName();
		}
	});

	SolrInputDocument doc = new SolrInputDocument();
	doc.addField("id", q.getId());
	doc.addField("title", q.getTitle());
	doc.addField("description", q.getMarkedDescription());
	doc.addField("tags", join(tagNames));

	String solution = null;
	List<String> answers = new ArrayList<>();
	for (Answer a : q.getAnswers()) {
		if (a.isSolution()) {
			solution = a.getDescription();
		} else {
			answers.add(a.getDescription());
		}
	}

	if (solution != null) {
		doc.addField("solution", solution);
	}
	if (answers.size() > 0) {
		doc.addField("answers", join(answers));
	}

	return doc;
}
 
源代码4 项目: dremio-oss   文件: CopyWithCluster.java
private RelNode copyOf(LogicalWindow window) {
  final RelNode input = window.getInput().accept(this);
  return new LogicalWindow(
    cluster,
    copyOf(window.getTraitSet()),
    input,
    Lists.transform(window.constants, COPY_REX_LITERAL),
    copyOf(window.getRowType()),
    window.groups
  );
}
 
@Override
public List<BundleSubmission> getBundleSubmissionsWithGradingsByContainerJidAndProblemJidAndUserJid(String containerJid, String problemJid, String userJid) {
    List<SM> submissionModels = bundleSubmissionDao.findSortedByFiltersEq("id", "asc", "", ImmutableMap.<SingularAttribute<? super SM, ? extends Object>, String>of(AbstractBundleSubmissionModel_.containerJid, containerJid, AbstractBundleSubmissionModel_.problemJid, problemJid, AbstractBundleSubmissionModel_.createdBy, userJid), 0, -1);
    Map<String, List<GM>> gradingModelsMap = bundleGradingDao.getBySubmissionJids(Lists.transform(submissionModels, m -> m.jid));

    return Lists.transform(submissionModels, m -> BundleSubmissionServiceUtils.createSubmissionFromModels(m, gradingModelsMap.get(m.jid)));
}
 
源代码6 项目: googleads-java-lib   文件: Pql.java
/**
 * Gets the values in a row of the result set in the form of a string list.
 *
 * @param row the row to get the values for
 * @return the string list of the row values
 */
public static List<String> getRowStringValues(Row row) {
  return Lists.transform(
      Lists.newArrayList(row.getValues()),
      new Function<Value, String>() {
        public String apply(Value input) {
          return Pql.toString(input);
        }
      });
}
 
源代码7 项目: incubator-atlas   文件: GraphBackedTypeStore.java
/**
 * Finds or creates type vertices with the information specified.
 *
 * @param infoList
 * @return list with the vertices corresponding to the types in the list.
 * @throws AtlasException
 */
private List<AtlasVertex> createVertices(List<TypeVertexInfo> infoList) throws AtlasException {

    List<AtlasVertex> result = new ArrayList<>(infoList.size());
    List<String> typeNames = Lists.transform(infoList, new Function<TypeVertexInfo,String>() {
        @Override
        public String apply(TypeVertexInfo input) {
            return input.getTypeName();
        }
    });
    Map<String, AtlasVertex> vertices = findVertices(typeNames);

    for(TypeVertexInfo info : infoList) {
        AtlasVertex vertex = vertices.get(info.getTypeName());
        if (! GraphHelper.elementExists(vertex)) {
            LOG.debug("Adding vertex {}{}", PROPERTY_PREFIX, info.getTypeName());
            vertex = graph.addVertex();
            setProperty(vertex, Constants.VERTEX_TYPE_PROPERTY_KEY, VERTEX_TYPE); // Mark as type AtlasVertex
            setProperty(vertex, Constants.TYPE_CATEGORY_PROPERTY_KEY, info.getCategory());
            setProperty(vertex, Constants.TYPENAME_PROPERTY_KEY, info.getTypeName());
        }
        String newDescription = info.getTypeDescription();
        if (newDescription != null) {
            String oldDescription = getPropertyKey(Constants.TYPEDESCRIPTION_PROPERTY_KEY);
            if (!newDescription.equals(oldDescription)) {
                setProperty(vertex, Constants.TYPEDESCRIPTION_PROPERTY_KEY, newDescription);
            }
        } else {
            LOG.debug(" type description is null ");
        }
        result.add(vertex);
    }
    return result;
}
 
源代码8 项目: phoenix   文件: ScanUtilTest.java
private static Collection<?> foreach(KeyRange[][] ranges, int[] widths, byte[] expectedKey,
        Bound bound) {
    List<List<KeyRange>> slots = Lists.transform(Lists.newArrayList(ranges), ARRAY_TO_LIST);
    List<Object> ret = Lists.newArrayList();
    ret.add(new Object[] { slots, widths, expectedKey, bound });
    return ret;
}
 
源代码9 项目: ganttproject   文件: RecentColorsOption.java
@Override
public String getPersistentValue() {
  if (myColors.isEmpty()) {
    return null;
  }
  List<String> values = Lists.transform(myColors, new Function<Color, String>() {
    @Override
    public String apply(Color c) {
      return Util.getColor(c);
    }
  });
  return Joiner.on(' ').join(values);
}
 
源代码10 项目: estatio   文件: Lease.java
@Programmatic
public LeaseStatus getEffectiveStatus() {
    List<LeaseItem> all = Lists.newArrayList(getItems());
    int itemCount = getItems().size();
    List<LeaseItemStatus> statusList = Lists.transform(all, leaseItem -> leaseItem.getStatus());
    int suspensionCount = Collections.frequency(statusList, LeaseItemStatus.SUSPENDED);
    if (suspensionCount > 0) {
        if (itemCount == suspensionCount) {
            return LeaseStatus.SUSPENDED;
        } else {
            return LeaseStatus.SUSPENDED_PARTIALLY;
        }
    }
    return null;
}
 
源代码11 项目: hifive-pitalium   文件: AssertionView.java
/**
 * スクリーンショット比較の前準備として、除外領域をマスクし、座標情報とペアにして返します。
 *
 * @param target スクリーンショット撮影結果
 * @return マスク済の画像と座標情報のペア
 */
private ImageRectanglePair prepareScreenshotImageForCompare(TargetResult target) {
	BufferedImage image = target.getImage().get();

	// Mask
	List<ScreenAreaResult> excludes = target.getExcludes();
	if (!excludes.isEmpty()) {
		List<Rectangle> maskAreas = Lists.transform(toExcludesForJson(excludes),
				SCREEN_AREA_RESULT_TO_RECTANGLE_FUNCTION);
		image = ImageUtils.getMaskedImage(image, maskAreas);
	}

	return new ImageRectanglePair(image, target.getTarget().getRectangle().toRectangle());
}
 
源代码12 项目: deploymentmanager-autogen   文件: SoyFunctions.java
private static List<VmTierSpec> extractTierList(SoyValue tiersArg) {
  if (tiersArg instanceof SoyList) {
    List<? extends SoyValue> list = ((SoyList) tiersArg).asResolvedJavaList();
    return Lists.transform(list, new Function<SoyValue, VmTierSpec>() {
      @Override
      public VmTierSpec apply(SoyValue soyValue) {
        return (VmTierSpec) ((SoyProtoValue) soyValue).getProto();
      }
    });
  } else if (tiersArg instanceof SoyProtoValue) {
    return ((MultiVmDeploymentPackageSpec) ((SoyProtoValue) tiersArg).getProto()).getTiersList();
  } else {
    throw new IllegalArgumentException("Unable to extract tier list from argument");
  }
}
 
源代码13 项目: brooklyn-server   文件: LdapSecurityProvider.java
/**
 * Returns the LDAP path for the user
 *
 * @param user
 * @return String
 */
protected String getUserDN(String user) {
    List<String> domain = Lists.transform(Arrays.asList(ldapRealm.split("\\.")), new Function<String, String>() {
        @Override
        public String apply(String input) {
            return "dc=" + input;
        }
    });

    String dc = Joiner.on(",").join(domain).toLowerCase();
    return "cn=" + user + ",ou=" + organizationUnit + "," + dc;
}
 
源代码14 项目: phoenix   文件: SkipScanFilterTest.java
private static Collection<?> foreach(KeyRange[][] ranges, int[] widths, int[] slotSpans, Expectation... expectations) {
    List<List<KeyRange>> cnf = Lists.transform(Lists.newArrayList(ranges), ARRAY_TO_LIST);
    List<Object> ret = Lists.newArrayList();
    ret.add(new Object[] {cnf, widths, slotSpans, Arrays.asList(expectations)} );
    return ret;
}
 
源代码15 项目: buck   文件: XmlElement.java
/**
 * Compares this element with another {@link XmlElement} ignoring all attributes belonging to
 * the {@link SdkConstants#TOOLS_URI} namespace.
 *
 * @param other the other element to compare against.
 * @return a {@link String} describing the differences between the two XML elements or
 * {@link Optional#absent()} if they are equals.
 */
@NonNull
public Optional<String> compareTo(Object other) {

    if (!(other instanceof XmlElement)) {
        return Optional.of("Wrong type");
    }
    XmlElement otherNode = (XmlElement) other;

    // compare element names
    if (getXml().getNamespaceURI() != null) {
        if (!getXml().getLocalName().equals(otherNode.getXml().getLocalName())) {
            return Optional.of(
                    String.format("Element names do not match: %1$s versus %2$s",
                            getXml().getLocalName(),
                            otherNode.getXml().getLocalName()));
        }
        // compare element ns
        String thisNS = getXml().getNamespaceURI();
        String otherNS = otherNode.getXml().getNamespaceURI();
        if ((thisNS == null && otherNS != null)
                || (thisNS != null && !thisNS.equals(otherNS))) {
            return Optional.of(
                    String.format("Element namespaces names do not match: %1$s versus %2$s",
                            thisNS, otherNS));
        }
    } else {
        if (!getXml().getNodeName().equals(otherNode.getXml().getNodeName())) {
            return Optional.of(String.format("Element names do not match: %1$s versus %2$s",
                    getXml().getNodeName(),
                    otherNode.getXml().getNodeName()));
        }
    }

    // compare attributes, we do it twice to identify added/missing elements in both lists.
    Optional<String> message = checkAttributes(this, otherNode);
    if (message.isPresent()) {
        return message;
    }
    message = checkAttributes(otherNode, this);
    if (message.isPresent()) {
        return message;
    }

    // compare children
    @NonNull List<Node> expectedChildren = filterUninterestingNodes(getXml().getChildNodes());
    @NonNull List<Node> actualChildren = filterUninterestingNodes(otherNode.getXml().getChildNodes());
    if (expectedChildren.size() != actualChildren.size()) {

        if (expectedChildren.size() > actualChildren.size()) {
            // missing some.
            @NonNull List<String> missingChildrenNames =
                    Lists.transform(expectedChildren, NODE_TO_NAME);
            missingChildrenNames.removeAll(Lists.transform(actualChildren, NODE_TO_NAME));
            return Optional.of(String.format(
                    "%1$s: Number of children do not match up: "
                            + "expected %2$d versus %3$d at %4$s, missing %5$s",
                    getId(),
                    expectedChildren.size(),
                    actualChildren.size(),
                    otherNode.printPosition(),
                    Joiner.on(",").join(missingChildrenNames)));
        } else {
            // extra ones.
            @NonNull List<String> extraChildrenNames = Lists.transform(actualChildren, NODE_TO_NAME);
            extraChildrenNames.removeAll(Lists.transform(expectedChildren, NODE_TO_NAME));
            return Optional.of(String.format(
                    "%1$s: Number of children do not match up: "
                            + "expected %2$d versus %3$d at %4$s, extra elements found : %5$s",
                    getId(),
                    expectedChildren.size(),
                    actualChildren.size(),
                    otherNode.printPosition(),
                    Joiner.on(",").join(expectedChildren)));
        }
    }
    for (Node expectedChild : expectedChildren) {
        if (expectedChild.getNodeType() == Node.ELEMENT_NODE) {
            @NonNull XmlElement expectedChildNode = new XmlElement((Element) expectedChild, mDocument);
            message = findAndCompareNode(otherNode, actualChildren, expectedChildNode);
            if (message.isPresent()) {
                return message;
            }
        }
    }
    return Optional.absent();
}
 
源代码16 项目: dsl-devkit   文件: ResourceDescriptionDeltaTest.java
@SuppressWarnings("PMD.CyclomaticComplexity")
private IResourceDescription createDescriptionWithFingerprints(final String... fragmentsAndFingerprints) {
  final URI resourceURI = URI.createURI("foo:/foo.foo");
  return new AbstractResourceDescription() {

    public Iterable<QualifiedName> getImportedNames() {
      return ImmutableSet.of();
    }

    public Iterable<IReferenceDescription> getReferenceDescriptions() {
      return ImmutableSet.of();
    }

    public URI getURI() {
      return resourceURI;
    }

    @Override
    protected List<IEObjectDescription> computeExportedObjects() {
      return Lists.transform(Lists.newArrayList(fragmentsAndFingerprints), new Function<String, IEObjectDescription>() {
        public IEObjectDescription apply(final String from) {
          final String fragment = from.split(":")[0];
          final String fingerprint = from.indexOf(':') != -1 ? from.split(":")[1] : from;
          return new AbstractEObjectDescription() {

            public QualifiedName getQualifiedName() {
              return QualifiedName.create(fragment);
            }

            public QualifiedName getName() {
              return getQualifiedName();
            }

            public URI getEObjectURI() {
              return resourceURI.appendFragment(fragment);
            }

            public EObject getEObjectOrProxy() {
              return null;
            }

            public EClass getEClass() {
              return null;
            }

            @Override
            public String[] getUserDataKeys() {
              return new String[] {IFingerprintComputer.OBJECT_FINGERPRINT};
            }

            @Override
            public String getUserData(final String name) {
              return name.equals(IFingerprintComputer.OBJECT_FINGERPRINT) ? Integer.toString(fingerprint.hashCode()) : null; // NOPMD
            }
          };
        }
      });
    }
  };
}
 
源代码17 项目: Bats   文件: Lattice.java
public List<String> uniqueColumnNames() {
  return Lists.transform(columns, column -> column.alias);
}
 
源代码18 项目: storm   文件: PrettyProtobuf.java
/**
 * Pretty-print List of mesos protobuf Offers.
 */
public static String offerListToString(List<Offer> offers) {
  List<String> offersAsStrings = Lists.transform(offers, offerToStringTransform);
  return String.format("[\n%s]", StringUtils.join(offersAsStrings, ",\n"));
}
 
源代码19 项目: c5-replicator   文件: OLogRawDataContent.java
private static List<ByteBuffer> sliceAll(List<ByteBuffer> buffers) {
  return Lists.transform(buffers, ByteBuffer::slice);
}
 
源代码20 项目: java-n-IDE-for-Android   文件: XmlElement.java
/**
 * Compares this element with another {@link XmlElement} ignoring all attributes belonging to
 * the {@link SdkConstants#TOOLS_URI} namespace.
 *
 * @param other the other element to compare against.
 * @return a {@link String} describing the differences between the two XML elements or
 * {@link Optional#absent()} if they are equals.
 */
public Optional<String> compareTo(Object other) {

    if (!(other instanceof XmlElement)) {
        return Optional.of("Wrong type");
    }
    XmlElement otherNode = (XmlElement) other;

    // compare element names
    if (getXml().getNamespaceURI() != null) {
        if (!getXml().getLocalName().equals(otherNode.getXml().getLocalName())) {
            return Optional.of(
                    String.format("Element names do not match: %1$s versus %2$s",
                            getXml().getLocalName(),
                            otherNode.getXml().getLocalName()));
        }
        // compare element ns
        String thisNS = getXml().getNamespaceURI();
        String otherNS = otherNode.getXml().getNamespaceURI();
        if ((thisNS == null && otherNS != null)
                || (thisNS != null && !thisNS.equals(otherNS))) {
            return Optional.of(
                    String.format("Element namespaces names do not match: %1$s versus %2$s",
                            thisNS, otherNS));
        }
    } else {
        if (!getXml().getNodeName().equals(otherNode.getXml().getNodeName())) {
            return Optional.of(String.format("Element names do not match: %1$s versus %2$s",
                    getXml().getNodeName(),
                    otherNode.getXml().getNodeName()));
        }
    }

    // compare attributes, we do it twice to identify added/missing elements in both lists.
    Optional<String> message = checkAttributes(this, otherNode);
    if (message.isPresent()) {
        return message;
    }
    message = checkAttributes(otherNode, this);
    if (message.isPresent()) {
        return message;
    }

    // compare children
    List<Node> expectedChildren = filterUninterestingNodes(getXml().getChildNodes());
    List<Node> actualChildren = filterUninterestingNodes(otherNode.getXml().getChildNodes());
    if (expectedChildren.size() != actualChildren.size()) {

        if (expectedChildren.size() > actualChildren.size()) {
            // missing some.
            List<String> missingChildrenNames =
                    Lists.transform(expectedChildren, NODE_TO_NAME);
            missingChildrenNames.removeAll(Lists.transform(actualChildren, NODE_TO_NAME));
            return Optional.of(String.format(
                    "%1$s: Number of children do not match up: "
                            + "expected %2$d versus %3$d at %4$s, missing %5$s",
                    getId(),
                    expectedChildren.size(),
                    actualChildren.size(),
                    otherNode.printPosition(),
                    Joiner.on(",").join(missingChildrenNames)));
        } else {
            // extra ones.
            List<String> extraChildrenNames = Lists.transform(actualChildren, NODE_TO_NAME);
            extraChildrenNames.removeAll(Lists.transform(expectedChildren, NODE_TO_NAME));
            return Optional.of(String.format(
                    "%1$s: Number of children do not match up: "
                            + "expected %2$d versus %3$d at %4$s, extra elements found : %5$s",
                    getId(),
                    expectedChildren.size(),
                    actualChildren.size(),
                    otherNode.printPosition(),
                    Joiner.on(",").join(expectedChildren)));
        }
    }
    for (Node expectedChild : expectedChildren) {
        if (expectedChild.getNodeType() == Node.ELEMENT_NODE) {
            XmlElement expectedChildNode = new XmlElement((Element) expectedChild, mDocument);
            message = findAndCompareNode(otherNode, actualChildren, expectedChildNode);
            if (message.isPresent()) {
                return message;
            }
        }
    }
    return Optional.absent();
}