com.googlecode.concurrenttrees.radix.node.concrete.bytearray.ByteArrayNodeLeafNullValue Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of concurrent-trees Show documentation
Show all versions of concurrent-trees Show documentation
Concurrent Radix Trees and Concurrent Suffix Trees for Java.
The newest version!
/*
* Copyright 2012-2013 Niall Gallagher
*
* 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
*
* 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 com.googlecode.concurrenttrees.radix.node.concrete.bytearray;
import com.googlecode.concurrenttrees.radix.node.Node;
import com.googlecode.concurrenttrees.radix.node.NodeList;
import com.googlecode.concurrenttrees.radix.node.SimpleNodeList;
/**
* Similar to {@link com.googlecode.concurrenttrees.radix.node.concrete.chararray.CharArrayNodeLeafNullValue} but represents
* each character in UTF-8, instead of Java's default 2-byte UFT-16 encoding.
*
* Supports only characters which can be represented as a single byte in UTF-8. Throws an exception if characters
* are encountered which cannot be represented as a single byte.
*
* @author Niall Gallagher
*/
public class ByteArrayNodeLeafNullValue implements Node {
private static final long serialVersionUID = 1L;
// Characters in the edge arriving at this node from a parent node.
// Once assigned, we never modify this...
private final byte[] incomingEdgeCharArray;
public ByteArrayNodeLeafNullValue(CharSequence edgeCharSequence) {
this(ByteArrayCharSequence.toSingleByteUtf8Encoding(edgeCharSequence));
}
public ByteArrayNodeLeafNullValue(byte[] incomingEdgeCharArray) {
this.incomingEdgeCharArray = incomingEdgeCharArray;
}
@Override
public CharSequence getIncomingEdge() {
return new ByteArrayCharSequence(incomingEdgeCharArray, 0, incomingEdgeCharArray.length);
}
@Override
public char getIncomingEdgeFirstCharacter() {
return (char) (incomingEdgeCharArray[0] & 0xFF);
}
@Override
public int getIncomingEdgeLength() {
return incomingEdgeCharArray.length;
}
@Override
public char getIncomingEdgeCharacterAt(int index) {
return (char) (incomingEdgeCharArray[index] & 0xFF);
}
@Override
public Object getValue() {
return null;
}
@Override
public Node getOutgoingEdge(char edgeFirstCharacter) {
return null;
}
@Override
public void updateOutgoingEdge(Node childNode) {
throw new IllegalStateException("Cannot update the reference to the following child node for the edge starting with '" + childNode.getIncomingEdgeFirstCharacter() +"', no such edge already exists: " + childNode);
}
@Override
public NodeList getOutgoingEdges() {
return SimpleNodeList.EMPTY;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("Node{");
sb.append("edge=").append(getIncomingEdge());
sb.append(", value=null");
sb.append(", edges=[]");
sb.append("}");
return sb.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy