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.model;
 
 
A fully implemented java.util.HashSet, pretty much exactly like MVCArrayList.

Author(s):
Daniel Murphy
 
 public class MVCHashSet<E> extends HashSet<E> implements IModelICloneableIDirtyableIRevertible{
 	private static final long serialVersionUID = 1L;

Array size property name for listening to property change events

 
 	public static final String SIZE = "HASH_SET_SIZE";

Not exactly a property, but the name of the property when an element is removed from the set.
 
 	public static final String REMOVED = "HASH_SET_REMOVED";

Not exactly a property, but the name of the property when an element is added or inserted into the set.
 
 	public static final String ADDED = "HASH_SET_ADDED";
 	
 	private boolean dirty = false;
 	private final HashSet<E> saved = new HashSet<E>();
 	
 		public void propertyChange(PropertyChangeEvent argEvt) {
 				if(argEvt.getNewValue() == .){
 				}
 			}
 		}
 	};
     
     private void addListener(Object argObject){
 		if(argObject instanceof IModel){
 		}
 	}
 	
 	private void removeListener(Object argObject){
 		if(argObject instanceof IModel){
 		}
 	}

 
     public void addPropertyChangeListener(PropertyChangeListener argListener) {
         .addPropertyChangeListener(argListener);
     }

    
 
    public void removePropertyChangeListener(PropertyChangeListener argListener) {
    }
    private void firePropertyChange(String argPropertyNameObject argOldValueObject argNewValue) {
        .firePropertyChange(argPropertyNameargOldValueargNewValue);
    }
	public synchronized boolean add(E e) {
		boolean ret = super.add(e);
		boolean old = ;
		 = true;
		return ret;
	}
	private final HashSet<E> temp = new HashSet<E>();
	public synchronized void clear() {
		if(size() > 0){
			int oldSize = size();
			.addAll(this);
			super.clear();
			Iterator<E> it = .iterator();
			while(it.hasNext()){
e = it.next();
			}
			firePropertyChange(oldSize, 0);
			boolean old = ;
			 = true;
		}
	}
	public synchronized boolean remove(Object o) {
		boolean ret = super.remove(o);
		if(ret){
			boolean old = ;
			 = true;
		}
		return ret;
	}
	// do shallow clone, need to keep object references
	private void setFromSaved(){
		for(E e){
			add(e);
		}
	}
	// do shallow clone, need to keep object references
	private void setToSaved(){
		for(E ethis){
		}
	}

Clones from another java.util.ArrayList, if the values are com.dmurph.mvc.ICloneable, then they will be cloned to this one. Otherwise it's a shallow copy (just sets the same values).

	@SuppressWarnings("unchecked")
	public synchronized void cloneFromICloneable argOther) {
		MVCHashSet<E> other = (MVCHashSet<E>) argOther;
		for(E e : other){
		}
		for(E e : other.saved){
		}
		this. = other.dirty;
	}

Default just calls com.dmurph.mvc.ICloneable.clone(), but override to protect against loops (if the property tree goes in a loop).

Parameters:
argObject
Returns:
	@SuppressWarnings("unchecked")
	protected E cloneImpl(E argObject){
		if(argObject instanceof ICloneable){
			return (E) ((ICloneableargObject).clone();
		}else{
			return argObject;
		}
	}

Clones this object to another MVCArrayList. If the array values are also com.dmurph.mvc.ICloneable, then they will be cloned as well. If not, the values are just set (shallow copy).

	public synchronized ICloneable clone(){
		MVCArrayList<E> other = new MVCArrayList<E>();
		other.cloneFrom(this);
		return other;
	}

Also checks to see if elements in this array are dirty, if any are com.dmurph.mvc.IDirtyable.

	public synchronized boolean isDirty() {
		if(){
			return true;
		}
		for(E e : this){
			if(e instanceof IDirtyable){
					return true;
				}
			}
		}
		return false;
	}

Default just calls com.dmurph.mvc.IDirtyable.isDirty(), but override to protect against loops (if the property tree goes in a loop).

Returns:
	protected boolean isDirtyImpl(E argE){
		if(argE instanceof IDirtyable){
			if(((IDirtyableargE).isDirty()){
				return true;
			}
		}
		return false;
	}

Sets the dirty variable and, if argDirty is false, then will call com.dmurph.mvc.IDirtyable.setDirty(boolean) on all com.dmurph.mvc.IDirtyable objects in this array.

	public synchronized boolean setDirtyboolean argDirty) {
		boolean oldDirty = ;
		 = argDirty;
		if(!){
			for(E ethis){
				setDirtyImpl(efalse);
			}
		}
		return oldDirty;
	}

Default just calls com.dmurph.mvc.IDirtyable.setDirty(boolean), but override to protect against loops (if the property tree goes in a loop).

Parameters:
argE
argDirty
	protected void setDirtyImpl(E argEboolean argDirty){
		if(argE instanceof IDirtyable){
			((IDirtyableargE).setDirty(argDirty);
		}
	}

	public synchronized boolean revertChanges() {
		if(!isDirty()){
			return false;
		}
		for(E ethis){
		}
		return true;
	}

Default just calls com.dmurph.mvc.IRevertible.revertChanges(), but override to protect against loops (if the property tree goes in a loop).
	protected void revertChangesImpl(E argE){
		if(argE instanceof IRevertible){
		}
	}

Also calls IRevertable#saveChanges() on all objects in the reverted array that are com.dmurph.mvc.IRevertible.

	public synchronized boolean saveChanges() {
		if(!isDirty()){
			return false;
		}
		for(E ethis){
		}
		return true;
	}

Default just calls com.dmurph.mvc.IRevertible.saveChanges(), but override to protect against loops (if the property tree goes in a loop).
	protected void saveChangesImpl(E argE){
		if(argE instanceof IRevertible){
		}
	}
New to GrepCode? Check out our FAQ X