@@ -0,0 +1,1224 @@
+/*%0A * To change this license header, choose License Headers in Project Properties.%0A * To change this template file, choose Tools %7C Templates%0A * and open the template in the editor.%0A */%0Apackage doublex.lib.lockableContainers;%0A%0Aimport doublex.lib.locks.Locks;%0A%0A/**%0A *%0A * @author kenneth.lau%0A * @param %3CC%3E%0A * @param %3CK%3E%0A */%0Apublic final class LockableContainer%3CC, K%3E implements IContainable%3CC%3E  %7B%0A%0A    public final Locks%3CK%3E mLocks = new Locks%3C%3E();%0A%0A    private C mContents = null;%0A%0A    @Override%0A    public final void tryPutContents(final C contents) %7B%0A        if (canPutContents()) putContents(contents);%0A    %7D%0A%0A    @Override%0A    public final C tryTakeContents() %7B%0A        if (!canTakeContents()) return null;%0A        final C contents = mContents;%0A        clearContents();%0A        return contents;%0A    %7D%0A%0A    private boolean canPutContents() %7B%0A        return !mLocks.isLocked() && isEmpty();%0A    %7D%0A%0A    private void putContents(final C contents) %7B%0A        mContents = contents;%0A    %7D%0A%0A    private boolean canTakeContents() %7B%0A        return !mLocks.isLocked() && !isEmpty();%0A    %7D%0A%0A    private boolean isEmpty() %7B%0A        return mContents == null;%0A    %7D;%0A%0A    private void clearContents() %7B%0A        mContents = null;%0A    %7D%0A%0A%7D;%0A

Create LockableContainer.java