/*
* Copyright (C) 2004 Roman Krylov
* rkrylov@mail.ru
*
*
* This program 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
* of the License, or (at your option) any later version.
*
* This program 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.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package org.JWrapper;
import java.util.*;
/**
*
* It could seem insignificant, but really very important question:
* is children collection ordered or unordered?
*
*/
public abstract class JCompositeWrapper extends JWrapper
{
protected Signal1 childAdded = new Signal1();
protected Signal1 childRemoved = new Signal1();
protected Signal0 allChanged = new Signal0();
java.util.Map > > >
collective_user_functions
= new java.util.LinkedHashMap > > >();
public JCompositeWrapper(String _name)
{
super(_name);
}
public java.util.Map > > >
getCollectiveUserFunctions()
{
return
new java.util.LinkedHashMap > > >(collective_user_functions); }
public void putCollectiveUserFunction(
NamedFunction>> value)
{ collective_user_functions.put(value.getID(),value); }
/** Subclasses should provide; it's like javax/swing/TreeModel/getChildCount(...) */
public abstract int size() throws Exception;
public Signal1 getSignalChildAdded()
{ return childAdded; }
public Signal1 getSignalChildRemoved()
{ return childRemoved; }
public Signal0 getSignalAllChanged()
{ return allChanged; }
public abstract JWrapper[] getChildren() throws Exception;
public JWrapper getWrapper(int i) throws Exception
{
return getChildren()[i];
}
/**
* Should be overridden in subclasses
*/
public JWrapper getDetailedWrapper(JWrapper wrp) throws Exception
{
int i=-1;
JWrapper[] children = getChildren();
for(i=0;irelational scheme ?'
* and as a result: 'should this be better viewed as table or tree?' */
public boolean isRegular() {return false;}
public JWrapper getChildPrototype() throws Exception
{ return null; }
public List selectLeafChildren() throws Exception
{
Vector result = new Vector();
for(JWrapper wrp : this.getChildren())
{
if(wrp instanceof JLeafWrapper)
{ result.add((JLeafWrapper)wrp);}
}
return result;
}
public List select(function1 predicate) throws Exception
{
Vector result = new Vector();
for(JWrapper wrp : this.getChildren())
{
if(predicate.Op(wrp))
{ result.add(wrp);}
}
return result;
}
public void dump() throws Exception
{
System.out.println("+ "+this.getName());
for(JWrapper w : getChildren())
{ System.out.println(" - "+w); }
}
public int indexOf(JWrapper wrp) throws Exception
{
int result = -1;
for(int i=0; i
|