001package com.hfg.util.collection;
002
003
004import java.util.ArrayList;
005import java.util.Collection;
006import java.util.function.Predicate;
007import java.util.function.UnaryOperator;
008
009//------------------------------------------------------------------------------
010/**
011 List with dirty flag support.
012 <div>
013 @author J. Alex Taylor, hairyfatguy.com
014 </div>
015 */
016//------------------------------------------------------------------------------
017// com.hfg XML/HTML Coding Library
018//
019// This library is free software; you can redistribute it and/or
020// modify it under the terms of the GNU Lesser General Public
021// License as published by the Free Software Foundation; either
022// version 2.1 of the License, or (at your option) any later version.
023//
024// This library is distributed in the hope that it will be useful,
025// but WITHOUT ANY WARRANTY; without even the implied warranty of
026// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
027// Lesser General Public License for more details.
028//
029// You should have received a copy of the GNU Lesser General Public
030// License along with this library; if not, write to the Free Software
031// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
032//
033// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
034// jataylor@hairyfatguy.com
035//------------------------------------------------------------------------------
036
037public class DirtyList<T> extends ArrayList<T>
038{
039   private boolean mIsDirty;
040
041   //###########################################################################
042   // CONSTRUCTORS
043   //###########################################################################
044
045   //---------------------------------------------------------------------------
046   public DirtyList()
047   {
048      super();
049   }
050
051   //---------------------------------------------------------------------------
052   public DirtyList(int inInitialCapacity)
053   {
054      super(inInitialCapacity);
055   }
056
057   //---------------------------------------------------------------------------
058   public DirtyList(Collection<T> inCollection)
059   {
060      super();
061      addAll(inCollection);
062   }
063
064   //###########################################################################
065   // PUBLIC METHODS
066   //###########################################################################
067
068   //--------------------------------------------------------------------------
069   public void bless()
070   {
071      mIsDirty = false;
072   }
073
074   //--------------------------------------------------------------------------
075   public boolean isDirty()
076   {
077      return mIsDirty;
078   }
079
080   //---------------------------------------------------------------------------
081   @Override
082   public void clear()
083   {
084      if (size() > 0)
085      {
086         mIsDirty = true;
087      }
088
089      super.clear();
090   }
091
092   //---------------------------------------------------------------------------
093   @Override
094   public boolean remove(Object inObj)
095   {
096      mIsDirty = true;
097      return super.remove(inObj);
098   }
099
100   //---------------------------------------------------------------------------
101   @Override
102   public T remove(int inPosition)
103   {
104      mIsDirty = true;
105      return super.remove(inPosition);
106   }
107
108   //---------------------------------------------------------------------------
109   @Override
110   public boolean removeAll(Collection<? > inObjs)
111   {
112      mIsDirty = true;
113      return super.removeAll(inObjs);
114   }
115
116   //---------------------------------------------------------------------------
117   @Override
118   public boolean add(T inObj)
119   {
120      mIsDirty = true;
121      return super.add(inObj);
122   }
123
124   //---------------------------------------------------------------------------
125   @Override
126   public void add(int inIndex, T inObj)
127   {
128      mIsDirty = true;
129      super.add(inIndex, inObj);
130   }
131
132   //---------------------------------------------------------------------------
133   @Override
134   public boolean addAll(Collection<? extends T> inObjs)
135   {
136      mIsDirty = true;
137      return super.addAll(inObjs);
138   }
139
140   //---------------------------------------------------------------------------
141   @Override
142   public boolean addAll(int inIndex, Collection<? extends T> inObjs)
143   {
144      mIsDirty = true;
145      return super.addAll(inIndex, inObjs);
146   }
147
148   //---------------------------------------------------------------------------
149   @Override
150   public boolean retainAll(Collection<?> inObjs)
151   {
152      mIsDirty = true;
153      return super.retainAll(inObjs);
154   }
155
156   //---------------------------------------------------------------------------
157   @Override
158   public boolean removeIf(Predicate<? super T> inFilter)
159   {
160      mIsDirty = true;
161      return super.removeIf(inFilter);
162   }
163
164   //---------------------------------------------------------------------------
165   @Override
166   public void removeRange(int inFrom, int inTo)
167   {
168      mIsDirty = true;
169      super.removeRange(inFrom, inTo);
170   }
171
172   //---------------------------------------------------------------------------
173   @Override
174   public void replaceAll(UnaryOperator<T> inOperator)
175   {
176      mIsDirty = true;
177      super.replaceAll(inOperator);
178   }
179}