001    /**
002     * Copyright (c) 2000-present 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.kernel.concurrent;
016    
017    import com.liferay.portal.kernel.util.HashUtil;
018    import com.liferay.portal.kernel.util.StringBundler;
019    
020    import java.util.Objects;
021    
022    /**
023     * @author Shuyang Zhou
024     */
025    public abstract class IncreasableEntry<K, V> {
026    
027            public IncreasableEntry(K key, V value) {
028                    this.key = key;
029                    this.value = value;
030            }
031    
032            @Override
033            public boolean equals(Object obj) {
034                    if (this == obj) {
035                            return true;
036                    }
037    
038                    if (!(obj instanceof IncreasableEntry<?, ?>)) {
039                            return false;
040                    }
041    
042                    IncreasableEntry<K, V> increasableEntry = (IncreasableEntry<K, V>)obj;
043    
044                    if (Objects.equals(key, increasableEntry.key) &&
045                            Objects.equals(value, increasableEntry.value)) {
046    
047                            return true;
048                    }
049    
050                    return false;
051            }
052    
053            public K getKey() {
054                    return key;
055            }
056    
057            public V getValue() {
058                    return value;
059            }
060    
061            @Override
062            public int hashCode() {
063                    int hash = HashUtil.hash(0, key);
064    
065                    return HashUtil.hash(hash, value);
066            }
067    
068            public abstract IncreasableEntry<K, V> increase(V deltaValue);
069    
070            @Override
071            public String toString() {
072                    StringBundler sb = new StringBundler(5);
073    
074                    sb.append("{key=");
075                    sb.append(key);
076                    sb.append(", value=");
077                    sb.append(value);
078                    sb.append("}");
079    
080                    return sb.toString();
081            }
082    
083            protected final K key;
084            protected final V value;
085    
086    }