- java.lang.Object
-
- inet.ipaddr.format.AddressDivisionBase
-
- inet.ipaddr.format.standard.AddressDivision
-
- inet.ipaddr.mac.MACAddressSegment
-
- All Implemented Interfaces:
AddressComponent,AddressSegment,AddressComponentRange,AddressGenericDivision,AddressItem,AddressItemRange,AddressStringDivision,java.io.Serializable,java.lang.Comparable<AddressItem>,java.lang.Iterable<MACAddressSegment>
public class MACAddressSegment extends AddressDivision implements AddressSegment, java.lang.Iterable<MACAddressSegment>
Represents a segment of a MAC address. For MAC, segments are 1 byte. Segments are immutable, which also makes them thread-safe.- Author:
- sfoley
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class inet.ipaddr.format.standard.AddressDivision
AddressDivision.BitwiseOrResult, AddressDivision.MaskResult
-
-
Field Summary
Fields Modifier and Type Field Description static intMAX_CHARS-
Fields inherited from class inet.ipaddr.format.AddressDivisionBase
EXTENDED_DIGITS
-
-
Constructor Summary
Constructors Constructor Description MACAddressSegment(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontains(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.booleanequals(java.lang.Object other)Two 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.intgetBitCount()Provides the number of bits comprising this address itemintgetByteCount()Provides the number of bytes required for this address item, rounding up if the bit count is not a multiple of 8intgetDefaultTextualRadix()longgetDivisionValue()java.lang.Iterable<MACAddressSegment>getIterable()Useful for using an instance in a "for-each loop".MACAddressSegmentgetLower()If this segment represents a range of values, returns a segment representing just the lowest value in the range, otherwise returns this.intgetMaxDigitCount()intgetMaxSegmentValue()Gets the maximum possible value for this type of segment (for the highest range value of this particular segment, useAddressSegment.getUpper()longgetMaxValue()MACAddressNetworkgetNetwork()Returns 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.intgetSegmentValue()returns the lower valueMACAddressSegmentgetUpper()If this segment represents a range of values, returns a segment representing just the highest value in the range, otherwise returns this.longgetUpperDivisionValue()intgetUpperSegmentValue()returns the upper valueintgetValueCount()Returns 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.java.util.Iterator<MACAddressSegment>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.MACAddressSegmentreverseBits()MACAddressSegmentreverseBits(boolean perByte)Returns a new AddressComponent with the bits reversed.MACAddressSegmentreverseBytes()Returns an AddressComponent with the bytes reversed.AddressComponentSpliterator<MACAddressSegment>spliterator()Partitions and traverses through the individual address components.java.util.stream.Stream<MACAddressSegment>stream()Returns a sequential stream of the individual address components.java.lang.StringtoHexString(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.java.lang.StringtoNormalizedString()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.java.lang.StringtoNormalizedString(AddressDivisionGrouping.StringOptions options)-
Methods inherited from class inet.ipaddr.format.standard.AddressDivision
bitwiseOrRange, getDigitCount, getMaxDigitCount, getMinPrefixLengthForBlock, getPrefixLengthForSingleBlock, getUpperValue, getValue, hasUppercaseVariations, includesMax, includesZero, isBitwiseOrCompatibleWithRange, isMaskCompatibleWithRange, isMax, isMultiple, isZero, maskRange, matches, matchesWithMask, matchesWithMask
-
Methods inherited from class inet.ipaddr.format.AddressDivisionBase
getBytes, getBytes, getBytes, getDigitCount, getDigitCount, getLowerStandardString, getStandardString, getUpperBytes, getUpperBytes, getUpperBytes, toString
-
Methods inherited from interface inet.ipaddr.format.AddressItem
compareTo, getBytes, getBytes, getBytes, getCount, getMinPrefixLengthForBlock, getPrefixCount, getPrefixLengthForSingleBlock, getUpperBytes, getUpperBytes, getUpperBytes, getUpperValue, getValue, includesMax, includesZero, isFullRange, isMax, isMultiple, isZero
-
Methods inherited from interface inet.ipaddr.AddressSegment
isOneBit, testBit
-
Methods inherited from interface inet.ipaddr.format.string.AddressStringDivision
getDigitCount, getLowerStandardString, getMaxDigitCount, getStandardString
-
-
-
-
Field Detail
-
MAX_CHARS
public static final int MAX_CHARS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
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 Detail
-
getNetwork
public MACAddressNetwork 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
public MACAddressSegment 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
public MACAddressSegment 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
public MACAddressSegment reverseBits(boolean perByte)
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
public MACAddressSegment reverseBits()
-
reverseBytes
public MACAddressSegment 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
public boolean equals(java.lang.Object other)
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
public boolean contains(MACAddressSegment other)
- 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
public java.lang.Iterable<MACAddressSegment> 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
public java.util.Iterator<MACAddressSegment> 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 interfacejava.lang.Iterable<MACAddressSegment>
-
spliterator
public AddressComponentSpliterator<MACAddressSegment> 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 interfacejava.lang.Iterable<MACAddressSegment>
-
stream
public java.util.stream.Stream<MACAddressSegment> 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
public boolean prefixEquals(AddressSegment o, int segmentPrefixLength)
Description copied from interface:AddressSegmentReturns whether the given prefix bits match the same bits of the given segment.- Specified by:
prefixEqualsin interfaceAddressSegment- Returns:
-
overlaps
public boolean overlaps(AddressSegment other)
- Specified by:
overlapsin interfaceAddressSegment
-
contains
public boolean contains(AddressSegment other)
- Specified by:
containsin interfaceAddressSegment
-
toHexString
public java.lang.String toHexString(boolean with0xPrefix)
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
public java.lang.String 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
public java.lang.String toNormalizedString(AddressDivisionGrouping.StringOptions options)
-
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- 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.
-
-