All Downloads are FREE. Search and download functionalities are using the official Maven repository.

inet.ipaddr.mac.MACAddressAssociativeTrie Maven / Gradle / Ivy

There is a newer version: 5.5.1
Show newest version
/*
 * Copyright 2020 Sean C Foley
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *     or at
 *     https://github.com/seancfoley/IPAddress/blob/master/LICENSE
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package inet.ipaddr.mac;

import java.util.Iterator;
import java.util.Spliterator;
import java.util.function.Function;
import java.util.function.Supplier;

import inet.ipaddr.format.util.AssociativeAddedTree;
import inet.ipaddr.format.util.AssociativeAddressTrie;
import inet.ipaddr.format.util.BinaryTreeNode;
import inet.ipaddr.format.util.BinaryTreeNode.CachingIterator;

/**
 * A MAC address trie in which each node can be associated with a value.
 * 
 * See {@link AssociativeAddressTrie} for more details.
 * 
 * @author scfoley
 * 
 * @param  the type of the associated values
 *
 */
public class MACAddressAssociativeTrie extends AssociativeAddressTrie {

	private static final long serialVersionUID = 1L;

	private static final MACAddress INIT_ROOT = MACAddressTrie.INIT_ROOT;
	private static final MACAddress INIT_ROOT_EXTENDED = MACAddressTrie.INIT_ROOT_EXTENDED;

	public MACAddressAssociativeTrie() {
		super(new MACAssociativeTrieNode());
	}

	protected MACAddressAssociativeTrie(AddressBounds bounds) {
		super(new MACAssociativeTrieNode(), bounds);
	}

	protected MACAddressAssociativeTrie(MACAssociativeTrieNode root, AddressBounds bounds) {
		super(root, bounds);
	}

	// if the very first address inserted into the trie is 64-bit, the trie is 64 bit
	@Override
	protected void adjustRoot(MACAddress addr) {
		if(isEmpty() && addr.getSegmentCount() == MACAddress.EXTENDED_UNIQUE_IDENTIFIER_64_SEGMENT_COUNT) {
			absoluteRoot().setExtendedRootKey();
		}
	}

	@Override
	public MACAssociativeTrieNode getRoot() {
		return (MACAssociativeTrieNode) super.getRoot();
	}

	@Override
	protected MACAssociativeTrieNode absoluteRoot() {
		return (MACAssociativeTrieNode) super.absoluteRoot();
	}

	@Override
	protected MACAddressAssociativeTrie createNew(AddressBounds bounds) {
		return new MACAddressAssociativeTrie(bounds);
	}

	@Override
	protected MACAddressAssociativeTrie createSubTrie(AddressBounds bounds) {
		return new MACAddressAssociativeTrie(absoluteRoot(), bounds);
	}

	public static class MACAssociativeTrieNode extends AssociativeTrieNode {

		private static final long serialVersionUID = 1L;

		protected MACAssociativeTrieNode(MACAddress addr) {
			super(addr);
		}

		public MACAssociativeTrieNode() { // root node
			super(INIT_ROOT);
		}

		@Override
		protected void replaceThisRoot(BinaryTreeNode replacement) {
			super.replaceThisRoot(replacement);
			if(!FREEZE_ROOT && replacement == null) {
				setKey(INIT_ROOT);
			}
		}

		void setExtendedRootKey() {
			setKey(INIT_ROOT_EXTENDED);
		}

		@Override
		public MACAssociativeTrieNode getUpperSubNode() {
			return (MACAssociativeTrieNode) super.getUpperSubNode();
		}

		@Override
		public MACAssociativeTrieNode getLowerSubNode() {
			return (MACAssociativeTrieNode) super.getLowerSubNode();
		}

		@Override
		public MACAssociativeTrieNode getParent() {
			return (MACAssociativeTrieNode) super.getParent();
		}

		@Override
		protected MACAssociativeTrieNode createNewImpl(MACAddress addr) {
			return new MACAssociativeTrieNode(addr);
		}

		@Override
		public MACAssociativeTrieNode removeElementsContainedBy(MACAddress addr) {
			return (MACAssociativeTrieNode) super.removeElementsContainedBy(addr);
		}

