本文整理汇总了Java中com.google.common.collect.ImmutableRangeSet.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java ImmutableRangeSet.Builder方法的具体用法?Java ImmutableRangeSet.Builder怎么用?Java ImmutableRangeSet.Builder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.collect.ImmutableRangeSet
的用法示例。
在下文中一共展示了ImmutableRangeSet.Builder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testComplement
import com.google.common.collect.ImmutableRangeSet; //导入方法依赖的package包/类
@Test
public void testComplement() {
Range range;
ImmutableRangeSet.Builder builder;
Interval.Difference difference;
difference = a.complement();
range = Range.lessThan(2);
builder = ImmutableRangeSet.builder().add(range);
range = Range.greaterThan(4);
builder.add(range);
assertEquals(difference.getRanges(), builder.build());
assertEquals(difference.getDimension(), 1);
difference = Interval.MAGIC.complement();
builder = ImmutableRangeSet.builder();
assertEquals(difference.getRanges(), builder.build());
assertEquals(difference.getDimension(), 0);
difference = Interval.NULL.complement();
range = Range.all();
builder = ImmutableRangeSet.builder().add(range);
assertEquals(difference.getRanges(), builder.build());
assertEquals(difference.getDimension(), 0);
}
示例2: loadFrom
import com.google.common.collect.ImmutableRangeSet; //导入方法依赖的package包/类
public static QuoteFilter loadFrom(ByteSource source) throws IOException {
final ImmutableList<String> input = source.asCharSource(Charsets.UTF_8).readLines();
if (input.isEmpty()) {
throw new IOException("Attempted to load QuoteFilter from empty file");
}
final int numEntries = Integer.parseInt(input.get(0));
final int expectedLines = 2 * numEntries + 1;
if (input.size() != expectedLines) {
throw new IOException(String.format(
"Invalid number of lines when loading QuoteFiler. Expected %d, got %d",
expectedLines, input.size()));
}
final ImmutableMap.Builder<Symbol, ImmutableRangeSet<Integer>> ret = ImmutableMap.builder();
int curLine = 1;
for (int i = 0; i < numEntries; ++i) {
final Symbol docid = Symbol.from(input.get(curLine++));
final ImmutableRangeSet.Builder<Integer> ranges = ImmutableRangeSet.builder();
for (final String part : StringUtils.OnSpaces.split(input.get(curLine++))) {
final List<String> endPointStrings = DASH_SPLITTER.splitToList(part);
if (endPointStrings.size() != 2) {
throw new IOException(String.format("Invalid range serialization %s", part));
}
ranges.add(Range.closed(Integer.parseInt(endPointStrings.get(0)),
Integer.parseInt(endPointStrings.get(1))));
}
ret.put(docid, ranges.build());
}
return QuoteFilter.createFromBannedRegions(ret.build());
}
示例3: rangesToInstanceIds
import com.google.common.collect.ImmutableRangeSet; //导入方法依赖的package包/类
/**
* Performs {@link #toRange(IRange)} for a collection of ranges, and convert the result to a set
* of integers.
*
* @param ranges Ranges to convert.
* @return A set representing {@code ranges}.
*/
public static Set<Integer> rangesToInstanceIds(Iterable<IRange> ranges) {
ImmutableRangeSet.Builder<Integer> instanceIds = ImmutableRangeSet.builder();
for (IRange range : ranges) {
instanceIds.add(toRange(range));
}
return instanceIds.build().asSet(DiscreteDomain.integers());
}
示例4: getInstanceIds
import com.google.common.collect.ImmutableRangeSet; //导入方法依赖的package包/类
/**
* Creates a range set representing all instance IDs represented by a set of instance
* configurations included in a job update.
*
* @param configs Job update components.
* @return A range set representing the instance IDs mentioned in instance groupings.
*/
public static ImmutableRangeSet<Integer> getInstanceIds(Set<IInstanceTaskConfig> configs) {
ImmutableRangeSet.Builder<Integer> builder = ImmutableRangeSet.builder();
for (IInstanceTaskConfig config : configs) {
for (IRange range : config.getInstances()) {
builder.add(Range.closed(range.getFirst(), range.getLast()));
}
}
return builder.build();
}
示例5: createFrom
import com.google.common.collect.ImmutableRangeSet; //导入方法依赖的package包/类
/** Creates an IDN table given the lines from text file. */
static IdnTable createFrom(
String language, Iterable<String> data, Optional<LanguageValidator> languageValidator) {
ImmutableRangeSet.Builder<Integer> rangeSet = new ImmutableRangeSet.Builder<>();
URI url = null;
URI policy = null;
for (String line : data) {
// Remove leading and trailing whitespace.
line = line.trim();
// Handle special comment lines.
if (line.startsWith(URL_LINE_PREFIX)) {
url = URI.create(line.substring(URL_LINE_PREFIX.length()));
} else if (line.startsWith(POLICY_LINE_PREFIX)) {
policy = URI.create(line.substring(POLICY_LINE_PREFIX.length()));
}
// Skip empty and comment lines.
if (line.isEmpty() || line.startsWith("#")) {
continue;
}
int codepoint = readCodepoint(line);
rangeSet.add(Range.singleton(codepoint));
}
return new IdnTable(language, url, policy, rangeSet.build(), languageValidator);
}
示例6: fromRangeSet
import com.google.common.collect.ImmutableRangeSet; //导入方法依赖的package包/类
/**
* @see #fromRangeSet(RangeSet)
*/
@SafeVarargs
public static DigitMapping fromRangeSet(Range<Character>... ranges) {
ImmutableRangeSet.Builder<Character> builder = ImmutableRangeSet.builder();
for (Range<Character> range : ranges) {
builder.add(range);
}
return fromRangeSet(builder.build());
}
示例7: toRangeSet
import com.google.common.collect.ImmutableRangeSet; //导入方法依赖的package包/类
/**
* Converts the specified list into a range set.
*
* @param buffers the token restriction values
* @return the range set corresponding to the specified list
*/
private RangeSet<Token> toRangeSet(List<ByteBuffer> buffers)
{
ImmutableRangeSet.Builder<Token> builder = ImmutableRangeSet.builder();
for (ByteBuffer buffer : buffers)
builder.add(Range.singleton(deserializeToken(buffer)));
return builder.build();
}
示例8: Difference
import com.google.common.collect.ImmutableRangeSet; //导入方法依赖的package包/类
/**
* Construct a new Difference, which may have zero, one, or two non-null
* , nonempty, non-overlapping interval ranges in the same dimension.
* @param that interval
* @param other interval
* @see ImmutableRangeSet#add(com.google.common.collect.Range)
*/
private Difference(final Interval<C> that, final Interval<C> other) {
ImmutableRangeSet.Builder builder = ImmutableRangeSet.builder();
if(that.dimension == other.dimension) {
dimension = that.dimension;
} else {
dimension = 0;
}
if(that.overlaps(other)) {
dimension = that.getDimension();
builder.add(that.coalesce(other).toRange());
} else {
if(!that.hasNone() && !that.range.isEmpty()) {
dimension = that.dimension;
builder.add(that.range);
}
if(!other.hasNone() && !other.range.isEmpty()) {
if(dimension == 0) {
dimension = other.dimension;
}
if(dimension == other.dimension) {
builder.add(other.range);
}
}
}
ranges = builder.build();
}
示例9: parse
import com.google.common.collect.ImmutableRangeSet; //导入方法依赖的package包/类
public static Vlan parse(String vlan) {
if (!PATTERN.matcher(vlan).matches()) {
throw new IllegalArgumentException("invalid VLAN range: " + vlan);
}
ImmutableRangeSet.Builder<Integer> vlanRanges = ImmutableRangeSet.builder();
asList(vlan.split(",")).stream()
.map(part -> parsePart(part).canonical(integers()))
.forEach(vlanRanges::add);
return new Vlan(vlanRanges.build());
}
示例10: subtract
import com.google.common.collect.ImmutableRangeSet; //导入方法依赖的package包/类
public Vlan subtract(Set<Integer> vlanIds) {
ImmutableRangeSet.Builder<Integer> builder = ImmutableRangeSet.builder();
removeValuesFromRangeSet(vlanIds).asRanges().stream()
.map(r -> r.canonical(integers()))
.filter(r -> !r.isEmpty())
.forEach(builder::add);
return new Vlan(builder.build());
}
示例11: computeQuotedRegions
import com.google.common.collect.ImmutableRangeSet; //导入方法依赖的package包/类
/**
* Given the string contents of a document, will return the offset ranges of those portions within
* <quote> tags. This does not pay attention to the attributes of the quote tags.
*/
public static ImmutableRangeSet<Integer> computeQuotedRegions(String s) {
checkNotNull(s);
final ImmutableRangeSet.Builder<Integer> ret = ImmutableRangeSet.builder();
// current search position
int curPos = 0;
// search for first opening <quote> tag
int regionStart = StringUtils.earliestIndexOfAny(s, BANNED_REGION_STARTS, curPos);
// if we found a <quote> tag
while (regionStart != -1) {
curPos = regionStart;
int nestingCount = 1;
// until we find the matching </quote> tag..
while (nestingCount > 0) {
final int nextStart = StringUtils.earliestIndexOfAny(s, BANNED_REGION_STARTS, curPos + 1);
final int nextEnd = s.indexOf(BANNED_REGION_END, curPos + 1);
if (nextEnd == -1) {
// (a) uh-oh, we reached the end without ever finding a match
throw new RuntimeException(
String.format("<quote> tag opened at %d is never closed.", regionStart));
} else if (nextStart == -1 || nextEnd < nextStart) {
// (b) we find a </quote> before another <quote>, so
// we reduce the nesting level and remember the location
// of the closing tag
--nestingCount;
curPos = nextEnd;
} else if (nextEnd > nextStart) {
// (c) we found another <quote> before the end of the current
// <quote>, so there must be nesting.
++nestingCount;
curPos = nextStart;
} else {
throw new RuntimeException("It is impossible for nextEnd == nextStart");
}
}
// the only way we successfully exited is case (b)
// where curPos is the beginning of the </quote> tag
ret.add(Range.closed(regionStart, curPos + BANNED_REGION_END.length() - 1));
regionStart = StringUtils.earliestIndexOfAny(s, BANNED_REGION_STARTS, curPos + 1);
}
return ret.build();
}
示例12: linesBuilder
import com.google.common.collect.ImmutableRangeSet; //导入方法依赖的package包/类
ImmutableRangeSet.Builder<Integer> linesBuilder() {
return lines;
}
示例13: linesBuilder
import com.google.common.collect.ImmutableRangeSet; //导入方法依赖的package包/类
ImmutableRangeSet.Builder<Integer> linesBuilder() {
return lines;
}
示例14: testMinus
import com.google.common.collect.ImmutableRangeSet; //导入方法依赖的package包/类
@Test
public void testMinus() {
Range range;
ImmutableRangeSet.Builder builder;
Interval.Difference difference;
difference = c.minus(a);
range = Range.openClosed(4, 10);
builder = ImmutableRangeSet.builder().add(range);
assertEquals(difference.getRanges(), builder.build());
assertEquals(difference.getDimension(), 1);
difference = a.minus(a);
builder = ImmutableRangeSet.builder();
assertEquals(difference.getRanges(), builder.build());
assertEquals(difference.getDimension(), 1);
difference = a.minus(b);
range = a.toRange();
builder = ImmutableRangeSet.builder().add(range);
assertEquals(difference.getRanges(), builder.build());
assertEquals(difference.getDimension(), 1);
difference = b.minus(a);
range = b.toRange();
builder = ImmutableRangeSet.builder().add(range);
assertEquals(difference.getRanges(), builder.build());
assertEquals(difference.getDimension(), 1);
difference = c.minus(x);
range = Range.closedOpen(2, 5);
builder = ImmutableRangeSet.builder().add(range);
range = Range.openClosed(7, 10);
builder.add(range);
assertEquals(difference.getRanges(), builder.build());
assertEquals(difference.getDimension(), 1);
difference = x.minus(c);
builder = ImmutableRangeSet.builder();
assertEquals(difference.getRanges(), builder.build());
assertEquals(difference.getDimension(), 1);
}
示例15: parseRangeSet
import com.google.common.collect.ImmutableRangeSet; //导入方法依赖的package包/类
/**
* Parse multiple --lines flags, like {"1:12,14,20:36", "40:45,50"}. Multiple ranges can be given
* with multiple --lines flags or separated by commas. A single line can be set by a single
* number. Line numbers are {@code 1}-based, but are converted to the {@code 0}-based numbering
* used internally by google-java-format.
*/
private static void parseRangeSet(ImmutableRangeSet.Builder<Integer> result, String ranges) {
for (String range : COMMA_SPLITTER.split(ranges)) {
result.add(parseRange(range));
}
}