001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.increment;
016    
017    import com.liferay.portal.kernel.concurrent.IncreasableEntry;
018    import com.liferay.portal.kernel.increment.Increment;
019    
020    import org.aopalliance.intercept.MethodInterceptor;
021    import org.aopalliance.intercept.MethodInvocation;
022    
023    /**
024     * @author Zsolt Berentey
025     */
026    public class BufferedIncreasableEntry<K, T>
027            extends IncreasableEntry<K, Increment<T>> {
028    
029            public BufferedIncreasableEntry(
030                    MethodInterceptor nextInterceptor, MethodInvocation methodInvocation,
031                    K key, Increment<T> value) {
032    
033                    super(key, value);
034    
035                    _methodInvocation = methodInvocation;
036                    _nextInterceptor = nextInterceptor;
037            }
038    
039            @Override
040            public Increment<T> doIncrease(
041                    Increment<T> originalValue, Increment<T> deltaValue) {
042    
043                    return originalValue.increaseForNew(deltaValue.getValue());
044            }
045    
046            public void proceed() throws Throwable {
047                    Object[] arguments = _methodInvocation.getArguments();
048    
049                    arguments[arguments.length - 1] = getValue().getValue();
050    
051                    _nextInterceptor.invoke(_methodInvocation);
052            }
053    
054            @Override
055            public String toString() {
056                    return _methodInvocation.toString();
057            }
058    
059            private MethodInvocation _methodInvocation;
060            private MethodInterceptor _nextInterceptor;
061    
062    }