📄 node.java
字号:
/* * The contents of this file are subject to the Dyade Public License, * as defined by the file DYADE_PUBLIC_LICENSE.TXT * * You may not use this file except in compliance with the License. You may * obtain a copy of the License on the Dyade web site (www.dyade.fr) or * in the root directory of this distribution. * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for * the specific terms governing rights and limitations under the License. * * The Original Code is CmisJava API, including the java package * fr.dyade.cmis, released September 5, 2000. * * The Initial Developer of the Original Code is Dyade. The Original Code and * portions created by Dyade are Copyright Bull and Copyright INRIA. * All Rights Reserved. *//* Copyright 1996-2000 by Institut National de Recherche en Informatique * et en Automatique (INRIA) * All rights reserved. See COPYRIGHT in top-level directory. * * Authors: Laurent Andrey, Olivier Festor */package fr.dyade.cmis.agents.mit;import java.util.*;import fr.dyade.cmis.api.types.Ava;import fr.dyade.cmis.api.types.DistinguishedName;import fr.dyade.cmis.api.types.ObjectIdentifier;/** Node in a Managed Object Tree. * None of this class methods are public. Instances of this class have to be * used as index in a Managed Object Tree. * @see fr.dyade.cmis.agents.mit.ManagedObjectTree * @version $Id: Node.java,v 1.3 2000/09/05 09:58:43 festor Exp $ */public class Node { /** Empty constructor. * Only useful to create the top node of an empty managed object tree. */ Node () { super(); } Node(Node parent, Ava key, Object mo) { this.parent=parent; this.key=key; this.fMo=mo; } Node addChild(Ava pAva, Object mo) { ObjectIdentifier lOid=pAva.getAvaId(); SortedMap valuesForThisId=(SortedMap)oidWhichAreKey.get(lOid); if (valuesForThisId==null) { valuesForThisId=new TreeMap(); Object dummy=oidWhichAreKey.put(lOid, valuesForThisId); } // always access to old.. asked "name" already used. return (Node)valuesForThisId.put(pAva.getAvaValue(), new Node(this, pAva, mo)); } void remove() { if (parent!=null) { SortedMap inIdMap=(SortedMap)parent.oidWhichAreKey.get(key.getAvaId()); Object dummy = inIdMap.remove(key.getAvaValue()); if (inIdMap.isEmpty()) { dummy=parent.oidWhichAreKey.remove(key.getAvaId()); } } // else remove mit root.... ?! } /** Get child by ava. * TODO : add exeception. */ Node getChild(Ava ava) { SortedMap inIdMap=(SortedMap)oidWhichAreKey.get(ava.getAvaId()); if (inIdMap!=null) { return (Node)inIdMap.get(ava.getAvaValue()); } return null; } public final Object getManagedObject() { return fMo; } public Enumeration enumerateChilds() { return new ChildsEnumeration(this); } private SortedMap oidWhichAreKey=new TreeMap(); private Object fMo; // the ManagedObject private Node parent; private Ava key; class ChildsEnumeration implements Enumeration { ChildsEnumeration( Node pThis ){ keys=pThis.oidWhichAreKey.values().iterator(); if (keys.hasNext()) { currentValuesMap=((TreeMap)keys.next()).values().iterator(); seek(); } else { hasMore=false; } } public boolean hasMoreElements() { return hasMore; } public Object nextElement() { if (hasMore) { Object result=currentValuesMap.next(); seek(); return result; } else { // enumerateChilds/hasMoreElements/nextElement badly used throw new java.util.NoSuchElementException("Node enumerateChilds missused"); } } private void seek(){ while (!currentValuesMap.hasNext()) { if (keys.hasNext()) { currentValuesMap=((TreeMap)keys.next()).values().iterator(); } else { hasMore=false; return; } } } boolean hasMore=true; Iterator keys; Iterator currentValuesMap; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -