// Path: airomem-core/src/main/java/pl/setblack/airomem/core/ContextCommand.java
// @FunctionalInterface
// public interface ContextCommand<T, R> extends Serializable {
// 
//     /**
//      * @param system  reference to mutable system
//      * @param context context info (such as date)
//      */
//     R execute(T system, PrevalanceContext context);
// }
// 
// Path: airomem-core/src/main/java/pl/setblack/airomem/core/PrevalanceContext.java
// public class PrevalanceContext {
// 
//     /**
//      * Use this time object whenewer actual time was needed in command.
//      */
//     public final Instant time;
// 
//     public final boolean safe;
// 
//     public PrevalanceContext(final Date date) {
//         this(date.toInstant(), false);
//     }
// 
//     private PrevalanceContext(final Instant time, final boolean safe) {
//         this.time = time;
//         this.safe = safe;
//     }
// 
//     public PrevalanceContext safe() {
//         return new PrevalanceContext(this.time, true);
//     }
// 
//     public PrevalanceContext unsafe() {
//         return new PrevalanceContext(this.time, false);
//     }
// }
// 
// Path: airomem-core/src/main/java/pl/setblack/airomem/core/WriteChecker.java
// public class WriteChecker {
// 
//     private static final ThreadLocal<PrevalanceContext> CONTEXT_STORE = new ThreadLocal<>();
// 
//     public static void setContext(final PrevalanceContext ctx) {
//         assert !hasPrevalanceContext() : "Context was initialized before";
//         CONTEXT_STORE.set(ctx);
//     }
// 
//     public static PrevalanceContext getContext() {
//         return CONTEXT_STORE.get();
//     }
// 
//     public static void clearContext() {
//         assert hasPrevalanceContext() : "Context has to be initialized first";
//         CONTEXT_STORE.remove();
//     }
// 
//     public static boolean hasPrevalanceContext() {
//         return CONTEXT_STORE.get() != null;
//     }
// 
//     public static void enterSafe() {
//         assert hasPrevalanceContext() : "Context has to be initialized first";
//         assert !getContext().safe : "context cannot be safe before";
//         CONTEXT_STORE.set(getContext().safe());
//     }
// 
//     public static void leaveSafe() {
//         assert hasPrevalanceContext() : "Context has to be initialized first";
//         assert getContext().safe : "context must be safe before";
// 
//         CONTEXT_STORE.set(getContext().unsafe());
//     }
// 
// }


import org.prevayler.TransactionWithQuery;
import pl.setblack.airomem.core.ContextCommand;
import pl.setblack.airomem.core.PrevalanceContext;
import pl.setblack.airomem.core.WriteChecker;
import java.io.Serializable;
import java.util.Date;
/* Copyright (c) Jarek Ratajski, Licensed under the Apache License, Version 2.0
 * http://www.apache.org/licenses/LICENSE-2.0 */
package pl.setblack.airomem.core.impl;



/**
 * Class used internally to wrap user Command.
 *
 * @author jarekr
 */
class InternalTransaction<T extends Serializable, R> implements TransactionWithQuery<RoyalFoodTester<T>, R> {

    private static final long serialVersionUID = 1l;

    private final ContextCommand<T, R> cmd;

// Path: airomem-core/src/main/java/pl/setblack/airomem/core/ContextCommand.java
// @FunctionalInterface
// public interface ContextCommand<T, R> extends Serializable {
// 
//     /**
//      * @param system  reference to mutable system
//      * @param context context info (such as date)
//      */
//     R execute(T system, PrevalanceContext context);
// }
// 
// Path: airomem-core/src/main/java/pl/setblack/airomem/core/PrevalanceContext.java
// public class PrevalanceContext {
// 
//     /**
//      * Use this time object whenewer actual time was needed in command.
//      */
//     public final Instant time;
// 
//     public final boolean safe;
// 
//     public PrevalanceContext(final Date date) {
//         this(date.toInstant(), false);
//     }
// 
//     private PrevalanceContext(final Instant time, final boolean safe) {
//         this.time = time;
//         this.safe = safe;
//     }
// 
//     public PrevalanceContext safe() {
//         return new PrevalanceContext(this.time, true);
//     }
// 
//     public PrevalanceContext unsafe() {
//         return new PrevalanceContext(this.time, false);
//     }
// }
// 
// Path: airomem-core/src/main/java/pl/setblack/airomem/core/WriteChecker.java
// public class WriteChecker {
// 
//     private static final ThreadLocal<PrevalanceContext> CONTEXT_STORE = new ThreadLocal<>();
// 
//     public static void setContext(final PrevalanceContext ctx) {
//         assert !hasPrevalanceContext() : "Context was initialized before";
//         CONTEXT_STORE.set(ctx);
//     }
// 
//     public static PrevalanceContext getContext() {
//         return CONTEXT_STORE.get();
//     }
// 
//     public static void clearContext() {
//         assert hasPrevalanceContext() : "Context has to be initialized first";
//         CONTEXT_STORE.remove();
//     }
// 
//     public static boolean hasPrevalanceContext() {
//         return CONTEXT_STORE.get() != null;
//     }
// 
//     public static void enterSafe() {
//         assert hasPrevalanceContext() : "Context has to be initialized first";
//         assert !getContext().safe : "context cannot be safe before";
//         CONTEXT_STORE.set(getContext().safe());
//     }
// 
//     public static void leaveSafe() {
//         assert hasPrevalanceContext() : "Context has to be initialized first";
//         assert getContext().safe : "context must be safe before";
// 
//         CONTEXT_STORE.set(getContext().unsafe());
//     }
// 
// }


// Path: airomem-core/src/main/java/pl/setblack/airomem/core/impl/InternalTransaction.java
import org.prevayler.TransactionWithQuery;
import pl.setblack.airomem.core.ContextCommand;
import pl.setblack.airomem.core.PrevalanceContext;
import pl.setblack.airomem.core.WriteChecker;
import java.io.Serializable;
import java.util.Date;

/* Copyright (c) Jarek Ratajski, Licensed under the Apache License, Version 2.0
 * http://www.apache.org/licenses/LICENSE-2.0 */
package pl.setblack.airomem.core.impl;



/**
 * Class used internally to wrap user Command.
 *
 * @author jarekr
 */
class InternalTransaction<T extends Serializable, R> implements TransactionWithQuery<RoyalFoodTester<T>, R> {

    private static final long serialVersionUID = 1l;

    private final ContextCommand<T, R> cmd;

    InternalTransaction(ContextCommand<T, R> cmd) {