Java Code Examples for com.google.common.collect.Ordering#usingToString()

The following examples show how to use com.google.common.collect.Ordering#usingToString() . 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: SdkMavenRepository.java    From bazel with Apache License 2.0 7 votes vote down vote up
/**
 * Parses a set of maven repository directory trees looking for and parsing .pom files.
 */
static SdkMavenRepository create(Iterable<Path> mavenRepositories) throws IOException {
  Collection<Path> pomPaths = new ArrayList<>();
  for (Path mavenRepository : mavenRepositories) {
    pomPaths.addAll(
        FileSystemUtils.traverseTree(mavenRepository, path -> path.toString().endsWith(".pom")));
  }

  ImmutableSortedSet.Builder<Pom> poms =
      new ImmutableSortedSet.Builder<>(Ordering.usingToString());
  for (Path pomPath : pomPaths) {
    try {
      Pom pom = Pom.parse(pomPath);
      if (pom != null) {
        poms.add(pom);
      }
    } catch (ParserConfigurationException | SAXException e) {
      throw new IOException(e);
    }
  }
  return new SdkMavenRepository(poms.build());
}
 
Example 2
Source File: SchemaVersion.java    From nomulus with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a set of classes corresponding to all types persisted within the model classes, sorted
 * by the string representation.
 */
private static SortedSet<Class<?>> getAllPersistedTypes() {
  SortedSet<Class<?>> persistedTypes = new TreeSet<>(Ordering.usingToString());
  // Do a breadth-first search for persisted types, starting with @Entity types and expanding each
  // ImmutableObject by querying it for all its persisted field types.
  persistedTypes.addAll(EntityClasses.ALL_CLASSES);
  Queue<Class<?>> queue = new ArrayDeque<>(persistedTypes);
  while (!queue.isEmpty()) {
    Class<?> clazz = queue.remove();
    if (ImmutableObject.class.isAssignableFrom(clazz)) {
      for (Class<?> persistedFieldType : ModelUtils.getPersistedFieldTypes(clazz)) {
        if (persistedTypes.add(persistedFieldType)) {
          // If we haven't seen this type before, add it to the queue to query its field types.
          queue.add(persistedFieldType);
        }
      }
    }
  }
  return persistedTypes;
}
 
Example 3
Source File: AdminServiceImpl.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
@Override
public void removeInactiveAgents(int durationDays) {
    if (durationDays < MIN_DURATION_DAYS_FOR_INACTIVITY) {
        throw new IllegalArgumentException("duration may not be less than " + MIN_DURATION_DAYS_FOR_INACTIVITY + " days");
    }
    Map<String, List<String>> inactiveAgentMap = new TreeMap<>(Ordering.usingToString());

    List<Application> applications = this.applicationIndexDao.selectAllApplicationNames();
    Set<String> applicationNames = new TreeSet<>(Ordering.usingToString());
    // remove duplicates (same application name but different service type)
    for (Application application : applications) {
        applicationNames.add(application.getName());
    }
    for (String applicationName : applicationNames) {
        List<String> agentIds = this.applicationIndexDao.selectAgentIds(applicationName);
        Collections.sort(agentIds);
        List<String> inactiveAgentIds = filterInactiveAgents(agentIds, durationDays);
        if (!CollectionUtils.isEmpty(inactiveAgentIds)) {
            inactiveAgentMap.put(applicationName, inactiveAgentIds);
        }
    }
    // map may become big, but realistically won't cause OOM
    // if it becomes an issue, consider deleting inside the loop above
    logger.info("deleting {}", inactiveAgentMap);
    this.applicationIndexDao.deleteAgentIds(inactiveAgentMap);
}
 
Example 4
Source File: AdminServiceImpl.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, List<Application>> getInactiveAgents(String applicationName, int durationDays) {
    if (applicationName == null) {
        throw new NullPointerException("applicationName");
    }
    if (durationDays < MIN_DURATION_DAYS_FOR_INACTIVITY) {
        throw new IllegalArgumentException("duration may not be less than " + MIN_DURATION_DAYS_FOR_INACTIVITY + " days");
    }
    List<String> agentIds = this.applicationIndexDao.selectAgentIds(applicationName);
    if (CollectionUtils.isEmpty(agentIds)) {
        return Collections.emptyMap();
    }
    Map<String, List<Application>> agentIdMap = this.getAgentIdMap();
    Map<String, List<Application>> inactiveAgentMap = new TreeMap<>(Ordering.usingToString());
    List<String> inactiveAgentIds = filterInactiveAgents(agentIds, durationDays);
    for (String inactiveAgentId : inactiveAgentIds) {
        List<Application> applications = agentIdMap.get(inactiveAgentId);
        inactiveAgentMap.put(inactiveAgentId, applications);
    }
    return inactiveAgentMap;
}
 
