From: <mar...@us...> - 2010-09-27 16:28:50
|
Revision: 3637 http://bigdata.svn.sourceforge.net/bigdata/?rev=3637&view=rev Author: martyncutcher Date: 2010-09-27 16:28:41 +0000 (Mon, 27 Sep 2010) Log Message: ----------- Checkin of CTC Striterators with revised license Added Paths: ----------- branches/QUADS_QUERY_BRANCH/ctc-striterators/ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Appender.java branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Appenderator.java branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/ArrayIterator.java branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Contractor.java branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Contractorator.java branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/EmptyIterator.java branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/EnumIterator.java branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/ExclusionFilter.java branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Expander.java branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Expanderator.java branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Filter.java branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Filterator.java branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/IFilter.java branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/IStriterator.java branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/IXProperty.java branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/IXPropertyIterator.java branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Mapper.java branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Mapperator.java branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Merger.java branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Mergerator.java branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Resolver.java branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Resolverator.java branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/SingleValueIterator.java branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Sorter.java branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Sorterator.java branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Striterator.java branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/UniquenessFilter.java branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Visitor.java branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Visitorator.java branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/XProperty.java branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/XPropertyIterator.java Added: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Appender.java =================================================================== --- branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Appender.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Appender.java 2010-09-27 16:28:41 UTC (rev 3637) @@ -0,0 +1,52 @@ +/* +Striterator - transformation and mapping patterns over java Iterators + +Copyright (C) SYSTAP, LLC 2010. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +package cutthecrap.utils.striterators; + +import java.util.Iterator; + +/** + * Appender + * + * Used with Appenderator by Striterator to filter returned objects. + */ + +public class Appender implements IFilter { + protected Iterator m_xtra = null; + + public Appender() {} + + public Appender(Iterator xtra) { + m_xtra = xtra; + } + + //------------------------------------------------------------- + + final public Iterator filter(Iterator src) { + return new Appenderator(src, (Iterator) m_xtra); + } + + //------------------------------------------------------------- +} Property changes on: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Appender.java ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + text/plain Added: svn:keywords + Id Date Revision Author HeadURL Added: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Appenderator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Appenderator.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Appenderator.java 2010-09-27 16:28:41 UTC (rev 3637) @@ -0,0 +1,75 @@ +/* +Striterator - transformation and mapping patterns over java Iterators + +Copyright (C) SYSTAP, LLC 2010. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +package cutthecrap.utils.striterators; + +import java.util.*; + +/** + * Appenderator + **/ + +public class Appenderator implements Iterator { + + Iterator m_src; + Iterator m_xtra; + + Iterator m_current; + + public Appenderator(Iterator src, Iterator xtra) { + m_src = src; + m_xtra = xtra; + + m_current = m_src; + } + + //------------------------------------------------------------- + + public boolean hasNext() { + if (m_current.hasNext()) { + return true; + } + + m_current = m_xtra; + + return m_current.hasNext(); + } + + //------------------------------------------------------------- + // must call hasNext() to ensure m_current is correct + public Object next() { + if (hasNext()) { + return m_current.next(); + } + + throw new NoSuchElementException("FilterIterator"); + } + + //------------------------------------------------------------- + + public void remove() { + m_current.remove(); + } +} \ No newline at end of file Property changes on: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Appenderator.java ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + text/plain Added: svn:keywords + Id Date Revision Author HeadURL Added: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/ArrayIterator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/ArrayIterator.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/ArrayIterator.java 2010-09-27 16:28:41 UTC (rev 3637) @@ -0,0 +1,56 @@ +/* +Striterator - transformation and mapping patterns over java Iterators + +Copyright (C) SYSTAP, LLC 2010. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +package cutthecrap.utils.striterators; + +import java.util.Iterator; + +/** + * Supports standard iteration over an object Array, allowing this to + * be used as a source for a <code>Striterator</code>. + */ +public class ArrayIterator implements Iterator { + Object[] m_src = null; + int m_index = 0; + + /** Constructor takes source object array **/ + public ArrayIterator(Object[] src) { + m_src = src; + } + + /** checks with current index and array size **/ + public boolean hasNext() { + return m_src != null && m_src.length > m_index; + } + + /** @return current index from array **/ + public Object next() { + return m_src[m_index++]; + } + + /** void .. does nothing **/ + public void remove() { + } +} Property changes on: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/ArrayIterator.java ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + text/plain Added: svn:keywords + Id Date Revision Author HeadURL Added: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Contractor.java =================================================================== --- branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Contractor.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Contractor.java 2010-09-27 16:28:41 UTC (rev 3637) @@ -0,0 +1,55 @@ +/* +Striterator - transformation and mapping patterns over java Iterators + +Copyright (C) SYSTAP, LLC 2010. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +package cutthecrap.utils.striterators; + +import java.util.Iterator; + +/** + * Used with a Contractorator to contract an Expanded iterator + * + * The Contractorator will call contract on this object + * @author Martyn Cutcher + */ +public abstract class Contractor implements IFilter { + + protected Object m_state = null; + + public Contractor() { } + + public Contractor(Object state) { + m_state = state; + } + + //------------------------------------------------------------- + + public Iterator filter(Iterator src) { + return new Contractorator(src, this); + } + + //------------------------------------------------------------- + + protected abstract Object contract(Iterator src); +} Property changes on: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Contractor.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Id Date Revision Author HeadURL Added: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Contractorator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Contractorator.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Contractorator.java 2010-09-27 16:28:41 UTC (rev 3637) @@ -0,0 +1,76 @@ +/* +Striterator - transformation and mapping patterns over java Iterators + +Copyright (C) SYSTAP, LLC 2010. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +package cutthecrap.utils.striterators; + +import java.util.Iterator; +import java.util.NoSuchElementException; + +/** + * A Contractorator is the reverse of an Expanderator. A Contractorator takes a + * source Iterator, and consumes elements from it in batches by passing to the + * Contractor which returns an object when ready. It is upto the Contractor to + * handle termination conditions. For example, it might batch consume the + * objects ten at a time with some summary info, but handle that there may be + * less than ten elements in the final summary. + * + * A Contractor could also be used to chunk up a number of objects for + * serialization, perhaps for network transmission. Such a pattern might be used + * with an Expander on the other side to deserialize into an iterator. + * + * @author Martyn Cutcher + */ +public class Contractorator implements Iterator { + Iterator m_src; + Contractor m_contractor; + Object m_next; + + public Contractorator(Iterator src, Contractor contractor) { + m_src = src; + m_contractor = contractor; + + m_next = m_contractor.contract(m_src); + } + + public boolean hasNext() { + return m_next != null; + } + + public Object next() { + if (m_next == null) { + throw new NoSuchElementException(); + } + + Object ret = m_next; + m_next = m_contractor.contract(m_src); + + return ret; + } + + public void remove() { + throw new UnsupportedOperationException(); + } + +} Property changes on: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Contractorator.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Id Date Revision Author HeadURL Added: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/EmptyIterator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/EmptyIterator.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/EmptyIterator.java 2010-09-27 16:28:41 UTC (rev 3637) @@ -0,0 +1,50 @@ +/* +Striterator - transformation and mapping patterns over java Iterators + +Copyright (C) SYSTAP, LLC 2010. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +package cutthecrap.utils.striterators; + +import java.util.*; + +/*************************************************************************** + * <p>Need to return an iterator to indicate that there's nothing there? Here's + * one ready made.</p> + * + * <p>It allows calls to be made without needing to check for a null iterator.</p> + */ + +public final class EmptyIterator implements Iterator { + public boolean hasNext() { + return false; + } + + public Object next() { + return null; + } + + public void remove() {} + + final static public EmptyIterator DEFAULT = new EmptyIterator(); +} + Property changes on: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/EmptyIterator.java ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + text/plain Added: svn:keywords + Id Date Revision Author HeadURL Added: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/EnumIterator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/EnumIterator.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/EnumIterator.java 2010-09-27 16:28:41 UTC (rev 3637) @@ -0,0 +1,54 @@ +/* +Striterator - transformation and mapping patterns over java Iterators + +Copyright (C) SYSTAP, LLC 2010. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +package cutthecrap.utils.striterators; + +import java.util.Iterator; +import java.util.Enumeration; + +/** + * Wrapper for Enumeration objects to produce an Iterator. + */ + +public class EnumIterator implements Iterator { + + protected Enumeration m_enum = null; + + public EnumIterator(Enumeration p_enum) { + m_enum = p_enum; + } + + public boolean hasNext() { + return m_enum.hasMoreElements(); + } + + public Object next() { + return m_enum.nextElement(); + } + + public void remove() { + throw new UnsupportedOperationException("Remove Not Supported by underlying Enumeration"); + } +} Property changes on: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/EnumIterator.java ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + text/plain Added: svn:keywords + Id Date Revision Author HeadURL Added: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/ExclusionFilter.java =================================================================== --- branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/ExclusionFilter.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/ExclusionFilter.java 2010-09-27 16:28:41 UTC (rev 3637) @@ -0,0 +1,42 @@ +/* +Striterator - transformation and mapping patterns over java Iterators + +Copyright (C) SYSTAP, LLC 2010. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +package cutthecrap.utils.striterators; + +/****************************************************************************** + * Derived from Filter, and excludes a single object from the iteration. + */ +public class ExclusionFilter extends Filter { + public ExclusionFilter(Object state) { + super(state); + } + + /*********************************************************************** + * Just make sure that the current object is not the one to be excluded. + **/ + protected boolean isValid(Object obj) { + return obj != m_state; + } +} Property changes on: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/ExclusionFilter.java ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + text/plain Added: svn:keywords + Id Date Revision Author HeadURL Added: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Expander.java =================================================================== --- branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Expander.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Expander.java 2010-09-27 16:28:41 UTC (rev 3637) @@ -0,0 +1,56 @@ +/* +Striterator - transformation and mapping patterns over java Iterators + +Copyright (C) SYSTAP, LLC 2010. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +package cutthecrap.utils.striterators; + +import java.util.Iterator; + +/** + * Expander + * + * Used with Expanderator by Striterator to expand returned objects. + * + * Derivations must implement expand method. + */ + +public abstract class Expander implements IFilter { + protected Object m_state = null; + + public Expander() { } + + public Expander(Object state) { + m_state = state; + } + + //------------------------------------------------------------- + + final public Iterator filter(Iterator src) { + return new Expanderator(src, this); + } + + //------------------------------------------------------------- + + protected abstract Iterator expand(Object obj); +} \ No newline at end of file Property changes on: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Expander.java ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + text/plain Added: svn:keywords + Id Date Revision Author HeadURL Added: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Expanderator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Expanderator.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Expanderator.java 2010-09-27 16:28:41 UTC (rev 3637) @@ -0,0 +1,81 @@ +/* +Striterator - transformation and mapping patterns over java Iterators + +Copyright (C) SYSTAP, LLC 2010. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +package cutthecrap.utils.striterators; + +import java.util.*; + +/** + * Expanderator + * + * Flattens out a two-level iteration. By combining Expanderators recursively a general tree + * iteration is provided. + * + * Provides resolution for both the child object and also the nested iterator. + * The actual expansion is via an Expander object that is passed in at construction. + */ + +public class Expanderator implements Iterator { + + Iterator m_src; + Iterator m_child = null; + + Expander m_expander; + + public Expanderator(Iterator src, Expander expander) { + m_src = src; + m_expander = expander; + } + + //------------------------------------------------------------- + + public boolean hasNext() { + if (m_child != null && m_child.hasNext()) { + return true; + } else if (m_src.hasNext()) { + m_child = m_expander.expand(m_src.next()); + + return hasNext(); + } else { + return false; + } + } + + //------------------------------------------------------------- + // must call hasNext() to ensure m_child is setup + public Object next() { + if (hasNext()) { + return m_child.next(); + } + + throw new NoSuchElementException("Expanderator"); + } + + //------------------------------------------------------------- + + public void remove() { + m_child.remove(); + } +} \ No newline at end of file Property changes on: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Expanderator.java ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + text/plain Added: svn:keywords + Id Date Revision Author HeadURL Added: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Filter.java =================================================================== --- branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Filter.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Filter.java 2010-09-27 16:28:41 UTC (rev 3637) @@ -0,0 +1,52 @@ +/* +Striterator - transformation and mapping patterns over java Iterators + +Copyright (C) SYSTAP, LLC 2010. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +package cutthecrap.utils.striterators; + +import java.util.Iterator; + +/** + * Used with Filterator by Striterator to filter returned objects. + */ +public abstract class Filter implements IFilter { + + protected Object m_state = null; + + public Filter() {} + + public Filter(Object state) { + m_state = state; + } + + //------------------------------------------------------------- + + final public Iterator filter(Iterator src) { + return new Filterator(src, this); + } + + //------------------------------------------------------------- + + protected abstract boolean isValid(Object obj); +} Property changes on: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Filter.java ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + text/plain Added: svn:keywords + Id Date Revision Author HeadURL Added: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Filterator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Filterator.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Filterator.java 2010-09-27 16:28:41 UTC (rev 3637) @@ -0,0 +1,95 @@ +/* +Striterator - transformation and mapping patterns over java Iterators + +Copyright (C) SYSTAP, LLC 2010. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +package cutthecrap.utils.striterators; + +import java.util.*; + +/** + * <p>Example usage</p> + * <pre> + * Iterator src = new Filterator(old, new Filter(state)) { + * boolean isValid(Object object) { + * return object == m_state; + * } + * } ); + * </pre> + * + * <p>The Filterator provide the protocol support to utulise Filter objects.</p> + */ + +public class Filterator implements Iterator { + + Iterator m_src; + Object m_value = null; + + protected Filter m_filter = null; + + public Filterator(Iterator src, Filter filter) { + m_src = src; + m_filter = filter; + + m_value = getNext(); + } + + //------------------------------------------------------------- + + public boolean hasNext() { + return m_value != null; + } + + //------------------------------------------------------------- + // must call hasNext() to ensure m_child is setup + public Object next() { + if (hasNext()) { + Object val = m_value; + m_value = getNext(); + + return val; + } + + throw new NoSuchElementException("FilterIterator"); + } + + //------------------------------------------------------------- + + public void remove() { + m_src.remove(); + } + + //------------------------------------------------------------- + + protected Object getNext() { + while (m_src.hasNext()) { + Object next = m_src.next(); + + if (m_filter.isValid(next)) { + return next; + } + } + + return null; + } +} \ No newline at end of file Property changes on: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Filterator.java ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + text/plain Added: svn:keywords + Id Date Revision Author HeadURL Added: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/IFilter.java =================================================================== --- branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/IFilter.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/IFilter.java 2010-09-27 16:28:41 UTC (rev 3637) @@ -0,0 +1,47 @@ +/* +Striterator - transformation and mapping patterns over java Iterators + +Copyright (C) SYSTAP, LLC 2010. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +package cutthecrap.utils.striterators; + +import java.util.Iterator; +import java.io.Serializable; + +/** + * Provides the hook interface that allows use by Striterators + */ +public interface IFilter extends Serializable { + /** + * <p>The filter method is provided to allow the creation of the filtering iterator.</p> + * + * <p>Any implementation should follow the following pattern:</p> + * <pre> + * public Iterator filter(Iterator src) { + * return new Filterator(src, this); + * } + * </pre> + **/ + public abstract Iterator filter(Iterator src); +} \ No newline at end of file Property changes on: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/IFilter.java ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + text/plain Added: svn:keywords + Id Date Revision Author HeadURL Added: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/IStriterator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/IStriterator.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/IStriterator.java 2010-09-27 16:28:41 UTC (rev 3637) @@ -0,0 +1,62 @@ +/* +Striterator - transformation and mapping patterns over java Iterators + +Copyright (C) SYSTAP, LLC 2010. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +package cutthecrap.utils.striterators; + +import java.lang.reflect.Method; +import java.util.Iterator; +import java.util.Enumeration; + +/** + * IStriterator + * + * Extends the Iterator interface to expose methods to add IFilter objects and a specific Type filter + */ + +public interface IStriterator extends Iterator, Enumeration { + /** Adds a Discriminating IFilter object **/ + public IStriterator addFilter(IFilter filter); + + /** check each object against cls.isInstance(object) **/ + public IStriterator addTypeFilter(Class cls); + + /** check each object against object.getClass() == cls **/ + public IStriterator addInstanceOfFilter(Class cls); + + /** exclude the passed object from the iteration **/ + public IStriterator exclude(Object object); + + /** append the passed iteration **/ + public IStriterator append(Iterator iter); + + /** Ensures the returned values appear only once **/ + public IStriterator makeUnique(); + + /** map the clients method against the Iteration, the Method MUST take a single Object valued parameter. + * can be called by : + * iter.map(this, MyClass.aMethod); + **/ + public IStriterator map(Object client, Method method); +} Property changes on: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/IStriterator.java ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + text/plain Added: svn:keywords + Id Date Revision Author HeadURL Added: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/IXProperty.java =================================================================== --- branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/IXProperty.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/IXProperty.java 2010-09-27 16:28:41 UTC (rev 3637) @@ -0,0 +1,37 @@ +/* +Striterator - transformation and mapping patterns over java Iterators + +Copyright (C) SYSTAP, LLC 2010. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +package cutthecrap.utils.striterators; + +/** IXProperty.java + */ + +public interface IXProperty { + /** Returns the key of the property **/ + public String getKey(); + + /** Returns the value of the property **/ + public Object getValue(); +} Property changes on: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/IXProperty.java ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + text/plain Added: svn:keywords + Id Date Revision Author HeadURL Added: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/IXPropertyIterator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/IXPropertyIterator.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/IXPropertyIterator.java 2010-09-27 16:28:41 UTC (rev 3637) @@ -0,0 +1,36 @@ +/* +Striterator - transformation and mapping patterns over java Iterators + +Copyright (C) SYSTAP, LLC 2010. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +package cutthecrap.utils.striterators; + +/** + * IXPropertyIterator + * + * A standard iterator, extended to provide a nextProperty method returning IXProperty objects + **/ + +public interface IXPropertyIterator extends IStriterator { + public IXProperty nextProperty(); +} Property changes on: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/IXPropertyIterator.java ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + text/plain Added: svn:keywords + Id Date Revision Author HeadURL Added: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Mapper.java =================================================================== --- branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Mapper.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Mapper.java 2010-09-27 16:28:41 UTC (rev 3637) @@ -0,0 +1,64 @@ +/* +Striterator - transformation and mapping patterns over java Iterators + +Copyright (C) SYSTAP, LLC 2010. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +package cutthecrap.utils.striterators; + +import java.util.Iterator; +import java.lang.reflect.Method; + +/** + * Mapper + * + * Used with Mapperator by Striterator to map instance methods against member objects. + */ + +public class Mapper implements IFilter { + protected Object m_client = null; + protected Method m_method = null; + protected Object[] m_args = {null}; + + public Mapper(Object client, Method method) { + m_client = client; + m_method = method; + } + + //------------------------------------------------------------- + + final public Iterator filter(Iterator src) { + return new Mapperator(src, this); + } + + //------------------------------------------------------------- + + protected void apply(Object obj) { + try { + m_args[0] = obj; + + m_method.invoke(m_client, m_args); + } catch (Exception e) { + throw new RuntimeException("Error on mapping method", e); + } + } +} \ No newline at end of file Property changes on: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Mapper.java ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + text/plain Added: svn:keywords + Id Date Revision Author HeadURL Added: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Mapperator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Mapperator.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Mapperator.java 2010-09-27 16:28:41 UTC (rev 3637) @@ -0,0 +1,61 @@ +/* +Striterator - transformation and mapping patterns over java Iterators + +Copyright (C) SYSTAP, LLC 2010. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +package cutthecrap.utils.striterators; + +import java.util.*; + +/** + * Mapperator + * + * Initialized with a Mapper object, wraps a standard iterator and calls apply on each object as it is iterated + */ + +public class Mapperator implements Iterator { + + Iterator m_iter; + Mapper m_mapper; + + public Mapperator(Iterator iter, Mapper mapper) { + m_iter = iter; + m_mapper = mapper; + } + + public boolean hasNext() { + return m_iter.hasNext(); + } + + public Object next() { + Object obj = m_iter.next(); + + m_mapper.apply(obj); + + return obj; + } + + public void remove() { + m_iter.remove(); + } +} \ No newline at end of file Property changes on: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Mapperator.java ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + text/plain Added: svn:keywords + Id Date Revision Author HeadURL Added: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Merger.java =================================================================== --- branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Merger.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Merger.java 2010-09-27 16:28:41 UTC (rev 3637) @@ -0,0 +1,53 @@ +/* +Striterator - transformation and mapping patterns over java Iterators + +Copyright (C) SYSTAP, LLC 2010. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +package cutthecrap.utils.striterators; + +import java.util.Iterator; +import java.util.Comparator; + +/** + * Used with Mergerator by Striterator to merge returned objects. + */ + +public class Merger implements IFilter { + protected Iterator m_xtra = null; + protected Comparator m_comparator = null; + + public Merger() {} + + public Merger(Iterator xtra, Comparator comparator) { + m_xtra = xtra; + m_comparator = comparator; + } + + //------------------------------------------------------------- + + final public Iterator filter(Iterator src) { + return new Mergerator(src, m_xtra, m_comparator); + } + + //------------------------------------------------------------- +} Property changes on: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Merger.java ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + text/plain Added: svn:keywords + Id Date Revision Author HeadURL Added: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Mergerator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Mergerator.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Mergerator.java 2010-09-27 16:28:41 UTC (rev 3637) @@ -0,0 +1,88 @@ +/* +Striterator - transformation and mapping patterns over java Iterators + +Copyright (C) SYSTAP, LLC 2010. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +package cutthecrap.utils.striterators; + +import java.util.*; + +/** + * Merges two sorted lists removing equal objects. For example, two sorted + * lists of Strings to create a single list with no duplicates. + **/ +public class Mergerator implements Iterator { + + Iterator m_setA; + Iterator m_setB; + Comparator m_comparator; + + Object m_valA = null; + Object m_valB = null; + + public Mergerator(Iterator setA, Iterator setB, Comparator comparator) { + m_setA = setA; + m_setB = setB; + + m_comparator = comparator; + + if (m_setA.hasNext()) { + m_valA = m_setA.next(); + } + + if (m_setB.hasNext()) { + m_valB = m_setB.next(); + } + } + + //------------------------------------------------------------- + + public boolean hasNext() { + return m_valA != null || m_valB != null; + } + + //------------------------------------------------------------- + // must call hasNext() to ensure m_current is correct + public Object next() { + if (hasNext()) { + Object retVal = null; + + if (m_valB == null || (m_valA != null && (m_comparator.compare(m_valA, m_valB) <= 0))) { + retVal = m_valA; + m_valA = m_setA.hasNext() ? m_setA.next() : null; + } else { + retVal = m_valB; + m_valB = m_setB.hasNext() ? m_setB.next() : null; + } + return retVal; + } else { + throw new NoSuchElementException("Mergerator"); + } + } + + //------------------------------------------------------------- + + public void remove() { + throw new RuntimeException("Cannot remove object from merged set"); + } +} \ No newline at end of file Property changes on: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Mergerator.java ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + text/plain Added: svn:keywords + Id Date Revision Author HeadURL Added: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Resolver.java =================================================================== --- branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Resolver.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Resolver.java 2010-09-27 16:28:41 UTC (rev 3637) @@ -0,0 +1,56 @@ +/* +Striterator - transformation and mapping patterns over java Iterators + +Copyright (C) SYSTAP, LLC 2010. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +package cutthecrap.utils.striterators; + +import java.util.Iterator; + +/** + * Resolver + * + * Used with Resolverator by Striterator to resolve returned objects. + * + * Cannot be instantiated directly since an implementation of the resolve method is required. + */ + +public abstract class Resolver implements IFilter { + protected Object m_state = null; + + public Resolver() {} + + public Resolver(Object state) { + m_state = state; + } + + //------------------------------------------------------------- + + final public Iterator filter(Iterator src) { + return new Resolverator(src, this); + } + + //------------------------------------------------------------- + + protected abstract Object resolve(Object obj); +} \ No newline at end of file Property changes on: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Resolver.java ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + text/plain Added: svn:keywords + Id Date Revision Author HeadURL Added: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Resolverator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Resolverator.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Resolverator.java 2010-09-27 16:28:41 UTC (rev 3637) @@ -0,0 +1,57 @@ +/* +Striterator - transformation and mapping patterns over java Iterators + +Copyright (C) SYSTAP, LLC 2010. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +package cutthecrap.utils.striterators; + +import java.util.*; + +/** + * Resolverator + * + * Initialized with a Resolver object, wraps a standard iterator and resolves each returned object + */ + +public class Resolverator implements Iterator { + + Iterator m_iter; + Resolver m_resolver; + + public Resolverator(Iterator iter, Resolver resolver) { + m_iter = iter; + m_resolver = resolver; + } + + public boolean hasNext() { + return m_iter.hasNext(); + } + + public Object next() { + return m_resolver.resolve(m_iter.next()); + } + + public void remove() { + m_iter.remove(); + } +} \ No newline at end of file Property changes on: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Resolverator.java ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + text/plain Added: svn:keywords + Id Date Revision Author HeadURL Added: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/SingleValueIterator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/SingleValueIterator.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/SingleValueIterator.java 2010-09-27 16:28:41 UTC (rev 3637) @@ -0,0 +1,61 @@ +/* +Striterator - transformation and mapping patterns over java Iterators + +Copyright (C) SYSTAP, LLC 2010. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +package cutthecrap.utils.striterators; + +import java.util.*; + +/*************************************************************************** + * SingleValueIterator + * + * Only one value but need to return an iterator? This makes it easy. + */ + + public class SingleValueIterator implements Iterator { + Object m_value; + boolean m_hasNext = true; + + public SingleValueIterator(Object value) { + m_value = value; + } + public boolean hasNext() { + return m_hasNext; + } + public Object next() { + if (!m_hasNext) { + m_value = null; + } else { + m_hasNext = false; + } + + return m_value; + } + public void remove() { + m_hasNext = false; + m_value = null; + } +} + + Property changes on: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/util... [truncated message content] |