001/*
002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 *
009 * Contributors:
010 *     Nuxeo - initial API and implementation
011 *
012 * $Id$
013 */
014
015package org.nuxeo.ecm.core.api;
016
017/**
018 * An ID reference to a document.
019 *
020 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
021 */
022public class IdRef implements DocumentRef {
023
024    private static final long serialVersionUID = 2796201881930443026L;
025
026    public final String value;
027
028    public IdRef(String value) {
029        this.value = value;
030    }
031
032    @Override
033    public int type() {
034        return ID;
035    }
036
037    @Override
038    public Object reference() {
039        return value;
040    }
041
042    @Override
043    public int hashCode() {
044        return value.hashCode();
045    }
046
047    @Override
048    public boolean equals(Object obj) {
049        if (this == obj) {
050            return true;
051        }
052        if (obj instanceof IdRef) {
053            return ((IdRef) obj).value.equals(value);
054        }
055        // it is not possible to compare an IdRef with a PathRef
056        return false;
057    }
058
059    @Override
060    public String toString() {
061        return value;
062    }
063
064}