1 19 package org.netbeans.lib.jmi.query; 20 21 import java.util.Iterator ; 22 import java.util.NoSuchElementException ; 23 24 28 public abstract class AlterQuery implements Query { 29 30 private final Query QUERY; 31 private final Alternator ALTERNATOR; 32 33 AlterQuery(Query query) { 34 this.QUERY = query; 35 this.ALTERNATOR = null; 36 } 37 38 AlterQuery(Query query, Alternator alternator ) { 39 this.QUERY = query; 40 this.ALTERNATOR = alternator; 41 } 42 43 public Iterator iterator() { 44 return new AlterIterator(); 45 } 46 47 public boolean contains( Object object ) { 48 return QUERY.contains( alterBack( object ) ); 49 } 50 51 protected Object alter( Object object ) { 52 if ( ALTERNATOR == null ) { 53 return object; 54 } 55 else { 56 return ALTERNATOR.alter( object ); 57 } 58 } 59 60 protected Object alterBack( Object object ) { 61 if ( ALTERNATOR == null ) { 62 return object; 63 } 64 else { 65 return ALTERNATOR.alterBack( object ); 66 } 67 } 68 69 71 public interface Alternator { 72 73 public Object alter( Object object ); 74 75 public Object alterBack( Object object ); 76 } 77 78 private class AlterIterator extends QueryIterator.Delegate { 79 80 81 private Object next = null; 82 83 AlterIterator() { 84 super ( QUERY.iterator() ); 85 } 86 87 public boolean hasNext() { 88 return ITERATOR.hasNext(); 89 } 90 91 public Object next() { 92 93 Object next = ITERATOR.next(); 94 return alter( next ); 95 } 96 } 97 98 } 99 | Popular Tags |