Class MACAddressSegment
- All Implemented Interfaces:
AddressComponent, AddressSegment, AddressComponentRange, AddressGenericDivision, AddressItem, AddressItemRange, AddressStringDivision, Serializable, Comparable<AddressItem>, Iterable<MACAddressSegment>
- Author:
- sfoley
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class AddressDivision
AddressDivision.BitwiseOrResult, AddressDivision.MaskResult -
Field Summary
FieldsFields inherited from class AddressDivisionBase
EXTENDED_DIGITS -
Constructor Summary
ConstructorsConstructorDescriptionMACAddressSegment(int value) Constructs a segment of an IPv4 or IPv6 address with the given value.MACAddressSegment(int lower, int upper) Constructs a segment of a MAC address that represents a range of values. -
Method Summary
Modifier and TypeMethodDescriptionbooleancontains(AddressSegment other) booleancontains(MACAddressSegment other) booleancontainsPrefixBlock(int divisionPrefixLen) Returns whether the values of this series contains the prefix block for the given prefix length.booleancontainsSinglePrefixBlock(int divisionPrefixLen) Returns whether the division range matches exactly the block of values for the given prefix length.booleanTwo divisions are equal if they: - they match type/version (ipv4, ipv6, mac, or a specific division class) - match bit counts - match values Prefix lengths, for those divisions that have them, are ignored.intProvides the number of bits comprising this address itemintProvides the number of bytes required for this address item, rounding up if the bit count is not a multiple of 8intlongUseful for using an instance in a "for-each loop".getLower()If this segment represents a range of values, returns a segment representing just the lowest value in the range, otherwise returns this.intintGets the maximum possible value for this type of segment (for the highest range value of this particular segment, useAddressSegment.getUpper()longReturns the network object for components of the same version (eg IPv4, IPv6 and MAC each have their own network object)intgetPrefixValueCount(int segmentPrefixLength) Returns the count of prefix values in this address segment for the given prefix bit count.intreturns the lower valuegetUpper()If this segment represents a range of values, returns a segment representing just the highest value in the range, otherwise returns this.longintreturns the upper valueintReturns the count of values in this address segment.inthashCode()booleanisBoundedBy(int value) Returns true if the possible values of this division fall below the given value.iterator()Iterates through the individual address components.booleanmatches(int value) booleanmatchesWithMask(int value, int mask) booleanmatchesWithMask(int lowerValue, int upperValue, int mask) booleanoverlaps(AddressSegment other) booleanprefixEquals(AddressSegment o, int segmentPrefixLength) Returns whether the given prefix bits match the same bits of the given segment.reverseBits(boolean perByte) Returns a new AddressComponent with the bits reversed.Returns an AddressComponent with the bytes reversed.Partitions and traverses through the individual address components.stream()Returns a sequential stream of the individual address components.toHexString(boolean with0xPrefix) Writes this address component as a single hexadecimal value with always the exact same number of characters, with or without a preceding 0x prefix.Produces a string that is consistent for all address components of the same type and version, and is also similar to the canonical stringAddressSegmentSeries.toCanonicalString()inAddressComponentinstances that are alsoAddressSegmentSeriesinstances.Methods inherited from class AddressDivision
bitwiseOrRange, getDigitCount, getMaxDigitCount, getMinPrefixLengthForBlock, getPrefixLengthForSingleBlock, getUpperValue, getValue, hasUppercaseVariations, includesMax, includesZero, isBitwiseOrCompatibleWithRange, isMaskCompatibleWithRange, isMax, isMultiple, isZero, maskRange, matches, matchesWithMask, matchesWithMaskMethods inherited from class AddressDivisionBase
getBytes, getBytes, getBytes, getDigitCount, getDigitCount, getLowerStandardString, getStandardString, getUpperBytes, getUpperBytes, getUpperBytes, toStringMethods inherited from interface AddressItem
compareTo, getBytes, getBytes, getBytes, getCount, getMinPrefixLengthForBlock, getPrefixCount, getPrefixLengthForSingleBlock, getUpperBytes, getUpperBytes, getUpperBytes, getUpperValue, getValue, includesMax, includesZero, isFullRange, isMax, isMultiple, isZeroMethods inherited from interface AddressSegment
isOneBit, testBitMethods inherited from interface AddressStringDivision
getDigitCount, getLowerStandardString, getMaxDigitCount, getStandardString
-
Field Details
-
MAX_CHARS
public static final int MAX_CHARS- See Also:
-
-
Constructor Details
-
MACAddressSegment
public MACAddressSegment(int value) Constructs a segment of an IPv4 or IPv6 address with the given value.- Parameters:
value- the value of the segment- Throws:
AddressValueException- if value is negative or too large
-
MACAddressSegment
public MACAddressSegment(int lower, int upper) Constructs a segment of a MAC address that represents a range of values.- Parameters:
lower- the lower value of the range of values represented by the segment.upper- the upper value of the range of values represented by the segment.- Throws:
AddressValueException- if value is negative or too large
-
-
Method Details
-
getNetwork
Description copied from interface:AddressComponentReturns the network object for components of the same version (eg IPv4, IPv6 and MAC each have their own network object)- Specified by:
getNetworkin interfaceAddressComponent- Returns:
-
getValueCount
public int getValueCount()Description copied from interface:AddressSegmentReturns the count of values in this address segment.- Specified by:
getValueCountin interfaceAddressSegment- Returns:
- the same value as
AddressItem.getCount()as an integer
-
getPrefixValueCount
public int getPrefixValueCount(int segmentPrefixLength) Description copied from interface:AddressSegmentReturns the count of prefix values in this address segment for the given prefix bit count.- Specified by:
getPrefixValueCountin interfaceAddressSegment- Returns:
- the count of values
-
getBitCount
public int getBitCount()Description copied from interface:AddressItemProvides the number of bits comprising this address item- Specified by:
getBitCountin interfaceAddressItem- Returns:
- the number of bits
-
getByteCount
public int getByteCount()Description copied from interface:AddressItemProvides the number of bytes required for this address item, rounding up if the bit count is not a multiple of 8- Specified by:
getByteCountin interfaceAddressItem- Returns:
- the number of bytes
-
getMaxValue
public long getMaxValue()- Overrides:
getMaxValuein classAddressDivision
-
getDivisionValue
public long getDivisionValue()- Specified by:
getDivisionValuein classAddressDivision
-
getUpperDivisionValue
public long getUpperDivisionValue()- Specified by:
getUpperDivisionValuein classAddressDivision
-
getSegmentValue
public int getSegmentValue()returns the lower value- Specified by:
getSegmentValuein interfaceAddressSegment
-
getUpperSegmentValue
public int getUpperSegmentValue()returns the upper value- Specified by:
getUpperSegmentValuein interfaceAddressSegment
-
getLower
Description copied from interface:AddressSegmentIf this segment represents a range of values, returns a segment representing just the lowest value in the range, otherwise returns this.- Specified by:
getLowerin interfaceAddressComponentRange- Specified by:
getLowerin interfaceAddressSegment- Returns:
-
getUpper
Description copied from interface:AddressSegmentIf this segment represents a range of values, returns a segment representing just the highest value in the range, otherwise returns this.- Specified by:
getUpperin interfaceAddressComponentRange- Specified by:
getUpperin interfaceAddressSegment- Returns:
-
reverseBits
Description copied from interface:AddressComponentReturns a new AddressComponent with the bits reversed. If this component represents a range of values that cannot be reversed, then this throwsIncompatibleAddressException. In a range the most significant bits stay constant while the least significant bits range over different values, so reversing that scenario results in a series of non-consecutive values, in most cases, which cannot be represented with a single AddressComponent object.In such cases where isMultiple() is true, call iterator(), getLower(), getUpper() or some other methods to break the series down into a series representing a single value.
- Specified by:
reverseBitsin interfaceAddressComponent- Specified by:
reverseBitsin interfaceAddressSegment- Parameters:
perByte- if true, only the bits in each byte are reversed, if false, then all bits in the component are reversed- Returns:
-
reverseBits
-
reverseBytes
Description copied from interface:AddressComponentReturns an AddressComponent with the bytes reversed. If this component represents a range of values that cannot be reversed, then this throwsIncompatibleAddressException. In a range the most significant bits stay constant while the least significant bits range over different values, so reversing that scenario results in a series of non-consecutive values, in most cases, which cannot be represented with a single AddressComponent object.In such cases where isMultiple() is true, call iterator(), getLower(), getUpper() or some other methods to break the series down into a series representing a single value.
- Specified by:
reverseBytesin interfaceAddressComponent- Specified by:
reverseBytesin interfaceAddressSegment- Returns:
-
isBoundedBy
public boolean isBoundedBy(int value) Description copied from class:AddressDivisionReturns true if the possible values of this division fall below the given value.- Specified by:
isBoundedByin interfaceAddressStringDivision- Overrides:
isBoundedByin classAddressDivision
-
hashCode
public int hashCode()- Overrides:
hashCodein classAddressDivision
-
equals
Description copied from class:AddressDivisionBaseTwo divisions are equal if they: - they match type/version (ipv4, ipv6, mac, or a specific division class) - match bit counts - match values Prefix lengths, for those divisions that have them, are ignored.- Specified by:
equalsin interfaceAddressSegment- Overrides:
equalsin classAddressDivision
-
contains
- Parameters:
other-- Returns:
- whether this subnet segment contains the given address segment
-
getDefaultTextualRadix
public int getDefaultTextualRadix() -
getMaxDigitCount
public int getMaxDigitCount() -
matches
public boolean matches(int value) - Specified by:
matchesin interfaceAddressSegment
-
matchesWithMask
public boolean matchesWithMask(int value, int mask) - Specified by:
matchesWithMaskin interfaceAddressSegment
-
matchesWithMask
public boolean matchesWithMask(int lowerValue, int upperValue, int mask) - Specified by:
matchesWithMaskin interfaceAddressSegment
-
getIterable
Description copied from interface:AddressComponentRangeUseful for using an instance in a "for-each loop". Otherwise just callAddressComponentRange.iterator()directly.- Specified by:
getIterablein interfaceAddressComponentRange- Specified by:
getIterablein interfaceAddressSegment- Returns:
-
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- Specified by:
iteratorin interfaceAddressSegment- Specified by:
iteratorin interfaceIterable<MACAddressSegment>- Returns:
-
spliterator
Description copied from interface:AddressComponentRangePartitions and traverses through the individual address components.- Specified by:
spliteratorin interfaceAddressComponent- Specified by:
spliteratorin interfaceAddressComponentRange- Specified by:
spliteratorin interfaceAddressSegment- Specified by:
spliteratorin interfaceIterable<MACAddressSegment>- Returns:
-
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- Specified by:
streamin interfaceAddressSegment- Returns:
-
getMaxSegmentValue
public int getMaxSegmentValue()Description copied from interface:AddressSegmentGets the maximum possible value for this type of segment (for the highest range value of this particular segment, useAddressSegment.getUpper()- Specified by:
getMaxSegmentValuein interfaceAddressSegment- Returns:
-
prefixEquals
Description copied from interface:AddressSegmentReturns whether the given prefix bits match the same bits of the given segment.- Specified by:
prefixEqualsin interfaceAddressSegment- Parameters:
o-segmentPrefixLength-- Returns:
-
overlaps
- Specified by:
overlapsin interfaceAddressSegment
-
contains
- Specified by:
containsin interfaceAddressSegment
-
toHexString
Description copied from interface:AddressComponentWrites this address component as a single hexadecimal value with always the exact same number of characters, with or without a preceding 0x prefix.If this component represents a range of values outside of the network prefix length, then this is printed as a range of two hex values.
For instance, for IPv4 addresses there are 8 hex characters, for IPv6 addresses there are 32 hex characters.
- Specified by:
toHexStringin interfaceAddressComponent
-
toNormalizedString
Description copied from interface:AddressComponentProduces a string that is consistent for all address components of the same type and version, and is also similar to the canonical stringAddressSegmentSeries.toCanonicalString()inAddressComponentinstances that are alsoAddressSegmentSeriesinstances.- Specified by:
toNormalizedStringin interfaceAddressComponent- Returns:
-
toNormalizedString
-
containsPrefixBlock
public boolean containsPrefixBlock(int divisionPrefixLen) Description copied from interface:AddressItemReturns whether the values of this series contains the prefix block for the given prefix length.Use
AddressItem.getMinPrefixLengthForBlock()to determine the smallest prefix length for which this method returns true.- Specified by:
containsPrefixBlockin interfaceAddressItem- Parameters:
divisionPrefixLen-- Returns:
- whether the division range includes the block of values for the given prefix length
-
containsSinglePrefixBlock
public boolean containsSinglePrefixBlock(int divisionPrefixLen) Returns whether the division range matches exactly the block of values for the given prefix length.- Specified by:
containsSinglePrefixBlockin interfaceAddressItem- Parameters:
divisionPrefixLen-- Returns:
- whether the range of this division matches the range for a single prefix with a single value and the given prefix length.
-