		@Override
		public MACAssociativeTrieNode elementsContainedBy(MACAddress addr) {
			return (MACAssociativeTrieNode) super.elementsContainedBy(addr);
		}

		@Override
		public MACAssociativeTrieNode elementsContaining(MACAddress addr) {
			return (MACAssociativeTrieNode) super.elementsContaining(addr);
		}

		@Override
		public MACAssociativeTrieNode longestPrefixMatchNode(MACAddress addr) {
			return (MACAssociativeTrieNode) super.longestPrefixMatchNode(addr);
		}

		@Override
		public MACAssociativeTrieNode getAddedNode(MACAddress addr) {
			return (MACAssociativeTrieNode) super.getAddedNode(addr);
		}

		@Override
		public MACAssociativeTrieNode getNode(MACAddress addr) {
			return (MACAssociativeTrieNode) super.getNode(addr);
		}

		@SuppressWarnings("unchecked")
		@Override
		public Iterator> nodeIterator(boolean forward) {
			return (Iterator>) super.nodeIterator(forward);
		}

		@SuppressWarnings("unchecked")
		@Override
		public Iterator> allNodeIterator(boolean forward) {
			return (Iterator>) super.allNodeIterator(forward);
		}

		@SuppressWarnings("unchecked")
		@Override
		public Iterator> blockSizeNodeIterator(boolean lowerSubNodeFirst) {
			return (Iterator>) super.blockSizeNodeIterator(lowerSubNodeFirst);
		}

		@SuppressWarnings("unchecked")
		@Override
		public Iterator> blockSizeAllNodeIterator(boolean lowerSubNodeFirst) {
			return (Iterator>) super.blockSizeAllNodeIterator(lowerSubNodeFirst);
		}

		@SuppressWarnings("unchecked")
		@Override
		public  CachingIterator, MACAddress, C> blockSizeCachingAllNodeIterator() {
			return (CachingIterator, MACAddress, C>) super.blockSizeCachingAllNodeIterator();
		}

		@SuppressWarnings("unchecked")
		@Override
		public  CachingIterator, MACAddress, C> containingFirstIterator(boolean forwardSubNodeOrder) {
			return (CachingIterator, MACAddress, C>) super.containingFirstIterator(forwardSubNodeOrder);
		}

		@SuppressWarnings("unchecked")
		@Override
		public  CachingIterator, MACAddress, C> containingFirstAllNodeIterator(boolean forwardSubNodeOrder) {
			return (CachingIterator, MACAddress, C>) super.containingFirstAllNodeIterator(forwardSubNodeOrder);
		}

		@SuppressWarnings("unchecked")
		@Override
		public Iterator> containedFirstIterator(boolean forwardSubNodeOrder) {
			return (Iterator>) super.containedFirstIterator(forwardSubNodeOrder);
		}

		@SuppressWarnings("unchecked")
		@Override
		public Iterator> containedFirstAllNodeIterator(boolean forwardSubNodeOrder) {
			return (Iterator>) super.containedFirstAllNodeIterator(forwardSubNodeOrder);
		}

		@SuppressWarnings("unchecked")
		@Override
		public Spliterator> nodeSpliterator(boolean forward) {
			return (Spliterator>) super.nodeSpliterator(forward);
		}

		@SuppressWarnings("unchecked")
		@Override
		public Spliterator> allNodeSpliterator(boolean forward) {
			return (Spliterator>) super.allNodeSpliterator(forward);
		}

		@Override
		public MACAssociativeTrieNode previousAddedNode() {
			return (MACAssociativeTrieNode) super.previousAddedNode();
		}

		@Override
		public MACAssociativeTrieNode nextAddedNode() {
			return (MACAssociativeTrieNode) super.nextAddedNode();
		}

		@Override
		public MACAssociativeTrieNode nextNode() {
			return (MACAssociativeTrieNode) super.nextNode();
		}

		@Override
		public MACAssociativeTrieNode previousNode() {
			return (MACAssociativeTrieNode) super.previousNode();
		}

		@Override
		public MACAssociativeTrieNode lowerAddedNode(MACAddress addr) {
			return (MACAssociativeTrieNode) super.lowerAddedNode(addr);
		}

		@Override
		public MACAssociativeTrieNode floorAddedNode(MACAddress addr) {
			return (MACAssociativeTrieNode) super.floorAddedNode(addr);
		}

