Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2010 Daniel Murphy Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
Created on May 31, 2010, 1:17:24 PM
 
 package com.dmurph.mvc.util;
 
 
A java.util.HashSet that implements com.dmurph.mvc.ICloneable and com.dmurph.mvc.IDirtyable for use with com.dmurph.mvc.model.AbstractDirtyableModel. Unlike the proper implementation of com.dmurph.mvc.IDirtyable, this class will only keep track of if the set is dirty or not, it will not revert changes. TODO implement reverting changes, saving, etc

Author(s):
Daniel Murphy
 
 public class MVCHashSet<E> extends HashSet<E> implements ICloneableIDirtyable{
 	private static final long serialVersionUID = 1L;
 	
 	private boolean dirty = false;
 
 	public boolean add(E e) {
 		 = true;
 		return super.add(e);
 	}

 
 	public void clear() {
 		 = true;
 		super.clear();
 	}

 
 	public boolean remove(Object o) {
 		 = true;
 		return super.remove(o);
 	}

Clones this object, if it can it will clone the objects in the set as well, as long as they implement com.dmurph.mvc.ICloneable. Otherwise it can't copy them, and does a shallow copy.

See also:
com.dmurph.mvc.model.ICloneable.clone();
 
 	public ICloneable clone(){
 		MVCHashSet<E> set = new MVCHashSet<E>();
 		set.cloneFrom(this);
 		return set;
 	}

Clones from the other object, if it can it will clone the objects in the set as well, as long as they implement com.dmurph.mvc.ICloneable. Otherwise it can't copy them, and does a shallow copy.

 
 	@SuppressWarnings("unchecked")
 	public void cloneFrom(ICloneable argOther) {
 		// TODO Auto-generated method stub
 		HashSet<E> other = (HashSet<E>) argOther;
 		clear();
 		
 		for(E thing : other){
			if(thing instanceof ICloneable){
				add((E) ((ICloneablething).clone());
			}else{
				add(thing);
			}
		}
	}

Just sets dirty to false, doesn't revert changes

	public boolean revert() {
		boolean oldDirty = ;
		 = false;
		return oldDirty;
	}

	public boolean isDirty() {
		return ;
	}

Just sets the dirty variable

	public boolean setDirtyboolean argDirty) {
		boolean oldDirty = ;
		 = argDirty;
		return oldDirty;
	}
New to GrepCode? Check out our FAQ X