// Path: myeslib-core/src/main/java/org/myeslib/core/data/AggregateRootHistory.java
// @SuppressWarnings("serial")
// @Data
// public class AggregateRootHistory implements Serializable {
// 
// 	private final List<UnitOfWork> unitsOfWork;
// 	private final Set<UnitOfWork> persisted;
// 
// 	public AggregateRootHistory() {
// 		this.unitsOfWork = new LinkedList<>();
// 		this.persisted = new LinkedHashSet<>();
// 	}
// 
// 	public List<Event> getAllEvents() {
//        return getEventsAfterUntil(0, Long.MAX_VALUE);
// 	}
// 
// 	public List<Event> getEventsAfterUntil(long afterVersion, long untilVersion){
// 		List<Event> events = new LinkedList<>();
// 		for (UnitOfWork t : unitsOfWork) {
// 			if (t.getVersion() > afterVersion && t.getVersion() <= untilVersion){
// 				for (Event event : t.getEvents()) {
// 					events.add(event);
// 				}
// 			}
// 		}
// 		return events;
// 	}
// 	
// 	public List<Event> getEventsUntil(long version){
// 		List<Event> events = new LinkedList<>();
// 		for (UnitOfWork t : unitsOfWork) {
// 			if (t.getVersion() <= version){
// 				for (Event event : t.getEvents()) {
// 					events.add(event);
// 				}
// 			}
// 		}
// 		return events;
// 	}
// 	
// 	public Long getLastVersion() {
// 		return unitsOfWork.size()==0 ? 0 : unitsOfWork.get(unitsOfWork.size()-1).getVersion();
// 	}
// 
// 	public void add(final UnitOfWork transaction) {
// 		checkNotNull(transaction);
// 		unitsOfWork.add(transaction);
// 	}
// 
// 	public UnitOfWork getLastUnitOfWork() {
// 		return unitsOfWork.get(unitsOfWork.size()-1);
// 	}
// 
//     public List<UnitOfWork> getPendingOfPersistence() {
//         return Lists.newLinkedList(Sets.difference(Sets.newLinkedHashSet(unitsOfWork), persisted));
//     }
// 
//     public void markAsPersisted(UnitOfWork uow) {
//         checkArgument(unitsOfWork.contains(uow), "unitOfWork must be part of this AggregateRootHistory in order to be marked as persisted");
//         persisted.add(uow);
//     }
// 
// }
// 
// Path: myeslib-core/src/main/java/org/myeslib/core/data/UnitOfWork.java
// @SuppressWarnings("serial")
// @Value
// public class UnitOfWork implements Comparable<UnitOfWork>, Serializable {
// 
//     final UUID id;
// 	final Command command;
// 	final List<? extends Event> events;
// 	final long version;
// 	
// 	public UnitOfWork(UUID id, Command command, Long version, List<? extends Event> events) {
// 	    checkNotNull(id, "id cannot be null");
// 	    checkNotNull(command, "command cannot be null");
// 		checkArgument(command.getTargetVersion()>=0, "target version must be >= 0");
// 		checkArgument(version>0, "invalid version");
// 		checkNotNull(events, "events cannot be null");
// 		for (Event e: events){
// 			checkNotNull(e, "event within events list cannot be null");
// 		}
// 		this.id = id;
// 		this.command = command;
// 		this.version = version;
// 		this.events = events;
// 	}
// 	
// 	public static UnitOfWork create(UUID id, Command command, List<? extends Event> newEvents) {
// 		checkNotNull(command.getTargetVersion(), "target version cannot be null");
// 		checkArgument(command.getTargetVersion()>=0, "target version must be >= 0");
// 		return new UnitOfWork(id, command, command.getTargetVersion()+1, newEvents);
// 	}
// 	
// 	public List<Event> getEvents(){
// 		List<Event> result = new LinkedList<>();
// 		for (Event event : events) {
// 			result.add(event);
// 		}
// 		return result;
// 	}
// 	
// 	public int compareTo(UnitOfWork other) {
// 		if (version < other.version) {
// 			return -1;
// 		} else if (version > other.version) {
// 			return 1;
// 		}
// 		return 0;
// 	}
// 
// 	public Long getTargetVersion() {
// 		return command.getTargetVersion();
// 	}
// }
// 
// Path: myeslib-core/src/main/java/org/myeslib/core/storage/UnitOfWorkJournal.java
// public interface UnitOfWorkJournal<K> {
// 
// 	public void append(final K id, final UnitOfWork uow) ;
// 	
// }


import static com.google.common.base.Preconditions.checkNotNull;
import java.util.ConcurrentModificationException;
import lombok.extern.slf4j.Slf4j;
import org.myeslib.core.data.AggregateRootHistory;
import org.myeslib.core.data.UnitOfWork;
import org.myeslib.core.storage.UnitOfWorkJournal;
import com.google.inject.Inject;
import com.hazelcast.core.IMap;
package org.myeslib.hazelcast.storage;






