001    /*
002     * Copyright 2010-2015 JetBrains s.r.o.
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    
017    package org.jetbrains.kotlin.util.slicedMap;
018    
019    import org.jetbrains.annotations.NotNull;
020    
021    public final class SlicedMapKey<K, V> {
022    
023        private final WritableSlice<K, V> slice;
024        private final K key;
025    
026        public SlicedMapKey(@NotNull WritableSlice<K, V> slice, K key) {
027            this.slice = slice;
028            this.key = key;
029        }
030    
031        public WritableSlice<K, V> getSlice() {
032            return slice;
033        }
034    
035        public K getKey() {
036            return key;
037        }
038    
039        @Override
040        public boolean equals(Object o) {
041            if (this == o) return true;
042            if (!(o instanceof SlicedMapKey)) return false;
043    
044            SlicedMapKey that = (SlicedMapKey) o;
045    
046            if (key != null ? !key.equals(that.key) : that.key != null) return false;
047            if (!slice.equals(that.slice)) return false;
048    
049            return true;
050        }
051    
052        @Override
053        public int hashCode() {
054            int result = slice.hashCode();
055            result = 31 * result + (key != null ? key.hashCode() : 0);
056            return result;
057        }
058    
059        @Override
060        public String toString() {
061            return slice + " -> " + key;
062        }
063    }