001/**
002 *  Licensed to the Apache Software Foundation (ASF) under one or more
003 *  contributor license agreements.  See the NOTICE file distributed with
004 *  this work for additional information regarding copyright ownership.
005 *  The ASF licenses this file to You under the Apache License, Version 2.0
006 *  (the "License"); you may not use this file except in compliance with
007 *  the License.  You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 *  Unless required by applicable law or agreed to in writing, software
012 *  distributed under the License is distributed on an "AS IS" BASIS,
013 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 *  See the License for the specific language governing permissions and
015 *  limitations under the License.
016 */
017package org.apache.isis.objectstore.jdo.applib.service.settings;
018
019import java.io.Serializable;
020import java.util.StringTokenizer;
021
022/**
023 * @see http://www.datanucleus.org/products/datanucleus/jdo/primary_key.html
024 */
025public class UserSettingJdoPK implements Serializable
026{
027    private static final long serialVersionUID = 1L;
028
029    
030    public String user;
031    public String key;
032    
033    public UserSettingJdoPK ()
034    {
035    }
036
037    public String getUser() {
038        return user;
039    }
040
041    public void setUser(String user) {
042        this.user = user;
043    }
044
045    public String getKey() {
046        return key;
047    }
048    public void setKey(String key) {
049        this.key = key;
050    }
051
052
053    /**
054     * Constructor accepting same input as generated by toString().
055     */
056    public UserSettingJdoPK(String value) 
057    {
058        StringTokenizer token = new StringTokenizer (value, ";;");
059        token.nextToken();               // className
060        this.setUser(token.nextToken());   // user
061        this.setKey(token.nextToken());    // key
062    }
063
064    public boolean equals(Object obj)
065    {
066        if (obj == this)
067        {
068            return true;
069        }
070        if (!(obj instanceof UserSettingJdoPK))
071        {
072            return false;
073        }
074        UserSettingJdoPK c = (UserSettingJdoPK)obj;
075
076        return getUser().equals(c.getUser()) && getKey().equals(c.getKey());
077    }
078
079    public int hashCode ()
080    {
081        return this.getUser().hashCode() ^ this.getKey().hashCode();
082    }
083
084    public String toString ()
085    {
086        // Give output expected by String constructor
087        return this.getClass().getName() + ";;"  + this.getUser() + ";;" + this.getKey();
088    }
089
090}