// Path: GroundControl/groundcontrol/src/main/java/com/bottlerocketstudios/groundcontrol/policy/AgentPolicy.java
// public class AgentPolicy {
//     private final String mCallbackLooperId;
//     private final long mPolicyTimeoutMs;
//     private final long mParallelCallbackTimeoutMs;
//     private final long mMaxCacheAgeMs;
//     private final JobPriority mJobPriority;
//     private final boolean mParallelBackgroundCallback;
//     private final boolean mBypassCache;
//     private final boolean mClearCache;
// 
//     public AgentPolicy(AgentPolicyBuilder builder) {
//         mCallbackLooperId = builder.getCallbackLooperId();
//         mPolicyTimeoutMs = builder.getPolicyTimeoutMs();
//         mMaxCacheAgeMs = builder.getMaxCacheAgeMs();
//         mJobPriority = builder.getJobPriority();
//         mParallelBackgroundCallback = builder.isParallelBackgroundCallback();
//         mBypassCache = builder.shouldBypassCache();
//         mParallelCallbackTimeoutMs = builder.getParallelCallbackTimeoutMs();
//         mClearCache = builder.shouldClearCache();
//     }
// 
//     public String getCallbackLooperId() {
//         return mCallbackLooperId;
//     }
// 
//     public long getPolicyTimeoutMs() {
//         return mPolicyTimeoutMs;
//     }
// 
//     public long getMaxCacheAgeMs() {
//         return mMaxCacheAgeMs;
//     }
// 
//     public JobPriority getJobPriority() {
//         return mJobPriority;
//     }
// 
//     public boolean isParallelBackgroundCallback() {
//         return mParallelBackgroundCallback;
//     }
// 
//     public boolean shouldBypassCache() {
//         return mBypassCache;
//     }
// 
//     public long getParallelCallbackTimeoutMs() {
//         return mParallelCallbackTimeoutMs;
//     }
// 
//     public boolean shouldClearCache() {
//         return mClearCache;
//     }
// }
// 
// Path: GroundControl/groundcontrol/src/main/java/com/bottlerocketstudios/groundcontrol/tether/AgentTether.java
// public interface AgentTether {
//     /**
//      * Stop the Agent now, interrupting it if it is running and no other AgentListeners are registered for
//      * identical Agents.
//      */
//     void cancel();
// 
//     /**
//      * Unregister interest in the result of the Agent, but let it complete. This should be used in
//      * most cases of short-running requests that wouldn't hurt to complete or in the event of
//      * device rotation.
//      */
//     void release();
// 
//     /**
//      * Return the agent identifier associated with this agent tether
//      */
//     String getAgentIdentifier();
// }
// 
// Path: GroundControl/groundcontrol/src/main/java/com/bottlerocketstudios/groundcontrol/tether/UIAgentTetherCollection.java
// public class UIAgentTetherCollection {
// 
//     private static final String TAG = UIAgentTetherCollection.class.getSimpleName();
// 
//     private boolean mDestroyCalled;
// 
//     private final List<AgentTether> mAgentTetherList;
// 
//     public UIAgentTetherCollection() {
//         mAgentTetherList = new ArrayList<>();
//     }
// 
//     public boolean isDestroyed() {
//         return mDestroyCalled;
//     }
// 
//     public void addTether(AgentTether agentTether) {
//         if (agentTether != null) mAgentTetherList.add(agentTether);
//     }
// 
//     public void addAllTethers(Collection<AgentTether> agentTetherCollection) {
//         mAgentTetherList.addAll(agentTetherCollection);
//     }
// 
//     public void removeTether(AgentTether agentTether) {
//         mAgentTetherList.remove(agentTether);
//     }
// 
//     /**
//      * Release all held tethers.
//      */
//     public void destroy() {
//         for (AgentTether agentTether : mAgentTetherList) {
//             agentTether.release();
//         }
//         mAgentTetherList.clear();
//         mDestroyCalled = true;
//     }
// 
//     @Override
//     protected void finalize() throws Throwable {
//         super.finalize();
//         if (!isDestroyed()) {
//             destroy();
//             Log.e(TAG, "Object was finalized without a call to destroy()");
//         }
//     }
// }


import com.bottlerocketstudios.groundcontrol.policy.AgentPolicy;
import com.bottlerocketstudios.groundcontrol.tether.AgentTether;
import com.bottlerocketstudios.groundcontrol.tether.UIAgentTetherCollection;
import java.util.HashMap;
import java.util.Map;
import java.util.WeakHashMap;
/*
 * Copyright (c) 2016. Bottle Rocket LLC
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.bottlerocketstudios.groundcontrol.convenience;



/**
 * Holder for UI related information for a single AgentExecutor.
 */
public class UiInformationContainer {
    private final WeakHashMap<Object, UIAgentTetherCollection> mUIAgentTetherCollectionMap = new WeakHashMap<>();
    private final Map<String, OneTimeInformation> mOneTimeInformationMap = new HashMap<>();

    public void storeTether(Object uiObject, AgentTether agentTether) {
        UIAgentTetherCollection uiAgentTetherCollection = mUIAgentTetherCollectionMap.get(uiObject);
        if (uiAgentTetherCollection == null) {
            uiAgentTetherCollection = new UIAgentTetherCollection();
            mUIAgentTetherCollectionMap.put(uiObject, uiAgentTetherCollection);
        }
        uiAgentTetherCollection.addTether(agentTether);
    }

