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

inet.ipaddr.ipv4.IPv4AddressAssociativeTrie 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.ipv4;

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;

/**
 * An IPv4 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 IPv4AddressAssociativeTrie extends AssociativeAddressTrie {

	private static final long serialVersionUID = 1L;

	private static final IPv4Address INIT_ROOT = IPv4AddressTrie.INIT_ROOT;

	public IPv4AddressAssociativeTrie() {
		super(new IPv4AssociativeTrieNode());
	}

	protected IPv4AddressAssociativeTrie(AddressBounds bounds) {
		super(new IPv4AssociativeTrieNode(), bounds);
	}

	protected IPv4AddressAssociativeTrie(IPv4AssociativeTrieNode root, AddressBounds bounds) {
		super(root, bounds);
	}

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

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

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

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

	public static class IPv4AssociativeTrieNode extends AssociativeTrieNode {

		private static final long serialVersionUID = 1L;

		protected IPv4AssociativeTrieNode(IPv4Address addr) {
			super(addr);
		}

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

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

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

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

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

		@Override
		protected IPv4AssociativeTrieNode createNewImpl(IPv4Address addr) {
			return new IPv4AssociativeTrieNode(addr);
		}

		@Override
		public IPv4AssociativeTrieNode removeElementsContainedBy(IPv4Address addr) {
			return (IPv4AssociativeTrieNode) super.removeElementsContainedBy(addr);
		}

		@Override
		public IPv4AssociativeTrieNode elementsContainedBy(IPv4Address addr) {
			return (IPv4AssociativeTrieNode) super.elementsContainedBy(addr);
		}

		@Override
		public IPv4AssociativeTrieNode elementsContaining(IPv4Address addr) {
			return (IPv4AssociativeTrieNode) super.elementsContaining(addr);
		}
		
		@Override
		public IPv4AssociativeTrieNode longestPrefixMatchNode(IPv4Address addr) {
			return (IPv4AssociativeTrieNode) super.longestPrefixMatchNode(addr);
		}

		@Override
		public IPv4AssociativeTrieNode getAddedNode(IPv4Address addr) {
			return (IPv4AssociativeTrieNode) super.getAddedNode(addr);
		}

		@Override
		public IPv4AssociativeTrieNode getNode(IPv4Address addr) {
			return (IPv4AssociativeTrieNode) 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, IPv4Address, C> blockSizeCachingAllNodeIterator() {
			return (CachingIterator, IPv4Address, C>) super.blockSizeCachingAllNodeIterator();
		}

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

		@SuppressWarnings("unchecked")
		@Override
		public  CachingIterator, IPv4Address, C> containingFirstAllNodeIterator(boolean forwardSubNodeOrder) {
			return (CachingIterator, IPv4Address, 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 IPv4AssociativeTrieNode previousAddedNode() {
			return (IPv4AssociativeTrieNode) super.previousAddedNode();
		}

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

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

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

		@Override
		public IPv4AssociativeTrieNode lowerAddedNode(IPv4Address addr) {
			return (IPv4AssociativeTrieNode) super.lowerAddedNode(addr);
		}

		@Override
		public IPv4AssociativeTrieNode floorAddedNode(IPv4Address addr) {
			return (IPv4AssociativeTrieNode) super.floorAddedNode(addr);
		}

		@Override
		public IPv4AssociativeTrieNode higherAddedNode(IPv4Address addr) {
			return (IPv4AssociativeTrieNode) super.higherAddedNode(addr);
		}

		@Override
		public IPv4AssociativeTrieNode ceilingAddedNode(IPv4Address addr) {
			return (IPv4AssociativeTrieNode) super.ceilingAddedNode(addr);
		}

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

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

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

		@Override
		public IPv4AssociativeTrieNode lastAddedNode() {
			return (IPv4AssociativeTrieNode) super.lastAddedNode();
		}
		
		@Override
		protected IPv4AddressAssociativeTrie createNewTree() {
			return new IPv4AddressAssociativeTrie();
		}
		
		@Override
		public IPv4AddressAssociativeTrie asNewTrie() {
			return (IPv4AddressAssociativeTrie) super.asNewTrie();
		}

		@Override
		public IPv4AssociativeTrieNode cloneTree() {
			return (IPv4AssociativeTrieNode) super.cloneTree();
		}

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

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

	@Override
	public IPv4AssociativeTrieNode removeElementsContainedBy(IPv4Address addr) {
		return (IPv4AssociativeTrieNode) super.removeElementsContainedBy(addr);
	}

	@Override
	public IPv4AssociativeTrieNode elementsContainedBy(IPv4Address addr) {
		return (IPv4AssociativeTrieNode) super.elementsContainedBy(addr);
	}

	@Override
	public IPv4AssociativeTrieNode elementsContaining(IPv4Address addr) {
		return (IPv4AssociativeTrieNode) super.elementsContaining(addr);
	}

	@Override
	public IPv4AssociativeTrieNode longestPrefixMatchNode(IPv4Address addr) {
		return (IPv4AssociativeTrieNode) super.longestPrefixMatchNode(addr);
	}

	@Override
	public IPv4AssociativeTrieNode getAddedNode(IPv4Address addr) {
		return (IPv4AssociativeTrieNode) super.getAddedNode(addr);
	}

	@Override
	public IPv4AssociativeTrieNode getNode(IPv4Address addr) {
		return (IPv4AssociativeTrieNode) super.getNode(addr);
	}

	@Override
	public IPv4AssociativeTrieNode addNode(IPv4Address addr) {
		return (IPv4AssociativeTrieNode) super.addNode(addr);
	}

	@SuppressWarnings("unchecked")
	@Override
	public IPv4AssociativeTrieNode addTrie(TrieNode trie) {
		return (IPv4AssociativeTrieNode) 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, IPv4Address, C> blockSizeCachingAllNodeIterator() {
		return (CachingIterator, IPv4Address, C>) super.blockSizeCachingAllNodeIterator();
	}

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

	@SuppressWarnings("unchecked")
	@Override
	public  CachingIterator, IPv4Address, C> containingFirstAllNodeIterator(boolean forwardSubNodeOrder) {
		return (CachingIterator, IPv4Address, 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 IPv4AssociativeTrieNode lowerAddedNode(IPv4Address addr) {
		return (IPv4AssociativeTrieNode) super.lowerAddedNode(addr);
	}

	@Override
	public IPv4AssociativeTrieNode floorAddedNode(IPv4Address addr) {
		return (IPv4AssociativeTrieNode) super.floorAddedNode(addr);
	}

	@Override
	public IPv4AssociativeTrieNode higherAddedNode(IPv4Address addr) {
		return (IPv4AssociativeTrieNode) super.higherAddedNode(addr);
	}

	@Override
	public IPv4AssociativeTrieNode ceilingAddedNode(IPv4Address addr) {
		return (IPv4AssociativeTrieNode) super.ceilingAddedNode(addr);
	}

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

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

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

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

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

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

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

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

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

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

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

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




© 2015 - 2025 Weber Informatics LLC | Privacy Policy