		@Override
		public MACAssociativeTrieNode higherAddedNode(MACAddress addr) {
			return (MACAssociativeTrieNode) super.higherAddedNode(addr);
		}

		@Override
		public MACAssociativeTrieNode ceilingAddedNode(MACAddress addr) {
			return (MACAssociativeTrieNode) super.ceilingAddedNode(addr);
		}

		@Override
		public MACAssociativeTrieNode firstNode() {
			return (MACAssociativeTrieNode) super.firstNode();
		}

		@Override
		public MACAssociativeTrieNode lastNode() {
			return (MACAssociativeTrieNode) super.lastNode();
		}

		@Override
		public MACAssociativeTrieNode firstAddedNode() {
			return (MACAssociativeTrieNode) super.firstAddedNode();
		}

		@Override
		public MACAssociativeTrieNode lastAddedNode() {
			return (MACAssociativeTrieNode) super.lastAddedNode();
		}
		
		@Override
		protected MACAddressAssociativeTrie createNewTree() {
			return new MACAddressAssociativeTrie();
		}

		@Override
		public MACAddressAssociativeTrie asNewTrie() {
			return (MACAddressAssociativeTrie) super.asNewTrie();
		}
		
		@Override
		public MACAssociativeTrieNode cloneTree() {
			return (MACAssociativeTrieNode) super.cloneTree();
		}

		@Override
		public MACAssociativeTrieNode clone() {
			return (MACAssociativeTrieNode) super.clone();
		}

		@Override
		public boolean equals(Object o) {
			return o instanceof MACAddressAssociativeTrie.MACAssociativeTrieNode && super.equals(o);
		}
	}

	@Override
	public MACAssociativeTrieNode removeElementsContainedBy(MACAddress addr) {
		return (MACAssociativeTrieNode) super.removeElementsContainedBy(addr);
	}

	@Override
	public MACAssociativeTrieNode elementsContainedBy(MACAddress addr) {
		return (MACAssociativeTrieNode) super.elementsContainedBy(addr);
	}

	@Override
	public MACAssociativeTrieNode elementsContaining(MACAddress addr) {
		return (MACAssociativeTrieNode) super.elementsContaining(addr);
	}

	@Override
	public MACAssociativeTrieNode longestPrefixMatchNode(MACAddress addr) {
		return (MACAssociativeTrieNode) super.longestPrefixMatchNode(addr);
	}

	@Override
	public MACAssociativeTrieNode getAddedNode(MACAddress addr) {
		return (MACAssociativeTrieNode) super.getAddedNode(addr);
	}

	@Override
	public MACAssociativeTrieNode getNode(MACAddress addr) {
		return (MACAssociativeTrieNode) super.getNode(addr);
	}

	@Override
	public MACAssociativeTrieNode addNode(MACAddress addr) {
		return (MACAssociativeTrieNode) super.addNode(addr);
	}

	@SuppressWarnings("unchecked")
	@Override
	public MACAssociativeTrieNode addTrie(TrieNode trie) {
		return (MACAssociativeTrieNode) super.addTrie(trie);
	}

	@SuppressWarnings("unchecked")
	@Override
	public Iterator> nodeIterator(boolean forward) {
		return (Iterator>) super.nodeIterator(forward);
	}

	@SuppressWarnings("unchecked")
	@Override
	public Iterator> allNodeIterator(boolean forward) {
		return (Iterator>) super.allNodeIterator(forward);
	}

	@SuppressWarnings("unchecked")
	@Override
	public Iterator> blockSizeNodeIterator(boolean lowerSubNodeFirst) {
		return (Iterator>) super.blockSizeNodeIterator(lowerSubNodeFirst);
	}

	@SuppressWarnings("unchecked")
	@Override
	public Iterator> blockSizeAllNodeIterator(boolean lowerSubNodeFirst) {
		return (Iterator>) super.blockSizeAllNodeIterator(lowerSubNodeFirst);
	}

	@SuppressWarnings("unchecked")
	@Override
	public  CachingIterator, MACAddress, C> blockSizeCachingAllNodeIterator() {
		return (CachingIterator, MACAddress, C>) super.blockSizeCachingAllNodeIterator();
	}