@Slf4j
public class HzUnitOfWorkJournal<K> implements UnitOfWorkJournal<K> {

// Path: myeslib-core/src/main/java/org/myeslib/core/data/AggregateRootHistory.java
// @SuppressWarnings("serial")
// @Data
// public class AggregateRootHistory implements Serializable {
// 
// 	private final List<UnitOfWork> unitsOfWork;
// 	private final Set<UnitOfWork> persisted;
// 
// 	public AggregateRootHistory() {
// 		this.unitsOfWork = new LinkedList<>();
// 		this.persisted = new LinkedHashSet<>();
// 	}
// 
// 	public List<Event> getAllEvents() {
//        return getEventsAfterUntil(0, Long.MAX_VALUE);
// 	}
// 
// 	public List<Event> getEventsAfterUntil(long afterVersion, long untilVersion){
// 		List<Event> events = new LinkedList<>();
// 		for (UnitOfWork t : unitsOfWork) {
// 			if (t.getVersion() > afterVersion && t.getVersion() <= untilVersion){
// 				for (Event event : t.getEvents()) {
// 					events.add(event);
// 				}
// 			}
// 		}
// 		return events;
// 	}
// 	
// 	public List<Event> getEventsUntil(long version){
// 		List<Event> events = new LinkedList<>();
// 		for (UnitOfWork t : unitsOfWork) {
// 			if (t.getVersion() <= version){
// 				for (Event event : t.getEvents()) {
// 					events.add(event);
// 				}
// 			}
// 		}
// 		return events;
// 	}
// 	
// 	public Long getLastVersion() {
// 		return unitsOfWork.size()==0 ? 0 : unitsOfWork.get(unitsOfWork.size()-1).getVersion();
// 	}
// 
// 	public void add(final UnitOfWork transaction) {
// 		checkNotNull(transaction);
// 		unitsOfWork.add(transaction);
// 	}
// 
// 	public UnitOfWork getLastUnitOfWork() {
// 		return unitsOfWork.get(unitsOfWork.size()-1);
// 	}
// 
//     public List<UnitOfWork> getPendingOfPersistence() {
//         return Lists.newLinkedList(Sets.difference(Sets.newLinkedHashSet(unitsOfWork), persisted));
//     }
// 
//     public void markAsPersisted(UnitOfWork uow) {
//         checkArgument(unitsOfWork.contains(uow), "unitOfWork must be part of this AggregateRootHistory in order to be marked as persisted");
//         persisted.add(uow);
//     }
// 
// }
// 
// Path: myeslib-core/src/main/java/org/myeslib/core/data/UnitOfWork.java
// @SuppressWarnings("serial")
// @Value
// public class UnitOfWork implements Comparable<UnitOfWork>, Serializable {
// 
//     final UUID id;
// 	final Command command;
// 	final List<? extends Event> events;
// 	final long version;
// 	
// 	public UnitOfWork(UUID id, Command command, Long version, List<? extends Event> events) {
// 	    checkNotNull(id, "id cannot be null");
// 	    checkNotNull(command, "command cannot be null");
// 		checkArgument(command.getTargetVersion()>=0, "target version must be >= 0");
// 		checkArgument(version>0, "invalid version");
// 		checkNotNull(events, "events cannot be null");
// 		for (Event e: events){
// 			checkNotNull(e, "event within events list cannot be null");
// 		}
// 		this.id = id;
// 		this.command = command;
// 		this.version = version;
// 		this.events = events;
// 	}
// 	
// 	public static UnitOfWork create(UUID id, Command command, List<? extends Event> newEvents) {
// 		checkNotNull(command.getTargetVersion(), "target version cannot be null");
// 		checkArgument(command.getTargetVersion()>=0, "target version must be >= 0");
// 		return new UnitOfWork(id, command, command.getTargetVersion()+1, newEvents);
// 	}
// 	
// 	public List<Event> getEvents(){
// 		List<Event> result = new LinkedList<>();
// 		for (Event event : events) {
// 			result.add(event);
// 		}
// 		return result;
// 	}
// 	
// 	public int compareTo(UnitOfWork other) {
// 		if (version < other.version) {
// 			return -1;
// 		} else if (version > other.version) {
// 			return 1;
// 		}
// 		return 0;
// 	}
// 
// 	public Long getTargetVersion() {
// 		return command.getTargetVersion();
// 	}
// }
// 
// Path: myeslib-core/src/main/java/org/myeslib/core/storage/UnitOfWorkJournal.java
// public interface UnitOfWorkJournal<K> {
// 
// 	public void append(final K id, final UnitOfWork uow) ;
// 	
// }


// Path: myeslib-hazelcast/src/main/java/org/myeslib/hazelcast/storage/HzUnitOfWorkJournal.java
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.ConcurrentModificationException;
import lombok.extern.slf4j.Slf4j;
import org.myeslib.core.data.AggregateRootHistory;
import org.myeslib.core.data.UnitOfWork;
import org.myeslib.core.storage.UnitOfWorkJournal;
import com.google.inject.Inject;
import com.hazelcast.core.IMap;

package org.myeslib.hazelcast.storage;






@Slf4j
public class HzUnitOfWorkJournal<K> implements UnitOfWorkJournal<K> {

	private final IMap<K, AggregateRootHistory> pastTransactionsMap ;