Example 5
Source File: DefaultDirectedGraph.java    From Bats with Apache License 2.0 5 votes vote down vote up
@Override public String toString() {
  @SuppressWarnings("unchecked")
  final Ordering<V> vertexOrdering = (Ordering) Ordering.usingToString();
  @SuppressWarnings("unchecked")
  final Ordering<E> edgeOrdering = (Ordering) Ordering.usingToString();
  return toString(vertexOrdering, edgeOrdering);
}
 
Example 6
Source File: DefaultDirectedGraph.java    From Quicksql with MIT License 5 votes vote down vote up
@Override public String toString() {
  @SuppressWarnings("unchecked")
  final Ordering<V> vertexOrdering = (Ordering) Ordering.usingToString();
  @SuppressWarnings("unchecked")
  final Ordering<E> edgeOrdering = (Ordering) Ordering.usingToString();
  return toString(vertexOrdering, edgeOrdering);
}
 
Example 7
Source File: DefaultDirectedGraph.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override public String toString() {
  @SuppressWarnings("unchecked")
  final Ordering<V> vertexOrdering = (Ordering) Ordering.usingToString();
  @SuppressWarnings("unchecked")
  final Ordering<E> edgeOrdering = (Ordering) Ordering.usingToString();
  return toString(vertexOrdering, edgeOrdering);
}
 
Example 8
Source File: AdminServiceImpl.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, List<Application>> getAgentIdMap() {
    Map<String, List<Application>> agentIdMap = new TreeMap<>(Ordering.usingToString());
    List<Application> applications = this.applicationIndexDao.selectAllApplicationNames();
    for (Application application : applications) {
        List<String> agentIds = this.applicationIndexDao.selectAgentIds(application.getName());
        for (String agentId : agentIds) {
            if (!agentIdMap.containsKey(agentId)) {
                agentIdMap.put(agentId, new ArrayList<Application>());
            }
            agentIdMap.get(agentId).add(application);
        }
    }
    return agentIdMap;
}
 
Example 9
Source File: AdminServiceImpl.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, List<Application>> getDuplicateAgentIdMap() {
    Map<String, List<Application>> duplicateAgentIdMap = new TreeMap<>(Ordering.usingToString());
    Map<String, List<Application>> agentIdMap = this.getAgentIdMap();
    for (Map.Entry<String, List<Application>> entry : agentIdMap.entrySet()) {
        String agentId = entry.getKey();
        List<Application> applications = entry.getValue();
        if (applications.size() > 1) {
            duplicateAgentIdMap.put(agentId, applications);
        }
    }
    return duplicateAgentIdMap;
}
 
Example 10
Source File: SdkMavenRepository.java    From bazel with Apache License 2.0 5 votes vote down vote up
static Pom parse(Path path) throws IOException, ParserConfigurationException, SAXException {
  Document pomDocument = null;
  try (InputStream in = path.getInputStream()) {
    pomDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in);
  }
  Node packagingNode = pomDocument.getElementsByTagName("packaging").item(0);
  String packaging = packagingNode == null ? DEFAULT_PACKAGING : packagingNode.getTextContent();
  MavenCoordinate coordinate = MavenCoordinate.create(
      pomDocument.getElementsByTagName("groupId").item(0).getTextContent(),
      pomDocument.getElementsByTagName("artifactId").item(0).getTextContent(),
      pomDocument.getElementsByTagName("version").item(0).getTextContent());

  ImmutableSortedSet.Builder<MavenCoordinate> dependencyCoordinates =
      new ImmutableSortedSet.Builder<>(Ordering.usingToString());
  NodeList dependencies = pomDocument.getElementsByTagName("dependency");
  for (int i = 0; i < dependencies.getLength(); i++) {
    if (dependencies.item(i) instanceof Element) {
      Element dependency = (Element) dependencies.item(i);
      dependencyCoordinates.add(MavenCoordinate.create(
          dependency.getElementsByTagName("groupId").item(0).getTextContent(),
          dependency.getElementsByTagName("artifactId").item(0).getTextContent(),
          dependency.getElementsByTagName("version").item(0).getTextContent()));
    }
  }

  return new AutoValue_SdkMavenRepository_Pom(
      path, packaging, coordinate, dependencyCoordinates.build());
}