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