001/*
002// This software is subject to the terms of the Eclipse Public License v1.0
003// Agreement, available at the following URL:
004// http://www.eclipse.org/legal/epl-v10.html.
005// You must accept the terms of that agreement to use this software.
006//
007// Copyright (C) 2002-2005 Julian Hyde
008// Copyright (C) 2005-2012 Pentaho and others
009// All Rights Reserved.
010//
011// jhyde, 21 March, 2002
012*/
013package mondrian.rolap;
014
015import mondrian.olap.Util;
016
017/**
018 * <code>MemberKey</code> todo:
019 *
020 * @author jhyde
021 * @since 21 March, 2002
022 */
023class MemberKey {
024    private final RolapMember parent;
025    private final Object value;
026
027    MemberKey(RolapMember parent, Object value) {
028        this.parent = parent;
029        this.value = value;
030    }
031
032    @Override
033    public boolean equals(Object o) {
034        if (!(o instanceof MemberKey)) {
035            return false;
036        }
037        MemberKey other = (MemberKey) o;
038        return Util.equals(this.parent, other.parent)
039            && Util.equals(this.value, other.value);
040    }
041
042    @Override
043    public int hashCode() {
044        int h = 0;
045        if (value != null) {
046            h = value.hashCode();
047        }
048        if (parent != null) {
049            h = (h * 31) + parent.hashCode();
050        }
051        return h;
052    }
053
054    /**
055     * Returns the level of the member that this key represents.
056     *
057     * @return Member level, or null if is root member
058     */
059    public RolapLevel getLevel() {
060        if (parent == null) {
061            return null;
062        }
063        final RolapLevel level = parent.getLevel();
064        if (level.isParentChild()) {
065            return level;
066        }
067        return (RolapLevel) level.getChildLevel();
068    }
069}
070
071// End MemberKey.java