/** Return the previous HeirarchyNode before this one at the same level in the * entire heirarchy. Return null if this is the first one (or if there is * no parent). This proceeds as follows: If there is no parent, return * null. If there is a child before this one in the parent, return it, * otherwise ask the parent for the previousInHeirarchy at its level. If * there is none, return null. If the previous parent has children, * return return its last child. Otherwise, keep asking the parent * for its previousInHeirarchy until one is found with children. If none, * return null. */ public HeirarchyNode previousInHeirarchy() { if (_parent == null) { return(null); } int previousIndex = _index - 1; if (previousIndex >= 0) { return(_parent.getChild(previousIndex)); } for (HeirarchyNode previousParent = _parent.previousInHeirarchy(); previousParent != null; previousParent = previousParent.previousInHeirarchy()) { if (previousParent.getChildCount() > 0) { return(previousParent.getChild(previousParent.getChildCount() - 1)); } } return(null); }
/** Return the previous instance of the given class type looking * backwards from this MusicSymbol in the entire score. * For example, previousInstanceOfInScore(Beam.class) gets the * previous Beam. * * @param desiredClass Class object for the MusicSymbol being sought * @return the previous MusicSymbol of the desired class in the * entire Score, or null if not found. */ public MusicSymbol previousInstanceOfInScore(Type desiredClass) { for (HeirarchyNode previous = previousInHeirarchy(); previous != null; previous = previous.previousInHeirarchy()) { if (desiredClass.IsInstanceOfType(previous)) { return((MusicSymbol)previous); } } return(null); }