Java Code Examples for com.google.common.collect.ImmutableRangeSet#of()

The following examples show how to use com.google.common.collect.ImmutableRangeSet#of() . 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: MarkerTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Test the PeriodicMarker constructor
 */
@Test
public void testConstructor() {
    PeriodicMarker marker = new PeriodicMarker("name", "label", "id", "referenceid", "color", 1.0, "ms", Range.atLeast(0L), 0L, ImmutableRangeSet.of(Range.all()));
    assertEquals("name", marker.getName());
    assertEquals("label", marker.getLabel());
    assertEquals("id", marker.getId());
    assertEquals("referenceid", marker.getReferenceId());
    assertEquals("color", marker.getColor());
    assertEquals(1.0, marker.getPeriod(), 0);
    assertEquals("ms", marker.getUnit());
    assertEquals(Range.atLeast(0L), marker.getRange());
    assertEquals(0L, marker.getOffset());
    assertEquals(ImmutableRangeSet.of(Range.all()), marker.getIndexRange());
    assertEquals(0, marker.getSubMarkers().size());
}
 
Example 2
Source File: TypeTest.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void exceptionTest() {
    final UnresolvedNumber min = UnresolvedNumber.min();
    final UnresolvedNumber max = UnresolvedNumber.max();
    final EnumPair enumPair = EnumPairBuilder.create("enum1", 1).setDescription("description")
            .setReference("reference").setUnknownSchemaNodes(mock(UnknownSchemaNode.class)).build();

    final RangeSet<Integer> rangeset = ImmutableRangeSet.of(Range.closed(1, 2));
    final InvalidRangeConstraintException invalidRangeConstraintException = new InvalidRangeConstraintException(
            rangeset, "error msg", "other important messages");
    assertSame(rangeset, invalidRangeConstraintException.getOffendingRanges());

    final InvalidBitDefinitionException invalidBitDefinitionException = new InvalidBitDefinitionException(
            BIT_A, "error msg", "other important messages");
    assertEquals(invalidBitDefinitionException.getOffendingBit(), BIT_A);

    final InvalidEnumDefinitionException invalidEnumDefinitionException = new InvalidEnumDefinitionException(
            enumPair, "error msg", "other important messages");
    assertEquals(invalidEnumDefinitionException.getOffendingEnum(), enumPair);
}
 
Example 3
Source File: MarkerConfigXmlParser.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private static RangeSet<Long> parseRangeSet(String rangeSetAttr) {
    if (rangeSetAttr.isEmpty()) {
        return ImmutableRangeSet.of(Range.all());
    }
    RangeSet<Long> rangeSet = TreeRangeSet.create();
    String[] ranges = rangeSetAttr.split(","); //$NON-NLS-1$
    if (ranges.length == 0) {
        rangeSet.add(Range.all());
    } else {
        for (String range : ranges) {
            rangeSet.add(parseRange(range));
        }
    }
    return rangeSet;
}
 
Example 4
Source File: MarkerTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Test the SplitMarker and WeightedMarker constructors and method addMarker
 */
@Test
public void testAddSubMarker() {
    PeriodicMarker marker = new PeriodicMarker("name", "label", "id", "referenceid", "color", 1.0, "ms", Range.atLeast(0L), 0L, ImmutableRangeSet.of(Range.all()));
    SubMarker subMarkerA = new SplitMarker("A", "a", "a", "color", Range.atLeast(0L), ImmutableRangeSet.of(Range.all()));
    marker.addSubMarker(subMarkerA);
    SubMarker subMarkerB = new WeightedMarker("B");
    marker.addSubMarker(subMarkerB);
    assertEquals(Arrays.asList(subMarkerA, subMarkerB), marker.getSubMarkers());
}
 
Example 5
Source File: MarkerSetTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Test the method addMarker
 */
@Test
public void testAddMarker() {
    MarkerSet markerSet = new MarkerSet("name", "id");
    Marker markerA = new PeriodicMarker("A", "A %d", "a", "ref.a", "color1", 1.0, "ms", Range.atLeast(1L), 1L, ImmutableRangeSet.of(Range.atLeast(1L)));
    markerSet.addMarker(markerA);
    Marker markerB = new PeriodicMarker("B", "B %d", "b", "ref.b", "color2", 2.0, "ns", Range.atLeast(2L), 2L, ImmutableRangeSet.of(Range.atLeast(2L)));
    markerSet.addMarker(markerB);
    assertEquals(Arrays.asList(markerA, markerB), markerSet.getMarkers());
}
 
Example 6
Source File: F5BigipConfiguration.java    From batfish with Apache License 2.0 5 votes vote down vote up
private @Nonnull TransformationStep computeVirtualIncomingPoolMemberTransformation(
    PoolMember member, boolean translateAddress, boolean translatePort) {
  TransformationStep addressTranslation =
      translateAddress
          ? new AssignIpAddressFromPool(
              TransformationType.DEST_NAT,
              IpField.DESTINATION,
              ImmutableRangeSet.of(Range.singleton(member.getAddress())))
          : null;
  TransformationStep portTranslation =
      translatePort
          ? new AssignPortFromPool(
              TransformationType.DEST_NAT,
              PortField.DESTINATION,
              member.getPort(),
              member.getPort())
          : null;
  if (translateAddress && translatePort) {
    // pool
    return new ApplyAll(addressTranslation, portTranslation);
  } else if (translateAddress) {
    // pool
    return addressTranslation;
  } else if (translatePort) {
    // pool
    return portTranslation;
  } else {
    // ip-forward or just pool with weird options
    return Noop.NOOP_DEST_NAT;
  }
}
 
