1 28 29 package org.jibx.binding.util; 30 31 32 39 40 public class SparseStack 41 { 42 43 private Object m_current; 44 45 46 private int m_level; 47 48 49 private IntStack m_levels; 50 51 52 private ObjectStack m_items; 53 54 57 public SparseStack() { 58 59 m_levels = new IntStack(); 61 m_levels.push(-1); 62 m_items = new ObjectStack(); 63 m_items.push(null); 64 } 65 66 71 public Object getCurrent() { 72 return m_current; 73 } 74 75 80 public void setCurrent(Object obj) { 81 m_current = obj; 82 } 83 84 87 public void enter() { 88 if (m_current != m_items.peek()) { 89 m_levels.push(m_level); 90 m_items.push(m_current); 91 } 92 m_level++; 93 } 94 95 101 public Object exit() { 102 m_level--; 103 if (m_level == m_levels.peek()) { 104 Object obj = m_current; 105 m_levels.pop(); 106 m_current = m_items.pop(); 107 return obj; 108 } else { 109 return null; 110 } 111 } 112 } | Popular Tags |