KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > cvsclient > command > CommandUtils


1 /*****************************************************************************
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is the CVS Client Library.
16  * The Initial Developer of the Original Software is Thomas Singer.
17  * Portions created by Robert Greig are Copyright (C) 2001.
18  * All Rights Reserved.
19  *
20  * Contributor(s): Thomas Singer.
21  *****************************************************************************/

22 package org.netbeans.lib.cvsclient.command;
23
24 import java.util.*;
25
26 /**
27  * @author Thomas Singer
28  */

29 public class CommandUtils {
30     /**
31      * Returns the directory relative to local path from the specified message.
32      * This method returns null, if the specified message isn't a EXAM_DIR-
33      * message.
34      */

35     public static String JavaDoc getExaminedDirectory(String JavaDoc message, String JavaDoc examDirPattern) {
36         final int index = message.indexOf(examDirPattern);
37         final int startIndex = index + examDirPattern.length() + 1;
38         if (index < 0 || message.length() < startIndex + 1) {
39             return null;
40         }
41
42         return message.substring(startIndex);
43     }
44     
45     /**
46      * for a list of string will return the string that equals the name parameter.
47      * To be used everywhere you need to have only one string occupying teh memory space,
48      * eg. in Builders to have the revision number strings not repeatedly in memory.
49      */

50     public static String JavaDoc findUniqueString(String JavaDoc name, List list) {
51         if (name == null) {
52             return null;
53         }
54         int index = list.indexOf(name);
55         if (index >= 0) {
56             return (String JavaDoc)list.get(index);
57         }
58         else {
59             String JavaDoc newName = new String JavaDoc(name);
60             list.add(newName);
61             return newName;
62         }
63     }
64 }
65
Popular Tags