KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > launching > CompositeId


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.launching;
12
13 import java.util.ArrayList JavaDoc;
14
15 /**
16  * Utility class for id's made of multiple Strings
17  */

18 public class CompositeId {
19     private String JavaDoc[] fParts;
20     
21     public CompositeId(String JavaDoc[] parts) {
22         fParts= parts;
23     }
24     
25     public static CompositeId fromString(String JavaDoc idString) {
26         ArrayList JavaDoc parts= new ArrayList JavaDoc();
27         int commaIndex= idString.indexOf(',');
28         while (commaIndex > 0) {
29             int length= Integer.valueOf(idString.substring(0, commaIndex)).intValue();
30             String JavaDoc part= idString.substring(commaIndex+1, commaIndex+1+length);
31             parts.add(part);
32             idString= idString.substring(commaIndex+1+length);
33             commaIndex= idString.indexOf(',');
34         }
35         String JavaDoc[] result= (String JavaDoc[])parts.toArray(new String JavaDoc[parts.size()]);
36         return new CompositeId(result);
37     }
38     
39     public String JavaDoc toString() {
40         StringBuffer JavaDoc buf= new StringBuffer JavaDoc();
41         for (int i= 0; i < fParts.length; i++) {
42             buf.append(fParts[i].length());
43             buf.append(',');
44             buf.append(fParts[i]);
45         }
46         return buf.toString();
47     }
48     
49     public String JavaDoc get(int index) {
50         return fParts[index];
51     }
52     
53     public int getPartCount() {
54         return fParts.length;
55     }
56 }
57
Popular Tags