/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package doublex.lib.lockableContainers;

import doublex.lib.locks.Locks;

/**
 *
 * @author kenneth.lau
 * @param <C>
 * @param <K>
 */
public final class LockableContainer<C, K> implements IContainable<C>  {

    public final Locks<K> mLocks = new Locks<>();

    private C mContents = null;

    @Override
    public final void tryPutContents(final C contents) {
        if (canPutContents()) putContents(contents);
    }

    @Override
    public final C tryTakeContents() {
        if (!canTakeContents()) return null;
        final C contents = mContents;
        clearContents();
        return contents;
    }

    private boolean canPutContents() {
        return !mLocks.isLocked() && isEmpty();
    }

    private void putContents(final C contents) {
        mContents = contents;
    }

    private boolean canTakeContents() {
        return !mLocks.isLocked() && !isEmpty();
    }

    private boolean isEmpty() {
        return mContents == null;
    };

    private void clearContents() {
        mContents = null;
    }

};

@@ -274,19 +274,15 @@
 hor 
-kenneth.lau
+DoubleX
 %0A * 
@@ -638,13 +638,16 @@
 C tr
-y
+ied
 Take
+n
 Cont
@@ -712,86 +712,30 @@
     
-final C contents = mContents;%0A        clearContents();%0A        return contents
+return takenContents()
 ;%0A  
@@ -1085,16 +1085,16 @@
 ll;%0A
-
     %7D;%0A%0A
     
@@ -1089,16 +1089,143 @@
     %7D;%0A%0A
+    private C takenContents() %7B%0A        final C contents = mContents;%0A        clearContents();%0A        return contents;%0A    %7D%0A%0A
     priv

Update LockableContainer.java