	@SuppressWarnings("unchecked")
	@Override
	public  CachingIterator, MACAddress, C> containingFirstIterator(boolean forwardSubNodeOrder) {
		return (CachingIterator, MACAddress, C>) super.containingFirstIterator(forwardSubNodeOrder);
	}

	@SuppressWarnings("unchecked")
	@Override
	public  CachingIterator, MACAddress, C> containingFirstAllNodeIterator(boolean forwardSubNodeOrder) {
		return (CachingIterator, MACAddress, C>) super.containingFirstAllNodeIterator(forwardSubNodeOrder);
	}

	@SuppressWarnings("unchecked")
	@Override
	public Iterator> containedFirstIterator(boolean forwardSubNodeOrder) {
		return (Iterator>) super.containedFirstIterator(forwardSubNodeOrder);
	}

	@SuppressWarnings("unchecked")
	@Override
	public Iterator> containedFirstAllNodeIterator(boolean forwardSubNodeOrder) {
		return (Iterator>) super.containedFirstAllNodeIterator(forwardSubNodeOrder);
	}

	@SuppressWarnings("unchecked")
	@Override
	public Spliterator> nodeSpliterator(boolean forward) {
		return (Spliterator>) super.nodeSpliterator(forward);
	}

	@SuppressWarnings("unchecked")
	@Override
	public Spliterator> allNodeSpliterator(boolean forward) {
		return (Spliterator>) super.allNodeSpliterator(forward);
	}

	@Override
	public MACAssociativeTrieNode lowerAddedNode(MACAddress addr) {
		return (MACAssociativeTrieNode) super.lowerAddedNode(addr);
	}

	@Override
	public MACAssociativeTrieNode floorAddedNode(MACAddress addr) {
		return (MACAssociativeTrieNode) super.floorAddedNode(addr);
	}

	@Override
	public MACAssociativeTrieNode higherAddedNode(MACAddress addr) {
		return (MACAssociativeTrieNode) super.higherAddedNode(addr);
	}

	@Override
	public MACAssociativeTrieNode ceilingAddedNode(MACAddress addr) {
		return (MACAssociativeTrieNode) super.ceilingAddedNode(addr);
	}

	@Override
	public MACAssociativeTrieNode firstNode() {
		return (MACAssociativeTrieNode) super.firstNode();
	}

	@Override
	public MACAssociativeTrieNode lastNode() {
		return (MACAssociativeTrieNode) super.lastNode();
	}

	@Override
	public MACAssociativeTrieNode firstAddedNode() {
		return (MACAssociativeTrieNode) super.firstAddedNode();
	}

	@Override
	public MACAssociativeTrieNode lastAddedNode() {
		return (MACAssociativeTrieNode) super.lastAddedNode();
	}

	@Override
	public MACAssociativeTrieNode putNode(MACAddress addr, V value) {
		return (MACAssociativeTrieNode) super.putNode(addr, value);
	}

	@Override
	public MACAssociativeTrieNode putTrie(AssociativeTrieNode trie) {
		return (MACAssociativeTrieNode) super.putTrie(trie);
	}

	@Override
	public MACAssociativeTrieNode remap(MACAddress addr, Function remapper) {
		return (MACAssociativeTrieNode) super.remap(addr, remapper);
	}

	@Override
	public MACAssociativeTrieNode remapIfAbsent(MACAddress addr, Supplier remapper, boolean insertNull) {
		return (MACAssociativeTrieNode) super.remapIfAbsent(addr, remapper, insertNull);
	}

	@Override
	public boolean equals(Object o) {
		return o instanceof MACAddressAssociativeTrie && super.equals(o);
	}

	@Override
	public MACAddressAssociativeTrie clone() {
		return (MACAddressAssociativeTrie) super.clone();
	}

	@Override
	public AssociativeAddedTree constructAddedNodesTree() {
		MACAddressAssociativeTrie> trie = new MACAddressAssociativeTrie>();
		contructAssociativeAddedTree(trie);
		return new AssociativeAddedTree(trie);
	}

	@Override
	public String toAddedNodesTreeString() {
		MACAddressAssociativeTrie> trie = new MACAddressAssociativeTrie>();
		contructAssociativeAddedTree(trie);
		return toAddedNodesTreeString(trie);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy