com.google.common.collect.Range.asSet()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(6.1k)|赞(0)|评价(0)|浏览(145)

本文整理了Java中com.google.common.collect.Range.asSet方法的一些代码示例,展示了Range.asSet的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Range.asSet方法的具体详情如下:
包路径:com.google.common.collect.Range
类名称:Range
方法名:asSet

Range.asSet介绍

[英]Returns an ContiguousSet containing the same values in the given domain Range#contains by this range.

Note: a.asSet(d).equals(b.asSet(d)) does not imply a.equals(b)! For example, a and b could be [2..4] and (1..5), or the empty ranges [3..3) and [4..4).

Warning: Be extremely careful what you do with the asSet view of a large range (such as Range.greaterThan(0)). Certain operations on such a set can be performed efficiently, but others (such as Set#hashCode or Collections#frequency) can cause major performance problems.

The returned set's Object#toString method returns a short-hand form of the set's contents, such as "[1..100]"}.
[中]返回一个连续集,该连续集包含给定域范围#包含的相同值。
注:a.资产(d)。equals(b.asSet(d))并不意味着a.equals(b)!例如,a和b可以是[2..4]和(1..5),或者是空范围[3..3]和[4..4]。
警告:在使用大范围的资产视图(例如range.greaterThan(0))时要格外小心。对这样一个集合的某些操作可以高效地执行,但其他操作(如集合#哈希代码或集合#频率)可能会导致严重的性能问题。
返回的集合的Object#toString方法返回集合内容的简写形式,例如“[1..100]”。

代码示例

代码示例来源:origin: com.facebook.giraph.hive/hive-io-exp-core

private int[] computeColumnIds(List<String> columnNames, HiveTableSchema tableSchema) {
 List<Integer> ints;
 if (columnNames.isEmpty()) {
  Range<Integer> range = Ranges.closedOpen(0, tableSchema.numColumns());
  ints = range.asSet(DiscreteDomains.integers()).asList();
 } else {
  ints = transform(columnNames, HiveTableSchemas
    .schemaLookupFunc(tableSchema));
 }
 int[] result = new int[ints.size()];
 for (int i = 0; i < ints.size(); ++i) {
  result[i] = ints.get(i);
 }
 return result;
}

代码示例来源:origin: org.sonatype.sisu/sisu-guava

/* @Override */ ContiguousSet<C> headSetImpl(C toElement, boolean inclusive) {
 return range.intersection(Ranges.upTo(toElement, BoundType.forBoolean(inclusive)))
   .asSet(domain);
}

代码示例来源:origin: org.apache.twill/twill-yarn

Set<Integer> instancesToRemove = instanceIds == null ? null : ImmutableSet.copyOf(instanceIds);
if (instancesToRemove == null) {
 instancesToRemove = Ranges.closedOpen(0, runningCount).asSet(DiscreteDomains.integers());

代码示例来源:origin: apache/twill

Set<Integer> instancesToRemove = instanceIds == null ? null : ImmutableSet.copyOf(instanceIds);
if (instancesToRemove == null) {
 instancesToRemove = Ranges.closedOpen(0, runningCount).asSet(DiscreteDomains.integers());

代码示例来源:origin: facebookarchive/hive-io-experimental

/**
 * Compute column IDs from names
 *
 * @param columnNames names of columns
 * @param tableSchema schema for Hive table
 * @return array of column IDs
 */
private int[] computeColumnIds(List<String> columnNames, HiveTableSchema tableSchema)
{
 List<Integer> ints;
 if (columnNames.isEmpty()) {
  Range<Integer> range = Ranges.closedOpen(0, tableSchema.numColumns());
  ints = range.asSet(DiscreteDomains.integers()).asList();
 } else {
  ints = transform(columnNames, HiveTableSchemas
    .schemaLookupFunc(tableSchema));
 }
 int[] result = new int[ints.size()];
 for (int i = 0; i < ints.size(); ++i) {
  result[i] = ints.get(i);
 }
 return result;
}

代码示例来源:origin: org.sonatype.sisu/sisu-guava

/* @Override */ ContiguousSet<C> tailSetImpl(C fromElement, boolean inclusive) {
 return range.intersection(Ranges.downTo(fromElement, BoundType.forBoolean(inclusive)))
   .asSet(domain);
}

代码示例来源:origin: org.sonatype.sisu/sisu-guava

@Override public ContiguousSet<C> intersection(ContiguousSet<C> other) {
 checkNotNull(other);
 checkArgument(this.domain.equals(other.domain));
 if (other.isEmpty()) {
  return other;
 } else {
  C lowerEndpoint = Ordering.natural().max(this.first(), other.first());
  C upperEndpoint = Ordering.natural().min(this.last(), other.last());
  return (lowerEndpoint.compareTo(upperEndpoint) < 0)
    ? Ranges.closed(lowerEndpoint, upperEndpoint).asSet(domain)
    : new EmptyContiguousSet<C>(domain);
 }
}

代码示例来源:origin: org.sonatype.sisu/sisu-guava

/* @Override */ ContiguousSet<C> subSetImpl(C fromElement, boolean fromInclusive, C toElement,
  boolean toInclusive) {
 return range.intersection(Ranges.range(fromElement, BoundType.forBoolean(fromInclusive),
   toElement, BoundType.forBoolean(toInclusive))).asSet(domain);
}

代码示例来源:origin: cdapio/cdap

@Override
public synchronized void setRestartAllInstancesRequest(String serviceName, long startTimeMs, long endTimeMs,
                            boolean isSuccess) {
 Preconditions.checkNotNull(serviceName, "Service name should not be null.");
 RestartStatus status = isSuccess ? RestartStatus.SUCCESS : RestartStatus.FAILURE;
 Integer serviceInstance = getServiceInstance(serviceName);
 int instanceCount = (serviceInstance == null) ? 0 : serviceInstance;
 Set<Integer> instancesToRestart = Ranges.closedOpen(0, instanceCount).asSet(DiscreteDomains.integers());
 RestartServiceInstancesStatus restartStatus =
  new RestartServiceInstancesStatus(serviceName, startTimeMs, endTimeMs, status, instancesToRestart);
 String toJson = GSON.toJson(restartStatus, RestartServiceInstancesStatus.class);
 table.put(Bytes.toBytes(serviceName + "-restart"), Bytes.toBytes(toJson));
}

代码示例来源:origin: co.cask.cdap/cdap-app-fabric

@Override
public synchronized void setRestartAllInstancesRequest(String serviceName, long startTimeMs, long endTimeMs,
                            boolean isSuccess) {
 Preconditions.checkNotNull(serviceName, "Service name should not be null.");
 RestartStatus status = isSuccess ? RestartStatus.SUCCESS : RestartStatus.FAILURE;
 Integer serviceInstance = getServiceInstance(serviceName);
 int instanceCount = (serviceInstance == null) ? 0 : serviceInstance;
 Set<Integer> instancesToRestart = Ranges.closedOpen(0, instanceCount).asSet(DiscreteDomains.integers());
 RestartServiceInstancesStatus restartStatus =
  new RestartServiceInstancesStatus(serviceName, startTimeMs, endTimeMs, status, instancesToRestart);
 String toJson = GSON.toJson(restartStatus, RestartServiceInstancesStatus.class);
 table.put(Bytes.toBytes(serviceName + "-restart"), Bytes.toBytes(toJson));
}

代码示例来源:origin: pl.edu.icm.polindex/polindex-core

void removeSourceArticleCitationsWithIndexRange(String sourceArticleId, Integer minIndex, Integer maxIndex) {
  Range<Integer> indexRange = Ranges.closed(minIndex, maxIndex);
  ResolvedCitationQuery query = new ResolvedCitationQuery()
      .withSourceArticleId(sourceArticleId)
      .withCitationIndexIn(indexRange.asSet(DiscreteDomains.integers()));
  resolvedCitationStore.remove(query);
}

代码示例来源:origin: kite-sdk/kite-examples

for (int second : Ranges.closed(0, 15000).asSet(DiscreteDomains.integers())) {
 LOG.info("Generating log message " + second);

相关文章