-
- All Superinterfaces:
AddressComponent,AddressComponentRange,AddressDivisionSeries,AddressItem,AddressItemRange,AddressStringDivisionSeries,java.lang.Comparable<AddressItem>,java.io.Serializable
- All Known Subinterfaces:
AddressSection,IPAddressSegmentSeries
- All Known Implementing Classes:
Address,IPAddress,IPAddressSection,IPv4Address,IPv4AddressSection,IPv6Address,IPv6AddressSection,MACAddress,MACAddressSection
public interface AddressSegmentSeries extends AddressDivisionSeries, AddressComponent
Represents a series of address segments, each of equal byte size, the byte size being a whole number of bytes. Each segment can potentially range over multiple values, and thus this series of segments can represent many different values as well.- Author:
- sfoley
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description AddressSegmentSeriesadjustPrefixBySegment(boolean nextSegment)Increases or decreases prefix length to the next segment boundary.AddressSegmentSeriesadjustPrefixBySegment(boolean nextSegment, boolean zeroed)Increases or decreases prefix length to the next segment boundary.AddressSegmentSeriesadjustPrefixLength(int adjustment)Increases or decreases prefix length by the given increment.AddressSegmentSeriesadjustPrefixLength(int adjustment, boolean zeroed)Increases or decreases prefix length by the given increment.AddressSegmentSeriesapplyPrefixLength(int prefixLength)Deprecated.use #setPrefixLength(int)intgetBitsPerSegment()Returns the number of bits comprising each segment in this series.intgetBytesPerSegment()Returns the number of bytes comprising each segment in this series.java.lang.Iterable<? extends AddressSegmentSeries>getIterable()Useful for using an instance in a "for-each loop".AddressSegmentSeriesgetLower()If this represents a series with ranging values, returns a series representing the lower values of the range.intgetMaxSegmentValue()Returns the maximum possible segment value for this type of address.AddressSectiongetSection()Gets the subsection from the series that comprises all segmentsAddressSectiongetSection(int index)Gets the subsection from the series starting from the given index The first segment is at index 0.AddressSectiongetSection(int index, int endIndex)Gets the subsection from the series starting from the given index and ending just before the give endIndex The first segment is at index 0.AddressSegmentgetSegment(int index)Returns the segment from this series at the given index.intgetSegmentCount()Returns the number of segments in this series.AddressSegment[]getSegments()Returns the segments of this series of segments as an array.voidgetSegments(int start, int end, AddressSegment[] segs, int index)get the segments from start to end and insert into the segs array at the given indexvoidgetSegments(AddressSegment[] segs)Copies the existing segments into the given array.java.lang.String[]getSegmentStrings()Returns the an array with the values of each segment as they would appear in the normalized with wildcards string.AddressSegmentSeriesgetUpper()If this represents a series with ranging values, returns a series representing the upper values of the range.AddressSegmentSeriesincrement(long increment)Returns the series from the subnet that is the given increment upwards into the subnet range, with the increment of 0 returning the first address in the range.AddressSegmentSeriesincrementBoundary(long increment)If the given increment is positive, adds the value to the upper series (getUpper()) in the subnet range to produce a new series.default booleanisOneBit(int prefixBitIndex)Returns true if the bit in the lower value of this series at the given index is 1, where index 0 is the most significant bit.java.util.Iterator<? extends AddressSegmentSeries>iterator()Iterates through the individual address components.java.util.Iterator<? extends AddressSegmentSeries>prefixBlockIterator()Iterates through the individual prefix blocks.AddressComponentSpliterator<? extends AddressSegmentSeries>prefixBlockSpliterator()Partitions and traverses through the individual prefix blocks for the prefix length of this series.java.util.stream.Stream<? extends AddressSegmentSeries>prefixBlockStream()Returns a sequential stream of the individual prefix blocks for the prefix length of this series.java.util.Iterator<? extends AddressSegmentSeries>prefixIterator()Iterates through the individual prefixes.AddressComponentSpliterator<? extends AddressSegmentSeries>prefixSpliterator()Partitions and traverses through the individual prefixes for the prefix length of this series.java.util.stream.Stream<? extends AddressSegmentSeries>prefixStream()Returns a sequential stream of the individual prefixes for the prefix length of this series.AddressSegmentSeriesremovePrefixLength()Deprecated.to remove the prefix length, usewithoutPrefixLength(), to remove the prefix length and zero out the bits beyond the prefix, useadjustPrefixLength(int)withAddressDivisionSeries.getBitCount()as the argument, as in adjustPrefixLength(getBitCount())AddressSegmentSeriesremovePrefixLength(boolean zeroed)Deprecated.AddressSegmentSeriesreverseBits(boolean perByte)Returns a new segment series with the bits reversed.AddressSegmentSeriesreverseBytes()Returns a new segment series with the bytes reversed.AddressSegmentSeriesreverseBytesPerSegment()Returns a new segment series with the bytes reversed within each segment.AddressSegmentSeriesreverseSegments()Returns a new segment series with the segments reversed.java.util.Iterator<? extends AddressSegment[]>segmentsIterator()Iterates through the individual segments.AddressComponentRangeSpliterator<? extends AddressSegmentSeries,? extends AddressSegment[]>segmentsSpliterator()Partitions and traverses through the individual segment arrays.java.util.stream.Stream<? extends AddressSegment[]>segmentsStream()Returns a sequential stream of the individual segment arrays.AddressSegmentSeriessetPrefixLength(int prefixLength)Sets the prefix length.AddressSegmentSeriessetPrefixLength(int prefixLength, boolean zeroed)Sets the prefix length.AddressComponentSpliterator<? extends AddressSegmentSeries>spliterator()Partitions and traverses through the individual address components.java.util.stream.Stream<? extends AddressSegmentSeries>stream()Returns a sequential stream of the individual address components.default booleantestBit(int n)Analogous toBigInteger.testBit(int), Computes (this & (1 << n)) != 0)java.lang.StringtoCanonicalString()Produces the canonical representation of the addressjava.lang.StringtoCompressedString()Produces a short representation of the address while remaining within the confines of standard representation(s) of the addressAddressSegmentSeriestoPrefixBlock()If this series has a prefix length, returns the block for that prefix.AddressSegmentSerieswithoutPrefixLength()Provides the same address with no prefix.-
Methods inherited from interface inet.ipaddr.AddressComponent
getNetwork, toHexString, toNormalizedString
-
Methods inherited from interface inet.ipaddr.format.AddressDivisionSeries
getBitCount, getBlockCount, getCount, getDivision, getDivisionStrings, getPrefixCount, getPrefixCount, getPrefixLength, getSequentialBlockIndex, isMore, isPrefixBlock, isPrefixed, isSequential, isSinglePrefixBlock
-
Methods inherited from interface inet.ipaddr.format.AddressItem
compareTo, containsPrefixBlock, containsSinglePrefixBlock, getByteCount, getBytes, getBytes, getBytes, getMinPrefixLengthForBlock, getPrefixLengthForSingleBlock, getUpperBytes, getUpperBytes, getUpperBytes, getUpperValue, getValue, includesMax, includesZero, isFullRange, isMax, isMultiple, isZero
-
Methods inherited from interface inet.ipaddr.format.string.AddressStringDivisionSeries
getDivisionCount
-
-
-
-
Method Detail
-
getSegmentCount
int getSegmentCount()
Returns the number of segments in this series.- Returns:
-
getBitsPerSegment
int getBitsPerSegment()
Returns the number of bits comprising each segment in this series. Segments in the same series are equal length.- Returns:
-
getBytesPerSegment
int getBytesPerSegment()
Returns the number of bytes comprising each segment in this series. Segments in the same series are equal length.- Returns:
-
getMaxSegmentValue
int getMaxSegmentValue()
Returns the maximum possible segment value for this type of address. Note this is not the maximum value of the range of segment values in this specific address, this is the maximum value of any segment for this address type, and is usually determined by the number of bits per segment.- Returns:
- the maximum possible segment value for a series of the same type
-
getSection
AddressSection getSection()
Gets the subsection from the series that comprises all segments- Returns:
-
getSection
AddressSection getSection(int index)
Gets the subsection from the series starting from the given index The first segment is at index 0.- Parameters:
index-- Returns:
- Throws:
java.lang.IndexOutOfBoundsException- if index is negative
-
getSection
AddressSection getSection(int index, int endIndex)
Gets the subsection from the series starting from the given index and ending just before the give endIndex The first segment is at index 0.- Parameters:
index-endIndex-- Returns:
- Throws:
java.lang.IndexOutOfBoundsException- if index is negative or endIndex extends beyond the end of the series
-
getSegment
AddressSegment getSegment(int index)
Returns the segment from this series at the given index. The first segment is at index 0. A segment is an address division, seeAddressDivisionSeries.getDivision(int), the difference being that all segments in a given series are the same bit count, while divisions can have variable length.- Returns:
- Throws:
java.lang.IndexOutOfBoundsException- if the index is negative or as large as the segment count
-
getSegmentStrings
java.lang.String[] getSegmentStrings()
Returns the an array with the values of each segment as they would appear in the normalized with wildcards string.- Returns:
-
getSegments
void getSegments(AddressSegment[] segs)
Copies the existing segments into the given array. The array size should be at least as large asgetSegmentCount()- Throws:
java.lang.IndexOutOfBoundsException- if the provided array is too small
-
getSegments
void getSegments(int start, int end, AddressSegment[] segs, int index)get the segments from start to end and insert into the segs array at the given index- Parameters:
start- the first segment index from this series to be includedend- the first segment index to be excludedsegs- the target arrayindex- where to insert the segments in the segs array
-
getSegments
AddressSegment[] getSegments()
Returns the segments of this series of segments as an array. This must create a new array, so for efficiency usegetSegment(int)andgetSegmentCount()instead when feasible.- Returns:
-
getLower
AddressSegmentSeries getLower()
If this represents a series with ranging values, returns a series representing the lower values of the range. If this represents an series with a single value in each segment, returns this.- Specified by:
getLowerin interfaceAddressComponentRange- Returns:
-
getUpper
AddressSegmentSeries getUpper()
If this represents a series with ranging values, returns a series representing the upper values of the range. If this represents a series with a single value in each segment, returns this.- Specified by:
getUpperin interfaceAddressComponentRange- Returns:
-
testBit
default boolean testBit(int n)
Analogous toBigInteger.testBit(int), Computes (this & (1 << n)) != 0)- Parameters:
n-- Returns:
- Throws:
java.lang.IndexOutOfBoundsException- if the index is negative or as large as the bit count- See Also:
isOneBit(int)
-
isOneBit
default boolean isOneBit(int prefixBitIndex)
Returns true if the bit in the lower value of this series at the given index is 1, where index 0 is the most significant bit. For example, isOneBit(0) for 128.0.0.0 and isOneBit(31) for 0.0.0.1 are both true, while isOneBit(31) for 128.0.0.0/24 is false. isOneBit(0) for 8000:: is true.- Parameters:
prefixBitIndex-- Returns:
- Throws:
java.lang.IndexOutOfBoundsException- if the index is negative or as large as the bit count- See Also:
testBit(int)
-
getIterable
java.lang.Iterable<? extends AddressSegmentSeries> getIterable()
Description copied from interface:AddressComponentRangeUseful for using an instance in a "for-each loop". Otherwise just callAddressComponentRange.iterator()directly.- Specified by:
getIterablein interfaceAddressComponentRange- Returns:
-
iterator
java.util.Iterator<? extends AddressSegmentSeries> iterator()
Description copied from interface:AddressComponentRangeIterates through the individual address components.An address component can represent an individual segment, address, or section, or it can represent multiple, typically a subnet of addresses or a range of segment or section values.
Call
AddressItem.isMultiple()to determine if this instance represents multiple, orAddressItem.getCount()for the count.- Specified by:
iteratorin interfaceAddressComponentRange- Returns:
-
spliterator
AddressComponentSpliterator<? extends AddressSegmentSeries> spliterator()
Description copied from interface:AddressComponentRangePartitions and traverses through the individual address components.- Specified by:
spliteratorin interfaceAddressComponent- Specified by:
spliteratorin interfaceAddressComponentRange- Returns:
-
stream
java.util.stream.Stream<? extends AddressSegmentSeries> stream()
Description copied from interface:AddressComponentRangeReturns a sequential stream of the individual address components. For a parallel stream, callBaseStream.parallel()on the returned stream.- Specified by:
streamin interfaceAddressComponentRange- Returns:
-
prefixIterator
java.util.Iterator<? extends AddressSegmentSeries> prefixIterator()
Iterates through the individual prefixes.If the series has no prefix length, then this is equivalent to
iterator()
-
prefixSpliterator
AddressComponentSpliterator<? extends AddressSegmentSeries> prefixSpliterator()
Partitions and traverses through the individual prefixes for the prefix length of this series.- Returns:
-
prefixBlockIterator
java.util.Iterator<? extends AddressSegmentSeries> prefixBlockIterator()
Iterates through the individual prefix blocks.If the series has no prefix length, then this is equivalent to
iterator()
-
prefixStream
java.util.stream.Stream<? extends AddressSegmentSeries> prefixStream()
Returns a sequential stream of the individual prefixes for the prefix length of this series. For a parallel stream, callBaseStream.parallel()on the returned stream.- Returns:
-
prefixBlockSpliterator
AddressComponentSpliterator<? extends AddressSegmentSeries> prefixBlockSpliterator()
Partitions and traverses through the individual prefix blocks for the prefix length of this series.- Returns:
-
prefixBlockStream
java.util.stream.Stream<? extends AddressSegmentSeries> prefixBlockStream()
Returns a sequential stream of the individual prefix blocks for the prefix length of this series. For a parallel stream, callBaseStream.parallel()on the returned stream.- Returns:
-
segmentsIterator
java.util.Iterator<? extends AddressSegment[]> segmentsIterator()
Iterates through the individual segments.
-
segmentsSpliterator
AddressComponentRangeSpliterator<? extends AddressSegmentSeries,? extends AddressSegment[]> segmentsSpliterator()
Partitions and traverses through the individual segment arrays.- Returns:
-
segmentsStream
java.util.stream.Stream<? extends AddressSegment[]> segmentsStream()
Returns a sequential stream of the individual segment arrays. For a parallel stream, callBaseStream.parallel()on the returned stream.- Returns:
-
increment
AddressSegmentSeries increment(long increment) throws AddressValueException
Returns the series from the subnet that is the given increment upwards into the subnet range, with the increment of 0 returning the first address in the range.If the subnet has multiple values and the increment exceeds the subnet size, then the amount by which it exceeds the size - 1 is added to the upper series of the range (the final iterator value).
If the increment is negative, it is added to the lower series of the range (the first iterator value).
If the subnet is just a single address values, the series is simply incremented by the given value, positive or negative.
If a subnet has multiple values, a positive increment value is equivalent to the same number of values from the
iterator()For instance, a increment of 0 is the first value from the iterator, an increment of 1 is the second value from the iterator, and so on. A negative increment added to the subnet count is equivalent to the same number of values preceding the upper bound of the iterator. For instance, an increment of count - 1 is the last value from the iterator, an increment of count - 2 is the second last value, and so on.An increment of size count gives you the series just above the highest series of the subnet. To get the series just below the lowest series of the subnet, use the increment -1.
- Parameters:
increment-- Returns:
- Throws:
AddressValueException- in case of underflow or overflow
-
incrementBoundary
AddressSegmentSeries incrementBoundary(long increment) throws AddressValueException
If the given increment is positive, adds the value to the upper series (getUpper()) in the subnet range to produce a new series. If the given increment is negative, adds the value to the lower series (getLower()) in the subnet range to produce a new series. If the increment is zero, returns this.In the case where the series is a single value, this simply returns the address produced by adding the given increment to this address series.
- Parameters:
increment-- Returns:
- Throws:
AddressValueException- in case of underflow or overflow
-
toCanonicalString
java.lang.String toCanonicalString()
Produces the canonical representation of the address- Returns:
-
toCompressedString
java.lang.String toCompressedString()
Produces a short representation of the address while remaining within the confines of standard representation(s) of the address- Returns:
-
reverseSegments
AddressSegmentSeries reverseSegments()
Returns a new segment series with the segments reversed. This does not throwIncompatibleAddressExceptionsince all address series can reverse their segments.- Returns:
-
reverseBits
AddressSegmentSeries reverseBits(boolean perByte)
Returns a new segment series with the bits reversed.- Specified by:
reverseBitsin interfaceAddressComponent- Parameters:
perByte- if true, only the bits in each byte are reversed, if false, then all bits in the component are reversed- Returns:
- Throws:
IncompatibleAddressException- if reversing the bits within a single segment cannot be done because the segment represents a range, and when all values in that range are reversed, the result is not contiguous. In practice this means that to be reversible the range must include all values except possibly the largest and/or smallest.
-
reverseBytes
AddressSegmentSeries reverseBytes()
Returns a new segment series with the bytes reversed.- Specified by:
reverseBytesin interfaceAddressComponent- Returns:
- Throws:
IncompatibleAddressException- if the segments have more than 1 bytes, and if reversing the bits within a single segment cannot be done because the segment represents a range that is not the entire segment range.
-
reverseBytesPerSegment
AddressSegmentSeries reverseBytesPerSegment()
Returns a new segment series with the bytes reversed within each segment.- Returns:
- Throws:
IncompatibleAddressException- if the segments have more than 1 bytes, and if reversing the bits within a single segment cannot be done because the segment represents a range that is not the entire segment range.
-
toPrefixBlock
AddressSegmentSeries toPrefixBlock()
If this series has a prefix length, returns the block for that prefix. Otherwise, this address series is returned.- Returns:
- the block of address series for the prefix length
-
removePrefixLength
@Deprecated AddressSegmentSeries removePrefixLength()
Deprecated.to remove the prefix length, usewithoutPrefixLength(), to remove the prefix length and zero out the bits beyond the prefix, useadjustPrefixLength(int)withAddressDivisionSeries.getBitCount()as the argument, as in adjustPrefixLength(getBitCount())Removes the prefix length while zeroing out the bits beyond the prefix.If the series already has a prefix length, the bits outside the prefix become zero. Use
withoutPrefixLength()to remove the prefix length without changing the series values.Equivalent to calling removePrefixLength(true)
- Returns:
- See Also:
for an alternative which does not change the address series values.
-
withoutPrefixLength
AddressSegmentSeries withoutPrefixLength()
Provides the same address with no prefix. The values remain unchanged.Use
removePrefixLength()as an alternative that deletes the host at the same time by zeroing the host values.
-
removePrefixLength
@Deprecated AddressSegmentSeries removePrefixLength(boolean zeroed)
Deprecated.Removes the prefix length. If zeroed is false, the bits that were host bits do not become zero, unlikeremovePrefixLength()- Parameters:
zeroed- whether the bits outside the prefix become zero- Returns:
-
adjustPrefixBySegment
AddressSegmentSeries adjustPrefixBySegment(boolean nextSegment)
Increases or decreases prefix length to the next segment boundary.Follows the same rules as
adjustPrefixLength(int):
When prefix length is increased, the bits moved within the prefix become zero. When a prefix length is decreased, the bits moved outside the prefix become zero. To avoid the zeroing behaviour, useadjustPrefixBySegment(boolean, boolean)with second arg false.- Parameters:
nextSegment- whether to move prefix to previous or following segment boundary- Returns:
-
adjustPrefixBySegment
AddressSegmentSeries adjustPrefixBySegment(boolean nextSegment, boolean zeroed)
Increases or decreases prefix length to the next segment boundary.- Parameters:
nextSegment- whether to move prefix to previous or following segment boundaryzeroed- whether the bits that move from one side of the prefix to the other become zero or retain their original values- Returns:
-
adjustPrefixLength
AddressSegmentSeries adjustPrefixLength(int adjustment)
Increases or decreases prefix length by the given increment.When prefix length is increased, the bits moved within the prefix become zero. When the prefix is extended beyond the segment series boundary, it is removed. When a prefix length is decreased, the bits moved outside the prefix become zero. To avoid the zeroing behaviour, use
adjustPrefixLength(int, boolean)with second arg false.- Parameters:
adjustment-- Returns:
-
adjustPrefixLength
AddressSegmentSeries adjustPrefixLength(int adjustment, boolean zeroed)
Increases or decreases prefix length by the given increment.- Parameters:
zeroed- whether the bits that move from one side of the prefix to the other become zero or retain their original valuesadjustment- the increment- Returns:
-
setPrefixLength
AddressSegmentSeries setPrefixLength(int prefixLength)
Sets the prefix length.If this series has a prefix length, and the prefix length is increased, the bits moved within the prefix become zero. For an alternative that does not set bits to zero, use
setPrefixLength(int, boolean)with the second argument as false.When the prefix is extended beyond the segment series boundary, it is removed.
The bits that move from one side of the prefix length to the other (ie bits moved into the prefix or outside the prefix) are zeroed.
- Parameters:
prefixLength-- Returns:
-
setPrefixLength
AddressSegmentSeries setPrefixLength(int prefixLength, boolean zeroed)
Sets the prefix length.When the prefix is extended beyond the segment series boundary, it is removed.
- Parameters:
zeroed- whether the bits that move from one side of the prefix length to the other (ie bits moved into the prefix or outside the prefix) are zeroed.- Returns:
-
applyPrefixLength
@Deprecated AddressSegmentSeries applyPrefixLength(int prefixLength)
Deprecated.use #setPrefixLength(int)Applies the given prefix length to create a new segment series.Similar to
setPrefixLength(int)except that prefix lengths are never increased. When this series already has a prefix length that is less than or equal to the requested prefix length, this series is returned.Otherwise the returned series has the given prefix length.
The bits moved outside the prefix will become zero in the returned series.
- Parameters:
prefixLength-- Returns:
- See Also:
setPrefixLength(int)
-
-