    public void onDestroy(Object uiObject) {
// Path: GroundControl/groundcontrol/src/main/java/com/bottlerocketstudios/groundcontrol/policy/AgentPolicy.java
// public class AgentPolicy {
//     private final String mCallbackLooperId;
//     private final long mPolicyTimeoutMs;
//     private final long mParallelCallbackTimeoutMs;
//     private final long mMaxCacheAgeMs;
//     private final JobPriority mJobPriority;
//     private final boolean mParallelBackgroundCallback;
//     private final boolean mBypassCache;
//     private final boolean mClearCache;
// 
//     public AgentPolicy(AgentPolicyBuilder builder) {
//         mCallbackLooperId = builder.getCallbackLooperId();
//         mPolicyTimeoutMs = builder.getPolicyTimeoutMs();
//         mMaxCacheAgeMs = builder.getMaxCacheAgeMs();
//         mJobPriority = builder.getJobPriority();
//         mParallelBackgroundCallback = builder.isParallelBackgroundCallback();
//         mBypassCache = builder.shouldBypassCache();
//         mParallelCallbackTimeoutMs = builder.getParallelCallbackTimeoutMs();
//         mClearCache = builder.shouldClearCache();
//     }
// 
//     public String getCallbackLooperId() {
//         return mCallbackLooperId;
//     }
// 
//     public long getPolicyTimeoutMs() {
//         return mPolicyTimeoutMs;
//     }
// 
//     public long getMaxCacheAgeMs() {
//         return mMaxCacheAgeMs;
//     }
// 
//     public JobPriority getJobPriority() {
//         return mJobPriority;
//     }
// 
//     public boolean isParallelBackgroundCallback() {
//         return mParallelBackgroundCallback;
//     }
// 
//     public boolean shouldBypassCache() {
//         return mBypassCache;
//     }
// 
//     public long getParallelCallbackTimeoutMs() {
//         return mParallelCallbackTimeoutMs;
//     }
// 
//     public boolean shouldClearCache() {
//         return mClearCache;
//     }
// }
// 
// Path: GroundControl/groundcontrol/src/main/java/com/bottlerocketstudios/groundcontrol/tether/AgentTether.java
// public interface AgentTether {
//     /**
//      * Stop the Agent now, interrupting it if it is running and no other AgentListeners are registered for
//      * identical Agents.
//      */
//     void cancel();
// 
//     /**
//      * Unregister interest in the result of the Agent, but let it complete. This should be used in
//      * most cases of short-running requests that wouldn't hurt to complete or in the event of
//      * device rotation.
//      */
//     void release();
// 
//     /**
//      * Return the agent identifier associated with this agent tether
//      */
//     String getAgentIdentifier();
// }
// 
// Path: GroundControl/groundcontrol/src/main/java/com/bottlerocketstudios/groundcontrol/tether/UIAgentTetherCollection.java
// public class UIAgentTetherCollection {
// 
//     private static final String TAG = UIAgentTetherCollection.class.getSimpleName();
// 
//     private boolean mDestroyCalled;
// 
//     private final List<AgentTether> mAgentTetherList;
// 
//     public UIAgentTetherCollection() {
//         mAgentTetherList = new ArrayList<>();
//     }
// 
//     public boolean isDestroyed() {
//         return mDestroyCalled;
//     }
// 
//     public void addTether(AgentTether agentTether) {
//         if (agentTether != null) mAgentTetherList.add(agentTether);
//     }
// 
//     public void addAllTethers(Collection<AgentTether> agentTetherCollection) {
//         mAgentTetherList.addAll(agentTetherCollection);
//     }
// 
//     public void removeTether(AgentTether agentTether) {
//         mAgentTetherList.remove(agentTether);
//     }
// 
//     /**
//      * Release all held tethers.
//      */
//     public void destroy() {
//         for (AgentTether agentTether : mAgentTetherList) {
//             agentTether.release();
//         }
//         mAgentTetherList.clear();
//         mDestroyCalled = true;
//     }
// 
//     @Override
//     protected void finalize() throws Throwable {
//         super.finalize();
//         if (!isDestroyed()) {
//             destroy();
//             Log.e(TAG, "Object was finalized without a call to destroy()");
//         }
//     }
// }


// Path: GroundControl/groundcontrol/src/main/java/com/bottlerocketstudios/groundcontrol/convenience/UiInformationContainer.java
import com.bottlerocketstudios.groundcontrol.policy.AgentPolicy;
import com.bottlerocketstudios.groundcontrol.tether.AgentTether;
import com.bottlerocketstudios.groundcontrol.tether.UIAgentTetherCollection;
import java.util.HashMap;
import java.util.Map;
import java.util.WeakHashMap;

/*
 * Copyright (c) 2016. Bottle Rocket LLC
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.bottlerocketstudios.groundcontrol.convenience;



/**
 * Holder for UI related information for a single AgentExecutor.
 */
public class UiInformationContainer {
    private final WeakHashMap<Object, UIAgentTetherCollection> mUIAgentTetherCollectionMap = new WeakHashMap<>();
    private final Map<String, OneTimeInformation> mOneTimeInformationMap = new HashMap<>();

    public void storeTether(Object uiObject, AgentTether agentTether) {
        UIAgentTetherCollection uiAgentTetherCollection = mUIAgentTetherCollectionMap.get(uiObject);
        if (uiAgentTetherCollection == null) {
            uiAgentTetherCollection = new UIAgentTetherCollection();
            mUIAgentTetherCollectionMap.put(uiObject, uiAgentTetherCollection);
        }
        uiAgentTetherCollection.addTether(agentTether);
    }

    public void onDestroy(Object uiObject) {
        UIAgentTetherCollection uiAgentTetherCollection = mUIAgentTetherCollectionMap.get(uiObject);