📄 treefloorlist.java
字号:
/* * (C) 2001 by Argonne National Laboratory * See COPYRIGHT in top-level directory. *//* * @author Anthony Chan */package logformat.slog2.input;import java.util.Iterator;import java.util.TreeMap;import java.util.NoSuchElementException;import base.drawable.TimeBoundingBox;import base.drawable.Drawable;import base.drawable.Shadow;import logformat.slog2.*;/* The leaf TreeNodes are always at depth = 0, or at TreeFloor[ idx = 0 ].*/public class TreeFloorList{ private static final short NULL_DEPTH = -1; private TreeFloor[] floors; private Drawable.Order dobj_order; private BufForObjects.Order buf4objs_order; private short lowest_depth; public TreeFloorList( final Drawable.Order in_dobj_order ) { // For checking of consistence when used with IteratorOfXXXDrawables() dobj_order = in_dobj_order; buf4objs_order = dobj_order.isIncreasingTimeOrdered() ? BufForObjects.INCRE_INDEX_ORDER : BufForObjects.DECRE_INDEX_ORDER; lowest_depth = NULL_DEPTH; floors = null; } protected void init( short depth_max ) { floors = new TreeFloor[ depth_max + 1 ]; for ( int idx = floors.length-1; idx >= 0; idx-- ) floors[ idx ] = new TreeFloor( (short) idx, buf4objs_order ); lowest_depth = depth_max; } public BufForObjects getRoot() { // If InputLog.readTreeNode( InputLog.getFileBlockPtrToTreeRoot() ) // returns null, above init( short depth_max ) won't be called. // floors[] remain uninitialized. floors[] needs to be checked for null. if ( floors != null ) return (BufForObjects) floors[ floors.length-1 ].firstKey(); else return null; } /* add() guarantees that BufForObjects of same depth are added to */ public void put( final BufForObjects nodestub, final BufForObjects node ) { short node_depth = nodestub.getTreeNodeID().depth; floors[ node_depth ].put( nodestub, node ); if ( node_depth < lowest_depth ) lowest_depth = node_depth; } public TreeNode get( final BufForObjects nodestub ) { short node_depth = nodestub.getTreeNodeID().depth; if ( floors[ node_depth ].size() == 0 ) return null; else return (TreeNode) floors[ node_depth ].get( nodestub ); } public boolean contains( final BufForObjects nodestub ) { short node_depth = nodestub.getTreeNodeID().depth; if ( floors[ node_depth ].size() == 0 ) return false; else return floors[ node_depth ].containsKey( nodestub ); } // Invoking remove() may require calling updateLowestDepth(), recommended. public void remove( final BufForObjects nodestub ) { short node_depth = nodestub.getTreeNodeID().depth; if ( floors[ node_depth ].size() > 0 ) { floors[ node_depth ].remove( nodestub ); } } // updateLowestDepth() is needed after a series of remove()'s public void updateLowestDepth() { for ( short idx = 0; idx < floors.length; idx++ ) if ( floors[ idx ].size() > 0 ) { lowest_depth = idx; break; } } /* For informational service purpose only */ public short getLowestDepth() { return lowest_depth; } /* removeAllChildFloorsBelow() guarantees lowest_depth be set correctly, no need to call updateLowestDepth(). */ public void removeAllChildFloorsBelow( short floor_depth ) { for ( short idepth = 0; idepth < floor_depth; idepth++ ) { if ( floors[ idepth ].size() > 0 ) floors[ idepth ].clear(); } lowest_depth = floor_depth; } public TreeFloor getLowestFloor() { return floors[ lowest_depth ]; } /* For Zoom-out/Scrolling, i.e. enlargement/moving of the Time View. Assumption: | tframe( time_frame ) | >= | floors[ lowest_depth ] | Caller is required to check for the assumption before invoking the fn. Returned the lowest TreeFloor __totally__ covers tframe If not found, return the top TreeFloor */ public TreeFloor getCoveringFloor( final TimeBoundingBox tframe ) { for ( int idepth = lowest_depth; idepth < floors.length; idepth++ ) { if ( floors[ idepth ].covers( tframe ) ) return floors[ idepth ]; } return floors[ floors.length - 1 ]; } /* For Zoom-In, i.e. contraction of Time View Assumption: | tframe( time_frame ) | <= | floors[ lowest_depth ] | Caller is required to check for the assumption before invoking the fn. Returned the lowest TreeFloor __barely__ covers tframe If not found, return the top TreeFloor */ public TreeFloor pruneToBarelyCoveringFloor( final TimeBoundingBox tframe ) { for ( int idepth = lowest_depth; idepth < floors.length; idepth++ ) { if ( floors[ idepth ].coversBarely( tframe ) ) return floors[ idepth ]; else floors[ idepth ].pruneToBarelyCovering( tframe ); } return floors[ floors.length - 1 ]; } public Iterator iteratorOfAllDrawables( final TimeBoundingBox tframe, final Drawable.Order itrOrder, boolean isComposite, boolean isNestable ) { if ( itrOrder.isStartTimeOrdered() == dobj_order.isStartTimeOrdered() ) return new ItrOfDrawables( tframe, itrOrder, isComposite, isNestable, true ); else { System.err.println( "TreeFloorList.iteratorOfAllDrawables(): " + "Inconsistent Start/Final TimeOrder!\n" + "TreeFloor is created with " + dobj_order +"\n" + "but iteratorOfAllDrawables() is " + "invoked with " + itrOrder + "."); return null; } } public Iterator iteratorOfRealDrawables( final TimeBoundingBox tframe, final Drawable.Order itrOrder, boolean isComposite, boolean isNestable ) { if ( itrOrder.isStartTimeOrdered() == dobj_order.isStartTimeOrdered() ) return new ItrOfDrawables( tframe, itrOrder, isComposite, isNestable, false ); else { System.err.println( "TreeFloorList.iteratorOfRealDrawables(): " + "Inconsistent Start/Final Time Order!\n" + "TreeFloor is created with " + dobj_order +"\n" + "but iteratorOfRealDrawables() is " + "invoked with " + itrOrder + "."); return null; } } public Iterator iteratorOfLowestFloorShadows( final TimeBoundingBox tframe, final Drawable.Order itrOrder, boolean isNestable ) { if ( itrOrder.isStartTimeOrdered() == dobj_order.isStartTimeOrdered() ) return floors[ lowest_depth ].iteratorOfShadows( tframe, itrOrder, isNestable ); else { System.err.println( "TreeFloorList.iteratorOfLowestFloorShadows(): "
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -