//ReadNode.java // //This library is free software; you can redistribute it and/or //modify it under the terms of the GNU Lesser General Public //License as published by the Free Software Foundation; either //version 2.1 of the License, or (at your option) any later version. // //This library is distributed in the hope that it will be useful, //but WITHOUT ANY WARRANTY; without even the implied warranty of //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU //Lesser General Public License for more details. package rtree; import java.io.*; /*********************************************************************************************************** * * * * This is a special purpose class that is alowed read only operartion on tree. Any write operation * * would give error. * * This class was necessary to solve the following problem. Since none of the nodes are cloned when given * * to the clients, they can become problematic when multiple reads on the same node is going on. * * Because of the new buffer policy we do not clone node, it is like a single node in the whole system. * * But the obvious problem is multiple read threads when reading nodes. * * No though problem when writing as the whole tree is locked. What we can do is that clients themselves * * tell the cache that they need a cloned node and that it willnot be used for write purpose. * * This class does exactly that. * * @author Prachuryya Barua ***********************************************************************************************************/ class ReadNode extends Node { ReadNode() { } public static ReadNode makeReadNode(Node node) { ReadNode rdNode = new ReadNode(); try{ //Integer intVal; rdNode.file = node.file; rdNode.dirty = node.dirty; rdNode.fileName = new String(node.fileName.toCharArray()); rdNode.nodeIndex = node.nodeIndex; //rdNode.isNodeEmpty = node.isNodeEmpty; rdNode.sorted = node.sorted; rdNode.nodeMBR = new Rect(node.nodeMBR);//remove rdNode.elements = new Element[node.elements.length]; if(node.elementType == LEAF_NODE){ for(int i=0; iNever Use .length field With the Returned Array . Instead use getTotalElements(). @return An element Array. */ @Override public Element[] getAllElements() { return super.getAllElements(); } @Override Element getElement(int index) throws IllegalValueException { return super.getElement(index); } /** Adds the node to the free stack. Be very careful with this method because once called, this node may be given to any new node even when you have not destroyed its object. If the node is the only node then it updates the file header as well.
Once called, there is no turning back!. */ @Override public void deleteNode() throws NodeWriteException { throw new UnsupportedOperationException("operation not supported"); } /** * This method is added to sort the elements in this node to help sweepline algorithm. */ @Override void sweepSort()//check out for null elements { super.sweepSort(); }//sweepSort /** This is a new methos that will help the phylosophy where one should write to tbe cache only when required. @return true if needed write and written or false (not dirty). */ @Override public boolean flush() throws NodeWriteException { throw new UnsupportedOperationException("operation not supported"); } @Override void setDirty(boolean val) { throw new UnsupportedOperationException("operation not supported"); } @Override public boolean isDirty() { throw new UnsupportedOperationException("operation not supported"); } }