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.MethodInvocation;
021    
022    /**
023     * @author Zsolt Berentey
024     */
025    public class BufferedIncreasableEntry<K, T>
026            extends IncreasableEntry<K, Increment<T>> {
027    
028            public BufferedIncreasableEntry(
029                    MethodInvocation methodInvocation, K key, Increment<T> value) {
030    
031                    super(key, value);
032    
033                    _methodInvocation = methodInvocation;
034            }
035    
036            @Override
037            public Increment<T> doIncrease(
038                    Increment<T> originalValue, Increment<T> deltaValue) {
039    
040                    return originalValue.increaseForNew(deltaValue.getValue());
041            }
042    
043            public void proceed() throws Throwable {
044                    Object[] arguments = _methodInvocation.getArguments();
045    
046                    arguments[arguments.length - 1] = getValue().getValue();
047    
048                    _methodInvocation.proceed();
049            }
050    
051            @Override
052            public String toString() {
053                    return _methodInvocation.toString();
054            }
055    
056            private MethodInvocation _methodInvocation;
057    
058    }