/*
 * 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.ILocks;

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

    public final ILocks<K> mLocks;
    private C mContents = null;

    public LockableContainer(final ILocks<K> locks) {
        mLocks = locks;
    };

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

    @Override
    public final C triedTakenContents() {
        return canTakeContents() ? takenContents() : null;
    }

    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 C takenContents() {
        final C contents = mContents;
        clearContents();
        return contents;
    }

    private void clearContents() {
        mContents = null;
    }

};

@@ -416,24 +416,25 @@
 %3CK%3E mLocks;%0A
+%0A
     private 
@@ -433,16 +433,52 @@
 private 
+final C mNullContents;%0A%0A    private 
 C mConte
@@ -480,23 +480,16 @@
 Contents
- = null
 ;%0A%0A    p
@@ -512,16 +512,29 @@
 ntainer(
+%0A            
 final IL
@@ -550,33 +550,141 @@
 ocks
-) %7B%0A        mLocks = lock
+, final C contents, final C nullContents) %7B%0A        mLocks = locks;%0A        mContents = contents;%0A        mNullContents = nullContent
 s;%0A 
@@ -715,22 +715,16 @@
  public 
-final 
 void try
@@ -784,16 +784,30 @@
 tents())
+ %7B%0A           
  putCont
@@ -822,16 +822,26 @@
 tents);%0A
+        %7D%0A
     %7D%0A%0A 
@@ -864,22 +864,16 @@
  public 
-final 
 C triedT
@@ -942,20 +942,29 @@
 nts() : 
-n
+mN
 ull
+Contents
 ;%0A    %7D%0A
@@ -1300,20 +1300,29 @@
 ents == 
-n
+mN
 ull
+Contents
 ;%0A    %7D;
@@ -1401,21 +1401,19 @@
         
-clear
+put
 Contents
@@ -1417,102 +1417,47 @@
 nts(
-);%0A        return c
+mNullC
 ontents
+)
 ;%0A    
-%7D%0A%0A
     
-private void clearContents() %7B%0A        mContents = null
+return contents
 ;%0A  

Update LockableContainer.java