- java.lang.Object
-
- inet.ipaddr.Address
-
- inet.ipaddr.mac.MACAddress
-
- All Implemented Interfaces:
AddressComponent
,AddressSegmentSeries
,AddressComponentRange
,AddressDivisionSeries
,AddressItem
,AddressItemRange
,AddressStringDivisionSeries
,java.io.Serializable
,java.lang.Comparable<AddressItem>
,java.lang.Iterable<MACAddress>
public class MACAddress extends Address implements java.lang.Iterable<MACAddress>
A MAC address, or a collection of multiple MAC addresses. Each segment can represent a single value or a range of values.You can construct a MAC address from a byte array, from a long, from a
Address.SegmentValueProvider
, from aNetworkInterface
, from aMACAddressSection
of 6 or 8 segments, or from an array of 6 or 8MACAddressSegment
objects.To construct one from a
String
useMACAddressString.toAddress()
orMACAddressString.getAddress()
- Author:
- sfoley
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class inet.ipaddr.Address
Address.AddressValueProvider, Address.SegmentValueProvider
-
-
Field Summary
-
Fields inherited from class inet.ipaddr.Address
ADDRESS_HIGH_VALUE_COMPARATOR, ADDRESS_LOW_VALUE_COMPARATOR, ALTERNATIVE_RANGE_SEPARATOR, ALTERNATIVE_RANGE_SEPARATOR_STR, ALTERNATIVE_SEGMENT_WILDCARD_STR, DEFAULT_ADDRESS_COMPARATOR, HEX_PREFIX, OCTAL_PREFIX, RANGE_SEPARATOR, RANGE_SEPARATOR_STR, SEGMENT_SQL_SINGLE_WILDCARD, SEGMENT_SQL_SINGLE_WILDCARD_STR, SEGMENT_SQL_WILDCARD, SEGMENT_SQL_WILDCARD_STR, SEGMENT_WILDCARD, SEGMENT_WILDCARD_STR
-
-
Constructor Summary
Constructors Constructor Description MACAddress(byte[] bytes)
Constructs a MAC address.MACAddress(long address)
Constructs a MAC address.MACAddress(long address, boolean extended)
Constructs a MAC address.MACAddress(Address.SegmentValueProvider valueProvider)
Constructs a MAC addressMACAddress(Address.SegmentValueProvider valueProvider, boolean extended)
Constructs a MAC addressMACAddress(Address.SegmentValueProvider lowerValueProvider, Address.SegmentValueProvider upperValueProvider)
Constructs a MAC addressMACAddress(Address.SegmentValueProvider lowerValueProvider, Address.SegmentValueProvider upperValueProvider, boolean extended)
Constructs a MAC addressMACAddress(MACAddressSection section)
Constructs a MAC address.MACAddress(MACAddressSegment[] segments)
Constructs a MAC address.MACAddress(java.net.NetworkInterface ni)
Constructs a MAC address for a network interface.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description MACAddress
adjustPrefixBySegment(boolean nextSegment)
Increases or decreases prefix length to the next segment boundary.MACAddress
adjustPrefixBySegment(boolean nextSegment, boolean zeroed)
Increases or decreases prefix length to the next segment boundary.MACAddress
adjustPrefixLength(int adjustment)
Increases or decreases prefix length by the given increment.MACAddress
adjustPrefixLength(int adjustment, boolean zeroed)
Increases or decreases prefix length by the given increment.MACAddress
applyPrefixLength(int prefixLength)
Deprecated.MACAddressNetwork.MACAddressCreator
getAddressCreator()
int
getBitCount()
Provides the number of bits comprising this address itemint
getBitsPerSegment()
Returns the number of bits comprising each segment in this series.int
getByteCount()
Provides the number of bytes required for this address item, rounding up if the bit count is not a multiple of 8int
getBytesPerSegment()
Returns the number of bytes comprising each segment in this series.MACAddressSegment
getDivision(int index)
AddressDivisionGrouping
getDottedAddress()
IPv6AddressNetwork
getIPv6Network()
java.lang.Iterable<MACAddress>
getIterable()
Useful for using an instance in a "for-each loop".MACAddress
getLower()
If this represents a series with ranging values, returns a series representing the lower values of the range.int
getMaxSegmentValue()
Returns the maximum possible segment value for this type of address.MACAddressNetwork
getNetwork()
Returns the network object for components of the same version (eg IPv4, IPv6 and MAC each have their own network object)MACAddressSection
getODISection()
MACAddressSection
getOUISection()
MACAddressSection
getSection()
Gets the subsection from the series that comprises all segmentsMACAddressSection
getSection(int index)
Gets the subsection from the series starting from the given index The first segment is at index 0.MACAddressSection
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.MACAddressSegment
getSegment(int index)
Returns the segment from this series at the given index.MACAddressSegment[]
getSegments()
Returns the segments of this series of segments as an array.MACAddress
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.MACAddress
increment(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.MACAddress
incrementBoundary(long increment)
If the given increment is positive, adds the value to the upper series (AddressSegmentSeries.getUpper()
) in the subnet range to produce a new series.boolean
isAllAddresses()
boolean
isEUI64(boolean asMAC)
Whether this section is consistent with an IPv6 EUI64 section, which means it came from an extended 8 byte address, and the corresponding segments in the middle match 0xff and 0xff/fe for MAC/not-MACboolean
isExtended()
boolean
isLocal()
Local MAC addresses have the second least significant bit of the first octet set to 1.boolean
isMulticast()
Multicast MAC addresses have the least significant bit of the first octet set to 1.boolean
isUnicast()
boolean
isUniversal()
Universal MAC addresses have second the least significant bit of the first octet set to 0.java.util.Iterator<MACAddress>
iterator()
Iterates through the individual address components.long
longValue()
static int
maxSegmentValue()
java.util.Iterator<MACAddress>
prefixBlockIterator()
Iterates through the individual prefix blocks.AddressComponentSpliterator<MACAddress>
prefixBlockSpliterator()
Partitions and traverses through the individual prefix blocks for the prefix length of this series.java.util.stream.Stream<MACAddress>
prefixBlockStream()
Returns a sequential stream of the individual prefix blocks for the prefix length of this series.java.util.Iterator<MACAddress>
prefixIterator()
Iterates through the individual prefixes.AddressComponentSpliterator<MACAddress>
prefixSpliterator()
Partitions and traverses through the individual prefixes for the prefix length of this series.java.util.stream.Stream<MACAddress>
prefixStream()
Returns a sequential stream of the individual prefixes for the prefix length of this series.MACAddress
removePrefixLength()
Deprecated.MACAddress
removePrefixLength(boolean zeroed)
Deprecated.MACAddress
replace(int startIndex, int endIndex, MACAddress replacement, int replacementIndex)
Replaces segments starting from startIndex and ending before endIndex with the same number of segments starting at replacementStartIndex from the replacement sectionMACAddress
reverseBits(boolean perByte)
Use to produce: "MSB format", "IBM format", "Token-Ring format", and "non-canonical form" See RFC 2469 section 2 Also see https://en.wikipedia.org/wiki/MAC_addressMACAddress
reverseBytes()
Returns a new segment series with the bytes reversed.MACAddress
reverseBytesPerSegment()
Returns a new segment series with the bytes reversed within each segment.MACAddress
reverseSegments()
Returns a new segment series with the segments reversed.java.util.Iterator<MACAddressSegment[]>
segmentsIterator()
Iterates through the individual segments.AddressComponentRangeSpliterator<MACAddress,MACAddressSegment[]>
segmentsSpliterator()
Partitions and traverses through the individual segment arrays.java.util.stream.Stream<MACAddressSegment[]>
segmentsStream()
Returns a sequential stream of the individual segment arrays.MACAddress
setPrefixLength(int prefixLength)
Sets the prefix length.MACAddress
setPrefixLength(int prefixLength, boolean zeroed)
Sets the prefix length.AddressComponentSpliterator<MACAddress>
spliterator()
Partitions and traverses through the individual address components.java.util.stream.Stream<MACAddress>
stream()
Returns a sequential stream of the individual address components.MACAddressString
toAddressString()
Returns a host identifier string representation for this address, which will be already validated.java.lang.String
toColonDelimitedString()
java.lang.String
toDashedString()
java.lang.String
toDottedString()
MACAddress
toEUI64(boolean asMAC)
Convert to IPv6 EUI-64 section http://standards.ieee.org/develop/regauth/tut/eui64.pdfIPv6AddressSection
toEUI64IPv6()
Converts to an Ipv6 address section.IPv6Address
toLinkLocalIPv6()
Converts to a link-local Ipv6 address.java.lang.String
toNormalizedString(AddressDivisionGrouping.StringOptions stringOptions)
MACAddress
toOUIPrefixBlock()
Returns an address in which the range of values match the block for the OUI (organizationally unique identifier)MACAddress
toPrefixBlock()
If this series has a prefix length, returns the block for that prefix.java.lang.String
toSpaceDelimitedString()
java.lang.String
toString()
long
upperLongValue()
MACAddress
withoutPrefixLength()
Provides the same address with no prefix.-
Methods inherited from class inet.ipaddr.Address
contains, containsPrefixBlock, containsSinglePrefixBlock, defaultIpv4Network, defaultIpv6Network, defaultMACNetwork, equals, getBlockCount, getBytes, getBytes, getBytes, getCount, getDivisionCount, getDivisionStrings, getMinPrefixLengthForBlock, getPrefixCount, getPrefixCount, getPrefixLength, getPrefixLengthForSingleBlock, getSegmentCount, getSegments, getSegments, getSegmentStrings, getUpperBytes, getUpperBytes, getUpperBytes, getUpperValue, getValue, hashCode, includesMax, includesZero, isFullRange, isMax, isMore, isMultiple, isPrefixBlock, isPrefixed, isSameAddress, isSequential, isSinglePrefixBlock, isZero, prefixEquals, toCanonicalString, toCompressedString, toHexString, toNormalizedString
-
Methods inherited from interface inet.ipaddr.format.AddressDivisionSeries
getSequentialBlockIndex
-
Methods inherited from interface inet.ipaddr.format.AddressItem
compareTo
-
Methods inherited from interface inet.ipaddr.AddressSegmentSeries
isOneBit, testBit
-
-
-
-
Field Detail
-
COLON_SEGMENT_SEPARATOR
public static final char COLON_SEGMENT_SEPARATOR
- See Also:
- Constant Field Values
-
DASH_SEGMENT_SEPARATOR
public static final char DASH_SEGMENT_SEPARATOR
- See Also:
- Constant Field Values
-
SPACE_SEGMENT_SEPARATOR
public static final char SPACE_SEGMENT_SEPARATOR
- See Also:
- Constant Field Values
-
DOTTED_SEGMENT_SEPARATOR
public static final char DOTTED_SEGMENT_SEPARATOR
- See Also:
- Constant Field Values
-
DASHED_SEGMENT_RANGE_SEPARATOR
public static final char DASHED_SEGMENT_RANGE_SEPARATOR
- See Also:
- Constant Field Values
-
DASHED_SEGMENT_RANGE_SEPARATOR_STR
public static final java.lang.String DASHED_SEGMENT_RANGE_SEPARATOR_STR
-
BITS_PER_SEGMENT
public static final int BITS_PER_SEGMENT
- See Also:
- Constant Field Values
-
BYTES_PER_SEGMENT
public static final int BYTES_PER_SEGMENT
- See Also:
- Constant Field Values
-
MEDIA_ACCESS_CONTROL_SEGMENT_COUNT
public static final int MEDIA_ACCESS_CONTROL_SEGMENT_COUNT
- See Also:
- Constant Field Values
-
MEDIA_ACCESS_CONTROL_BIT_COUNT
public static final int MEDIA_ACCESS_CONTROL_BIT_COUNT
- See Also:
- Constant Field Values
-
MEDIA_ACCESS_CONTROL_DOTTED_SEGMENT_COUNT
public static final int MEDIA_ACCESS_CONTROL_DOTTED_SEGMENT_COUNT
- See Also:
- Constant Field Values
-
MEDIA_ACCESS_CONTROL_DOTTED_64_SEGMENT_COUNT
public static final int MEDIA_ACCESS_CONTROL_DOTTED_64_SEGMENT_COUNT
- See Also:
- Constant Field Values
-
MEDIA_ACCESS_CONTROL_DOTTED_BITS_PER_SEGMENT
public static final int MEDIA_ACCESS_CONTROL_DOTTED_BITS_PER_SEGMENT
- See Also:
- Constant Field Values
-
MEDIA_ACCESS_CONTROL_SINGLE_DASHED_SEGMENT_COUNT
public static final int MEDIA_ACCESS_CONTROL_SINGLE_DASHED_SEGMENT_COUNT
- See Also:
- Constant Field Values
-
EXTENDED_UNIQUE_IDENTIFIER_48_SEGMENT_COUNT
public static final int EXTENDED_UNIQUE_IDENTIFIER_48_SEGMENT_COUNT
- See Also:
- Constant Field Values
-
EXTENDED_UNIQUE_IDENTIFIER_64_SEGMENT_COUNT
public static final int EXTENDED_UNIQUE_IDENTIFIER_64_SEGMENT_COUNT
- See Also:
- Constant Field Values
-
EXTENDED_UNIQUE_IDENTIFIER_48_BIT_COUNT
public static final int EXTENDED_UNIQUE_IDENTIFIER_48_BIT_COUNT
- See Also:
- Constant Field Values
-
EXTENDED_UNIQUE_IDENTIFIER_64_BIT_COUNT
public static final int EXTENDED_UNIQUE_IDENTIFIER_64_BIT_COUNT
- See Also:
- Constant Field Values
-
DEFAULT_TEXTUAL_RADIX
public static final int DEFAULT_TEXTUAL_RADIX
- See Also:
- Constant Field Values
-
MAX_VALUE_PER_SEGMENT
public static final int MAX_VALUE_PER_SEGMENT
- See Also:
- Constant Field Values
-
MAX_VALUE_PER_DOTTED_SEGMENT
public static final int MAX_VALUE_PER_DOTTED_SEGMENT
- See Also:
- Constant Field Values
-
ORGANIZATIONAL_UNIQUE_IDENTIFIER_SEGMENT_COUNT
public static final int ORGANIZATIONAL_UNIQUE_IDENTIFIER_SEGMENT_COUNT
- See Also:
- Constant Field Values
-
ORGANIZATIONAL_UNIQUE_IDENTIFIER_BIT_COUNT
public static final int ORGANIZATIONAL_UNIQUE_IDENTIFIER_BIT_COUNT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
MACAddress
public MACAddress(MACAddressSegment[] segments) throws AddressValueException
Constructs a MAC address.- Parameters:
segments
- the address segments- Throws:
AddressValueException
-
MACAddress
public MACAddress(MACAddressSection section) throws AddressValueException
Constructs a MAC address.- Parameters:
section
- the address segments- Throws:
AddressValueException
-
MACAddress
public MACAddress(long address) throws AddressValueException
Constructs a MAC address.- Throws:
AddressValueException
-
MACAddress
public MACAddress(java.net.NetworkInterface ni) throws java.net.SocketException
Constructs a MAC address for a network interface.- Throws:
java.net.SocketException
-
MACAddress
public MACAddress(long address, boolean extended) throws AddressValueException
Constructs a MAC address.- Throws:
AddressValueException
-
MACAddress
public MACAddress(byte[] bytes) throws AddressValueException
Constructs a MAC address.- Throws:
AddressValueException
-
MACAddress
public MACAddress(Address.SegmentValueProvider lowerValueProvider, Address.SegmentValueProvider upperValueProvider, boolean extended)
Constructs a MAC address- Parameters:
lowerValueProvider
- supplies the 1 byte lower values for each segmentupperValueProvider
- supplies the 1 byte upper values for each segment
-
MACAddress
public MACAddress(Address.SegmentValueProvider lowerValueProvider, Address.SegmentValueProvider upperValueProvider)
Constructs a MAC address- Parameters:
lowerValueProvider
- supplies the 1 byte lower values for each segmentupperValueProvider
- supplies the 1 byte upper values for each segment
-
MACAddress
public MACAddress(Address.SegmentValueProvider valueProvider, boolean extended) throws AddressValueException
Constructs a MAC address- Parameters:
valueProvider
- supplies the 1 byte value for each segment- Throws:
AddressValueException
-
MACAddress
public MACAddress(Address.SegmentValueProvider valueProvider)
Constructs a MAC address- Parameters:
valueProvider
- supplies the 1 byte value for each segment
-
-
Method Detail
-
getNetwork
public MACAddressNetwork getNetwork()
Description copied from interface:AddressComponent
Returns the network object for components of the same version (eg IPv4, IPv6 and MAC each have their own network object)- Specified by:
getNetwork
in interfaceAddressComponent
- Returns:
-
getIPv6Network
public IPv6AddressNetwork getIPv6Network()
-
getAddressCreator
public MACAddressNetwork.MACAddressCreator getAddressCreator()
-
isExtended
public boolean isExtended()
-
isAllAddresses
public boolean isAllAddresses()
-
getSection
public MACAddressSection getSection()
Description copied from interface:AddressSegmentSeries
Gets the subsection from the series that comprises all segments- Specified by:
getSection
in interfaceAddressSegmentSeries
- Overrides:
getSection
in classAddress
- Returns:
-
getDivision
public MACAddressSegment getDivision(int index)
- Specified by:
getDivision
in interfaceAddressDivisionSeries
- Specified by:
getDivision
in interfaceAddressStringDivisionSeries
- Returns:
- the given division in this series. The first is at index 0.
-
getSegment
public MACAddressSegment getSegment(int index)
Description copied from interface:AddressSegmentSeries
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.- Specified by:
getSegment
in interfaceAddressSegmentSeries
- Returns:
-
getSegments
public MACAddressSegment[] getSegments()
Description copied from interface:AddressSegmentSeries
Returns the segments of this series of segments as an array. This must create a new array, so for efficiency useAddressSegmentSeries.getSegment(int)
andAddressSegmentSeries.getSegmentCount()
instead when feasible.- Specified by:
getSegments
in interfaceAddressSegmentSeries
- Returns:
-
maxSegmentValue
public static int maxSegmentValue()
-
getMaxSegmentValue
public int getMaxSegmentValue()
Description copied from interface:AddressSegmentSeries
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.- Specified by:
getMaxSegmentValue
in interfaceAddressSegmentSeries
- Returns:
- the maximum possible segment value for a series of the same type
-
getByteCount
public int getByteCount()
Description copied from interface:AddressItem
Provides the number of bytes required for this address item, rounding up if the bit count is not a multiple of 8- Specified by:
getByteCount
in interfaceAddressItem
- Overrides:
getByteCount
in classAddress
- Returns:
- the number of bytes
-
getBitCount
public int getBitCount()
Description copied from interface:AddressItem
Provides the number of bits comprising this address item- Specified by:
getBitCount
in interfaceAddressDivisionSeries
- Specified by:
getBitCount
in interfaceAddressItem
- Overrides:
getBitCount
in classAddress
- Returns:
- the number of bits
-
getBytesPerSegment
public int getBytesPerSegment()
Description copied from interface:AddressSegmentSeries
Returns the number of bytes comprising each segment in this series. Segments in the same series are equal length.- Specified by:
getBytesPerSegment
in interfaceAddressSegmentSeries
- Returns:
-
getBitsPerSegment
public int getBitsPerSegment()
Description copied from interface:AddressSegmentSeries
Returns the number of bits comprising each segment in this series. Segments in the same series are equal length.- Specified by:
getBitsPerSegment
in interfaceAddressSegmentSeries
- Returns:
-
getIterable
public java.lang.Iterable<MACAddress> getIterable()
Description copied from interface:AddressComponentRange
Useful for using an instance in a "for-each loop". Otherwise just callAddressComponentRange.iterator()
directly.- Specified by:
getIterable
in interfaceAddressComponentRange
- Specified by:
getIterable
in interfaceAddressSegmentSeries
- Specified by:
getIterable
in classAddress
- Returns:
-
iterator
public java.util.Iterator<MACAddress> iterator()
Description copied from interface:AddressComponentRange
Iterates 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:
iterator
in interfaceAddressComponentRange
- Specified by:
iterator
in interfaceAddressSegmentSeries
- Specified by:
iterator
in interfacejava.lang.Iterable<MACAddress>
- Specified by:
iterator
in classAddress
- Returns:
-
spliterator
public AddressComponentSpliterator<MACAddress> spliterator()
Description copied from interface:AddressComponentRange
Partitions and traverses through the individual address components.- Specified by:
spliterator
in interfaceAddressComponent
- Specified by:
spliterator
in interfaceAddressComponentRange
- Specified by:
spliterator
in interfaceAddressSegmentSeries
- Specified by:
spliterator
in interfacejava.lang.Iterable<MACAddress>
- Specified by:
spliterator
in classAddress
- Returns:
-
stream
public java.util.stream.Stream<MACAddress> stream()
Description copied from interface:AddressComponentRange
Returns a sequential stream of the individual address components. For a parallel stream, callBaseStream.parallel()
on the returned stream.- Specified by:
stream
in interfaceAddressComponentRange
- Specified by:
stream
in interfaceAddressSegmentSeries
- Specified by:
stream
in classAddress
- Returns:
-
prefixBlockIterator
public java.util.Iterator<MACAddress> prefixBlockIterator()
Description copied from interface:AddressSegmentSeries
Iterates through the individual prefix blocks.If the series has no prefix length, then this is equivalent to
AddressSegmentSeries.iterator()
- Specified by:
prefixBlockIterator
in interfaceAddressSegmentSeries
- Specified by:
prefixBlockIterator
in classAddress
-
prefixBlockSpliterator
public AddressComponentSpliterator<MACAddress> prefixBlockSpliterator()
Description copied from interface:AddressSegmentSeries
Partitions and traverses through the individual prefix blocks for the prefix length of this series.- Specified by:
prefixBlockSpliterator
in interfaceAddressSegmentSeries
- Specified by:
prefixBlockSpliterator
in classAddress
- Returns:
-
prefixBlockStream
public java.util.stream.Stream<MACAddress> prefixBlockStream()
Description copied from interface:AddressSegmentSeries
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.- Specified by:
prefixBlockStream
in interfaceAddressSegmentSeries
- Specified by:
prefixBlockStream
in classAddress
- Returns:
-
prefixIterator
public java.util.Iterator<MACAddress> prefixIterator()
Description copied from interface:AddressSegmentSeries
Iterates through the individual prefixes.If the series has no prefix length, then this is equivalent to
AddressSegmentSeries.iterator()
- Specified by:
prefixIterator
in interfaceAddressSegmentSeries
- Specified by:
prefixIterator
in classAddress
-
prefixSpliterator
public AddressComponentSpliterator<MACAddress> prefixSpliterator()
Description copied from interface:AddressSegmentSeries
Partitions and traverses through the individual prefixes for the prefix length of this series.- Specified by:
prefixSpliterator
in interfaceAddressSegmentSeries
- Specified by:
prefixSpliterator
in classAddress
- Returns:
-
prefixStream
public java.util.stream.Stream<MACAddress> prefixStream()
Description copied from interface:AddressSegmentSeries
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.- Specified by:
prefixStream
in interfaceAddressSegmentSeries
- Specified by:
prefixStream
in classAddress
- Returns:
-
segmentsIterator
public java.util.Iterator<MACAddressSegment[]> segmentsIterator()
Description copied from interface:AddressSegmentSeries
Iterates through the individual segments.- Specified by:
segmentsIterator
in interfaceAddressSegmentSeries
-
segmentsSpliterator
public AddressComponentRangeSpliterator<MACAddress,MACAddressSegment[]> segmentsSpliterator()
Description copied from interface:AddressSegmentSeries
Partitions and traverses through the individual segment arrays.- Specified by:
segmentsSpliterator
in interfaceAddressSegmentSeries
- Returns:
-
segmentsStream
public java.util.stream.Stream<MACAddressSegment[]> segmentsStream()
Description copied from interface:AddressSegmentSeries
Returns a sequential stream of the individual segment arrays. For a parallel stream, callBaseStream.parallel()
on the returned stream.- Specified by:
segmentsStream
in interfaceAddressSegmentSeries
- Returns:
-
increment
public MACAddress increment(long increment)
Description copied from interface:AddressSegmentSeries
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
AddressSegmentSeries.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.
- Specified by:
increment
in interfaceAddressSegmentSeries
- Specified by:
increment
in classAddress
- Returns:
-
incrementBoundary
public MACAddress incrementBoundary(long increment)
Description copied from interface:AddressSegmentSeries
If the given increment is positive, adds the value to the upper series (AddressSegmentSeries.getUpper()
) in the subnet range to produce a new series. If the given increment is negative, adds the value to the lower series (AddressSegmentSeries.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.
- Specified by:
incrementBoundary
in interfaceAddressSegmentSeries
- Specified by:
incrementBoundary
in classAddress
- Returns:
-
getLower
public MACAddress getLower()
Description copied from interface:AddressSegmentSeries
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:
getLower
in interfaceAddressComponentRange
- Specified by:
getLower
in interfaceAddressSegmentSeries
- Specified by:
getLower
in classAddress
- Returns:
-
getUpper
public MACAddress getUpper()
Description copied from interface:AddressSegmentSeries
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:
getUpper
in interfaceAddressComponentRange
- Specified by:
getUpper
in interfaceAddressSegmentSeries
- Specified by:
getUpper
in classAddress
- Returns:
-
longValue
public long longValue()
-
upperLongValue
public long upperLongValue()
-
reverseBits
public MACAddress reverseBits(boolean perByte)
Use to produce: "MSB format", "IBM format", "Token-Ring format", and "non-canonical form" See RFC 2469 section 2 Also see https://en.wikipedia.org/wiki/MAC_address- Specified by:
reverseBits
in interfaceAddressComponent
- Specified by:
reverseBits
in interfaceAddressSegmentSeries
- Specified by:
reverseBits
in classAddress
- Parameters:
perByte
- if true, only the bits in each byte are reversed, if false, then all bits in the component are reversed- Returns:
-
reverseBytes
public MACAddress reverseBytes()
Description copied from interface:AddressSegmentSeries
Returns a new segment series with the bytes reversed.- Specified by:
reverseBytes
in interfaceAddressComponent
- Specified by:
reverseBytes
in interfaceAddressSegmentSeries
- Specified by:
reverseBytes
in classAddress
- Returns:
-
reverseBytesPerSegment
public MACAddress reverseBytesPerSegment()
Description copied from interface:AddressSegmentSeries
Returns a new segment series with the bytes reversed within each segment.- Specified by:
reverseBytesPerSegment
in interfaceAddressSegmentSeries
- Specified by:
reverseBytesPerSegment
in classAddress
- Returns:
-
reverseSegments
public MACAddress reverseSegments()
Description copied from interface:AddressSegmentSeries
Returns a new segment series with the segments reversed. This does not throwIncompatibleAddressException
since all address series can reverse their segments.- Specified by:
reverseSegments
in interfaceAddressSegmentSeries
- Specified by:
reverseSegments
in classAddress
- Returns:
-
removePrefixLength
@Deprecated public MACAddress removePrefixLength()
Deprecated.Description copied from interface:AddressSegmentSeries
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
AddressSegmentSeries.withoutPrefixLength()
to remove the prefix length without changing the series values.Equivalent to calling removePrefixLength(true)
- Specified by:
removePrefixLength
in interfaceAddressSegmentSeries
- Specified by:
removePrefixLength
in classAddress
- Returns:
- See Also:
for an alternative which does not change the address series values.
-
withoutPrefixLength
public MACAddress withoutPrefixLength()
Description copied from interface:AddressSegmentSeries
Provides the same address with no prefix. The values remain unchanged.Use
AddressSegmentSeries.removePrefixLength()
as an alternative that deletes the host at the same time by zeroing the host values.- Specified by:
withoutPrefixLength
in interfaceAddressSegmentSeries
- Specified by:
withoutPrefixLength
in classAddress
-
removePrefixLength
@Deprecated public MACAddress removePrefixLength(boolean zeroed)
Deprecated.Description copied from interface:AddressSegmentSeries
Removes the prefix length. If zeroed is false, the bits that were host bits do not become zero, unlikeAddressSegmentSeries.removePrefixLength()
- Specified by:
removePrefixLength
in interfaceAddressSegmentSeries
- Specified by:
removePrefixLength
in classAddress
- Parameters:
zeroed
- whether the bits outside the prefix become zero- Returns:
-
applyPrefixLength
@Deprecated public MACAddress applyPrefixLength(int prefixLength)
Deprecated.Description copied from interface:AddressSegmentSeries
Applies the given prefix length to create a new segment series.Similar to
AddressSegmentSeries.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.
- Specified by:
applyPrefixLength
in interfaceAddressSegmentSeries
- Specified by:
applyPrefixLength
in classAddress
- Returns:
- See Also:
AddressSegmentSeries.setPrefixLength(int)
-
adjustPrefixBySegment
public MACAddress adjustPrefixBySegment(boolean nextSegment)
Description copied from interface:AddressSegmentSeries
Increases or decreases prefix length to the next segment boundary.Follows the same rules as
AddressSegmentSeries.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, useAddressSegmentSeries.adjustPrefixBySegment(boolean, boolean)
with second arg false.- Specified by:
adjustPrefixBySegment
in interfaceAddressSegmentSeries
- Specified by:
adjustPrefixBySegment
in classAddress
- Parameters:
nextSegment
- whether to move prefix to previous or following segment boundary- Returns:
-
adjustPrefixBySegment
public MACAddress adjustPrefixBySegment(boolean nextSegment, boolean zeroed)
Description copied from interface:AddressSegmentSeries
Increases or decreases prefix length to the next segment boundary.- Specified by:
adjustPrefixBySegment
in interfaceAddressSegmentSeries
- Specified by:
adjustPrefixBySegment
in classAddress
- 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
public MACAddress adjustPrefixLength(int adjustment)
Description copied from interface:AddressSegmentSeries
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
AddressSegmentSeries.adjustPrefixLength(int, boolean)
with second arg false.- Specified by:
adjustPrefixLength
in interfaceAddressSegmentSeries
- Specified by:
adjustPrefixLength
in classAddress
- Returns:
-
adjustPrefixLength
public MACAddress adjustPrefixLength(int adjustment, boolean zeroed)
Description copied from interface:AddressSegmentSeries
Increases or decreases prefix length by the given increment.- Specified by:
adjustPrefixLength
in interfaceAddressSegmentSeries
- Specified by:
adjustPrefixLength
in classAddress
- Parameters:
adjustment
- the incrementzeroed
- whether the bits that move from one side of the prefix to the other become zero or retain their original values- Returns:
-
setPrefixLength
public MACAddress setPrefixLength(int prefixLength)
Description copied from interface:AddressSegmentSeries
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
AddressSegmentSeries.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.
- Specified by:
setPrefixLength
in interfaceAddressSegmentSeries
- Specified by:
setPrefixLength
in classAddress
- Returns:
-
setPrefixLength
public MACAddress setPrefixLength(int prefixLength, boolean zeroed)
Description copied from interface:AddressSegmentSeries
Sets the prefix length.When the prefix is extended beyond the segment series boundary, it is removed.
- Specified by:
setPrefixLength
in interfaceAddressSegmentSeries
- Specified by:
setPrefixLength
in classAddress
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:
-
getSection
public MACAddressSection getSection(int index)
Description copied from interface:AddressSegmentSeries
Gets the subsection from the series starting from the given index The first segment is at index 0.- Specified by:
getSection
in interfaceAddressSegmentSeries
- Returns:
-
getSection
public MACAddressSection getSection(int index, int endIndex)
Description copied from interface:AddressSegmentSeries
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.- Specified by:
getSection
in interfaceAddressSegmentSeries
- Returns:
-
getODISection
public MACAddressSection getODISection()
-
getOUISection
public MACAddressSection getOUISection()
-
toOUIPrefixBlock
public MACAddress toOUIPrefixBlock()
Returns an address in which the range of values match the block for the OUI (organizationally unique identifier)- Returns:
-
toPrefixBlock
public MACAddress toPrefixBlock()
Description copied from interface:AddressSegmentSeries
If this series has a prefix length, returns the block for that prefix. Otherwise, this address series is returned.- Specified by:
toPrefixBlock
in interfaceAddressSegmentSeries
- Specified by:
toPrefixBlock
in classAddress
- Returns:
- the block of address series for the prefix length
-
toLinkLocalIPv6
public IPv6Address toLinkLocalIPv6()
Converts to a link-local Ipv6 address. Any MAC prefix length is ignored. Other elements of this address section are incorporated into the conversion. This will provide the latter 4 segments of an IPv6 address, to be paired with the link-local IPv6 prefix of 4 segments.- Returns:
-
toEUI64IPv6
public IPv6AddressSection toEUI64IPv6()
Converts to an Ipv6 address section. Any MAC prefix length is ignored. Other elements of this address section are incorporated into the conversion. This will provide the latter 4 segments of an IPv6 address, to be paired with an IPv6 prefix of 4 segments.- Returns:
-
isEUI64
public boolean isEUI64(boolean asMAC)
Whether this section is consistent with an IPv6 EUI64 section, which means it came from an extended 8 byte address, and the corresponding segments in the middle match 0xff and 0xff/fe for MAC/not-MAC- Parameters:
asMAC
-- Returns:
-
toEUI64
public MACAddress toEUI64(boolean asMAC)
Convert to IPv6 EUI-64 section http://standards.ieee.org/develop/regauth/tut/eui64.pdf- Parameters:
asMAC
- if true, this address is considered MAC and the EUI-64 is extended using ff-ff, otherwise this address is considered EUI-48 and extended using ff-fe Note that IPv6 treats MAC as EUI-48 and extends MAC to IPv6 addresses using ff-fe- Returns:
-
replace
public MACAddress replace(int startIndex, int endIndex, MACAddress replacement, int replacementIndex)
Replaces segments starting from startIndex and ending before endIndex with the same number of segments starting at replacementStartIndex from the replacement section- Parameters:
startIndex
-endIndex
-replacement
-replacementIndex
-- Returns:
- Throws:
java.lang.IndexOutOfBoundsException
-
getDottedAddress
public AddressDivisionGrouping getDottedAddress()
-
toAddressString
public MACAddressString toAddressString()
Description copied from class:Address
Returns a host identifier string representation for this address, which will be already validated.- Overrides:
toAddressString
in classAddress
- Returns:
-
toNormalizedString
public java.lang.String toNormalizedString(AddressDivisionGrouping.StringOptions stringOptions)
-
toDottedString
public java.lang.String toDottedString() throws IncompatibleAddressException
- Throws:
IncompatibleAddressException
-
toDashedString
public java.lang.String toDashedString()
-
toColonDelimitedString
public java.lang.String toColonDelimitedString()
-
toSpaceDelimitedString
public java.lang.String toSpaceDelimitedString()
-
isUnicast
public boolean isUnicast()
-
isMulticast
public boolean isMulticast()
Multicast MAC addresses have the least significant bit of the first octet set to 1.- Specified by:
isMulticast
in classAddress
- See Also:
InetAddress.isMulticastAddress()
-
isUniversal
public boolean isUniversal()
Universal MAC addresses have second the least significant bit of the first octet set to 0.
-
-