@Test public void containsPrefixTest() { Prefix prefix = Prefix.parse("10.10.10.0/24"); _ps.addPrefix(prefix); assertThat( "Shorter prefixes not included", _ps.containsPrefix(Prefix.parse("10.10.10.0/20")), equalTo(false)); assertThat( "Exact given prefix is included", _ps.containsPrefix(Prefix.parse("10.10.10.0/24")), equalTo(true)); assertThat( "Longer prefixes not included", _ps.containsPrefix(Prefix.parse("10.10.10.0/26")), equalTo(false)); assertThat( "Prefixes with mismatch in masked bits not included", _ps.containsPrefix(Prefix.parse("10.10.11.0/24")), equalTo(false)); assertThat( "Prefixes with mismatch in unmasked bits included", _ps.containsPrefix(Prefix.parse("10.10.10.255/24")), equalTo(true)); }
public boolean containsPrefix(Prefix prefix) { @Nullable Boolean result = _cache.get(prefix); if (result != null) { return result; } else { boolean contained = containsPrefixRange(PrefixRange.fromPrefix(prefix)); _cache.put(prefix, contained); return contained; } }
PrefixSpace implements Serializable { public boolean containsPrefix(Prefix prefix) { @Nullable Boolean result = _cache.get(prefix); if (result != null) { return result; } else { boolean contained = containsPrefixRange(PrefixRange.fromPrefix(prefix)); _cache.put(prefix, contained); return contained; } } }
PrefixSpace implements Serializable { public boolean containsPrefix(Prefix prefix) { @Nullable Boolean result = _cache.get(prefix); if (result != null) { return result; } else { boolean contained = containsPrefixRange(PrefixRange.fromPrefix(prefix)); _cache.put(prefix, contained); return contained; } } PrefixSpace(); @JsonCreator  PrefixSpace(Iterable<PrefixRange> prefixRanges);  PrefixSpace(PrefixRange... prefixRanges); }
PrefixSpace implements Serializable { public boolean containsPrefix(Prefix prefix) { @Nullable Boolean result = _cache.get(prefix); if (result != null) { return result; } else { boolean contained = containsPrefixRange(PrefixRange.fromPrefix(prefix)); _cache.put(prefix, contained); return contained; } } PrefixSpace(); @JsonCreator  PrefixSpace(Iterable<PrefixRange> prefixRanges);  PrefixSpace(PrefixRange... prefixRanges); void addPrefix(Prefix prefix); void addPrefixRange(PrefixRange prefixRange); void addSpace(PrefixSpace prefixSpace); boolean containsPrefix(Prefix prefix); boolean containsPrefixRange(PrefixRange prefixRange); @Override boolean equals(Object obj); Set<PrefixRange> getPrefixRanges(); @Override int hashCode(); PrefixSpace intersection(PrefixSpace intersectSpace); @JsonIgnore boolean isEmpty(); boolean overlaps(PrefixSpace intersectSpace); @Override String toString(); }
PrefixSpace implements Serializable { public boolean containsPrefix(Prefix prefix) { @Nullable Boolean result = _cache.get(prefix); if (result != null) { return result; } else { boolean contained = containsPrefixRange(PrefixRange.fromPrefix(prefix)); _cache.put(prefix, contained); return contained; } } PrefixSpace(); @JsonCreator  PrefixSpace(Iterable<PrefixRange> prefixRanges);  PrefixSpace(PrefixRange... prefixRanges); void addPrefix(Prefix prefix); void addPrefixRange(PrefixRange prefixRange); void addSpace(PrefixSpace prefixSpace); boolean containsPrefix(Prefix prefix); boolean containsPrefixRange(PrefixRange prefixRange); @Override boolean equals(Object obj); Set<PrefixRange> getPrefixRanges(); @Override int hashCode(); PrefixSpace intersection(PrefixSpace intersectSpace); @JsonIgnore boolean isEmpty(); boolean overlaps(PrefixSpace intersectSpace); @Override String toString();  }