001: /*
002: * ====================================================================
003: * Copyright (c) 2004-2008 TMate Software Ltd. All rights reserved.
004: *
005: * This software is licensed as described in the file COPYING, which
006: * you should have received as part of this distribution. The terms
007: * are also available at http://svnkit.com/license.html
008: * If newer versions of this license are posted there, you may use a
009: * newer version instead, at your option.
010: * ====================================================================
011: */
012:
013: package org.tmatesoft.svn.core;
014:
015: /**
016: * The <b>SVNNodeKind</b> class is used to describe the kind of a
017: * directory entry (node, in other words). This can be:
018: * <ul>
019: * <li>a directory - the node is a directory
020: * <li>a file - the node is a file
021: * <li>none - the node is missing (does not exist)
022: * <li>unknown - the node kind can not be recognized
023: * </ul>
024: *
025: * @version 1.1.1
026: * @author TMate Software Ltd.
027: * @see SVNDirEntry
028: */
029: public final class SVNNodeKind implements Comparable {
030: /**
031: * This node kind is used to say that a node is missing
032: */
033: public static final SVNNodeKind NONE = new SVNNodeKind(2);
034: /**
035: * Defines the file node kind
036: */
037: public static final SVNNodeKind FILE = new SVNNodeKind(1);
038: /**
039: * Defines the directory node kind
040: */
041: public static final SVNNodeKind DIR = new SVNNodeKind(0);
042: /**
043: * This node kind is used to say that the kind of a node is
044: * actually unknown
045: */
046: public static final SVNNodeKind UNKNOWN = new SVNNodeKind(3);
047:
048: private int myID;
049:
050: private SVNNodeKind(int id) {
051: myID = id;
052: }
053:
054: /**
055: * Parses the passed string and finds out the node kind. For instance,
056: * <code>parseKind(<span class="javastring">"dir"</span>)</code> will return
057: * {@link #DIR}.
058: *
059: * @param kind a node kind as a string
060: * @return an <b>SVNNodeKind</b> representation
061: */
062: public static SVNNodeKind parseKind(String kind) {
063: if ("file".equals(kind)) {
064: return FILE;
065: } else if ("dir".equals(kind)) {
066: return DIR;
067: } else if ("none".equals(kind) || kind == null) {
068: return NONE;
069: }
070: return UNKNOWN;
071: }
072:
073: /**
074: * Represents the current <b>SVNNodeKind</b> object as a string.
075: *
076: * @return a string representation of this object.
077: */
078: public String toString() {
079: if (this == NONE) {
080: return "none";
081: } else if (this == FILE) {
082: return "file";
083: } else if (this == DIR) {
084: return "dir";
085: }
086: return "unknown";
087: }
088:
089: /**
090: * Compares this object with another one.
091: * Each <b>SVNNodeKind</b> constant has got its own unique id.
092: *
093: * @param o an object to compare with
094: * @return <ul>
095: * <li>-1 - if <code>o</code> is either <span class="javakeyword">null</span>,
096: * or is not an instance of <b>SVNNodeKind</b>, or the id of
097: * this object is smaller than the id of <code>o</code>;
098: * </li>
099: * <li>1 - if the id of this object is bigger than the id of
100: * <code>o</code>;
101: * </li>
102: * <li>0 - if and only if <code>o</code> is the same constant
103: * value as this one (has the same id)
104: * </li>
105: * </ul>
106: */
107: public int compareTo(Object o) {
108: if (o == null || o.getClass() != SVNNodeKind.class) {
109: return -1;
110: }
111: int otherID = ((SVNNodeKind) o).myID;
112: return myID > otherID ? 1 : myID < otherID ? -1 : 0;
113: }
114: }
|