Example 7
Source File: AddressObject.java    From batfish with Apache License 2.0 5 votes vote down vote up
/** Returns all addresses owned by this address object as an IP {@link RangeSet}. */
@Nonnull
public RangeSet<Ip> getAddressAsRangeSet() {
  if (_ip != null) {
    return ImmutableRangeSet.of(Range.singleton(_ip));
  } else if (_prefix != null) {
    return ImmutableRangeSet.of(
        Range.closed(_prefix.getPrefix().getStartIp(), _prefix.getPrefix().getEndIp()));
  } else if (_ipRange != null) {
    return ImmutableRangeSet.of(_ipRange);
  }
  return ImmutableRangeSet.of();
}
 
Example 8
Source File: SampleRowsData.java    From hop with Apache License 2.0 4 votes vote down vote up
public SampleRowsData() {
  super();
  rangeSet = ImmutableRangeSet.of();
  addlineField = false;
  outputRow = null;
}
 
Example 9
Source File: AssignIpAddressFromPool.java    From batfish with Apache License 2.0 4 votes vote down vote up
public AssignIpAddressFromPool(
    TransformationType type, IpField ipField, Ip poolStart, Ip poolEnd) {
  this(type, ipField, ImmutableRangeSet.of(Range.closed(poolStart, poolEnd)));
}
 
Example 10
Source File: PaloAltoConfiguration.java    From batfish with Apache License 2.0 4 votes vote down vote up
/** Converts {@link RuleEndpoint} to IP {@code RangeSet} */
@Nonnull
@SuppressWarnings("fallthrough")
private RangeSet<Ip> ruleEndpointToIpRangeSet(RuleEndpoint endpoint, Vsys vsys, Warnings w) {
  String endpointValue = endpoint.getValue();
  // Palo Alto allows object references that look like IP addresses, ranges, etc.
  // Devices use objects over constants when possible, so, check to see if there is a matching
  // group or object regardless of the type of endpoint we're expecting.
  if (vsys.getAddressObjects().containsKey(endpointValue)) {
    return vsys.getAddressObjects().get(endpointValue).getAddressAsRangeSet();
  }
  if (vsys.getAddressGroups().containsKey(endpoint.getValue())) {
    return vsys.getAddressGroups()
        .get(endpointValue)
        .getIpRangeSet(vsys.getAddressObjects(), vsys.getAddressGroups());
  }
  switch (vsys.getNamespaceType()) {
    case LEAF:
      if (_shared != null) {
        return ruleEndpointToIpRangeSet(endpoint, _shared, w);
      }
      // fall-through
    case SHARED:
      if (_panorama != null) {
        return ruleEndpointToIpRangeSet(endpoint, _panorama, w);
      }
      // fall-through
    default:
      // No named object found matching this endpoint, so parse the endpoint value as is
      switch (endpoint.getType()) {
        case Any:
          return ImmutableRangeSet.of(Range.closed(Ip.ZERO, Ip.MAX));
        case IP_ADDRESS:
          return ImmutableRangeSet.of(Range.singleton(Ip.parse(endpointValue)));
        case IP_PREFIX:
          Prefix prefix = Prefix.parse(endpointValue);
          return ImmutableRangeSet.of(Range.closed(prefix.getStartIp(), prefix.getEndIp()));
        case IP_RANGE:
          String[] ips = endpointValue.split("-");
          return ImmutableRangeSet.of(Range.closed(Ip.parse(ips[0]), Ip.parse(ips[1])));
        case REFERENCE:
          // Rely on undefined references to surface this issue (endpoint reference not defined)
          return ImmutableRangeSet.of();
        default:
          w.redFlag("Could not convert RuleEndpoint to RangeSet: " + endpoint);
          return ImmutableRangeSet.of();
      }
  }
}
 
Example 11
Source File: AbstractRangeRestrictedBaseType.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
AbstractRangeRestrictedBaseType(final QName qname, final N minValue, final N maxValue) {
    super(qname);
    this.rangeConstraint = new ResolvedRangeConstraint<>(BUILTIN_CONSTRAINT, ImmutableRangeSet.of(
        Range.closed(minValue, maxValue)));
}
 
Example 12
Source File: BaseDecimalType.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
private static RangeConstraint<BigDecimal> createRangeConstraint(final String min, final String max) {
    return new ResolvedRangeConstraint<>(BUILTIN_CONSTRAINT, ImmutableRangeSet.of(
        Range.closed(new BigDecimal(min), new BigDecimal(max))));
}
 
Example 13
Source File: SampleRowsData.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public SampleRowsData() {
  super();
  rangeSet = ImmutableRangeSet.of();
  addlineField = false;
  outputRow = null;
}