1 23 24 package org.apache.slide.event; 25 26 import java.util.List ; 27 import java.util.Iterator ; 28 import java.util.ArrayList ; 29 30 33 34 public class EventCollectionFilter { 35 public static ContentEvent[] getChangedContents(EventCollection collection) { 36 List changedContents = new ArrayList (); 37 if (collection != null) 38 { 39 List collectedEvents = collection.getCollection(); 40 for ( Iterator i = collectedEvents.iterator(); i.hasNext(); ) { 41 EventCollection.Event event = (EventCollection.Event)i.next(); 42 if ( event.getMethod() == ContentEvent.STORE ) { 43 removeContentEvents(changedContents, ((ContentEvent)event.getEvent()).getUri()); 44 changedContents.add(event.getEvent()); 45 } else if ( event.getMethod() == ContentEvent.REMOVE ) { 46 removeContentEvents(changedContents, ((ContentEvent)event.getEvent()).getUri()); 47 } 48 } 49 } 50 ContentEvent[] changedContentEvents = new ContentEvent[changedContents.size()]; 51 return (ContentEvent [])changedContents.toArray(changedContentEvents); 52 } 53 54 public static ContentEvent[] getCreatedContents(EventCollection collection) { 55 List changedContents = new ArrayList (); 56 if (collection != null) 57 { 58 List collectedEvents = collection.getCollection(); 59 for ( Iterator i = collectedEvents.iterator(); i.hasNext(); ) { 60 EventCollection.Event event = (EventCollection.Event)i.next(); 61 if ( event.getMethod() == ContentEvent.CREATE ) { 62 removeContentEvents(changedContents, ((ContentEvent)event.getEvent()).getUri()); 63 changedContents.add(event.getEvent()); 64 } else if ( event.getMethod() == ContentEvent.REMOVE ) { 65 removeContentEvents(changedContents, ((ContentEvent)event.getEvent()).getUri()); 66 } 67 } 68 } 69 ContentEvent[] changedContentEvents = new ContentEvent[changedContents.size()]; 70 return (ContentEvent [])changedContents.toArray(changedContentEvents); 71 } 72 73 public static ContentEvent[] getRemovedContents(EventCollection collection) { 74 List changedContents = new ArrayList (); 75 if (collection != null) 76 { 77 List collectedEvents = collection.getCollection(); 78 for ( Iterator i = collectedEvents.iterator(); i.hasNext(); ) { 79 EventCollection.Event event = (EventCollection.Event)i.next(); 80 if ( event.getMethod() == ContentEvent.REMOVE ) { 81 removeContentEvents(changedContents, ((ContentEvent)event.getEvent()).getUri()); 82 changedContents.add(event.getEvent()); 83 } else if ( event.getMethod() == ContentEvent.CREATE || event.getMethod() == ContentEvent.STORE ) { 84 removeContentEvents(changedContents, ((ContentEvent)event.getEvent()).getUri()); 85 } 86 } 87 } 88 ContentEvent[] changedContentEvents = new ContentEvent[changedContents.size()]; 89 return (ContentEvent [])changedContents.toArray(changedContentEvents); 90 } 91 92 private static void removeContentEvents(List changedContents, String uri) { 93 for ( Iterator i = changedContents.iterator(); i.hasNext(); ) { 94 ContentEvent event = (ContentEvent)i.next(); 95 if ( ((ContentEvent)event).getUri().equals(uri) ) { 96 i.remove(); 97 } 98 } 99 } 100 } | Popular Tags |