1 22 23 package org.xquark.mapper.mapping; 24 25 import java.util.HashMap ; 26 27 31 public class MappingSetIteratorImpl implements MappingSetIterator 32 { 33 private int current = -1; 34 private int currentIndex = -1; 35 private int firstOccurenceIndex = -1; 36 private MappingInfo[] array; 37 private boolean reverse = false; 38 private HashMap tableFirstOccurences = new HashMap (); 39 40 43 public MappingSetIteratorImpl(MappingInfo[] tms, boolean reverse) 44 { 45 array = tms; 46 this.reverse = reverse; 47 if (tms != null) 48 { 49 if (reverse) 50 current = array.length; 51 else 52 current = -1; 53 } 54 } 55 56 public MappingSetIteratorImpl(MappingInfo[] tms) 57 { 58 this(tms, false); 59 } 60 61 72 public boolean hasNext() 73 { 74 if (array == null) 75 return false; 76 if (reverse) 77 return current > 0; 78 else 79 return (current + 1) < array.length; 80 } 81 82 public MappingInfo next() 83 { 84 MappingInfo ret = null; 85 if (hasNext()) 86 { 87 if (reverse) 89 current--; 90 else 91 current++; 92 registerTable(); 93 ret = array[current]; 94 } 95 return ret; 96 } 97 98 public boolean isTableFirstOccurence() 99 { 100 return firstOccurenceIndex == currentIndex; 101 } 102 103 public int getFirstOccurenceTableIndex() 104 { 105 return firstOccurenceIndex; 106 } 107 108 private void registerTable() 109 { 110 if (hasNext()) 111 { 112 TableMapping wTable = array[current].getTableMapping(); 113 currentIndex = wTable.getTableIndex(); 114 Integer firstOccurenceObject = (Integer )tableFirstOccurences.get(wTable.getTableName()); 115 if (firstOccurenceObject == null) { 117 tableFirstOccurences.put(wTable.getTableName(), new Integer (currentIndex)); 118 firstOccurenceIndex = currentIndex; 119 } 120 else 121 firstOccurenceIndex = firstOccurenceObject.intValue(); 122 } 123 } 124 125 } 126 | Popular Tags |