testdev/ite/src/com.nokia.testfw.codegen.ui/src/com/nokia/testfw/codegen/ui/util/PathNodeConverter.java
equal
deleted
inserted
replaced
|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 package com.nokia.testfw.codegen.ui.util; |
|
18 |
|
19 public class PathNodeConverter { |
|
20 |
|
21 static public PathNode pathToNode(PathNode root, String path) { |
|
22 PathNode parent = root; |
|
23 PathNode child = null; |
|
24 String[] segmentArray = path.split("/"); |
|
25 for (String segment : segmentArray) { |
|
26 child = parent.getChild(segment); |
|
27 if (child == null) { |
|
28 child = new PathNode(segment); |
|
29 parent.addChild(child); |
|
30 } |
|
31 parent = child; |
|
32 } |
|
33 return child; |
|
34 } |
|
35 |
|
36 static public String nodeToPath(PathNode node) { |
|
37 String path = node.getName(); |
|
38 while (node.getParent() != null) { |
|
39 path = node.getParent().getName() + "/" + path; |
|
40 node = node.getParent(); |
|
41 } |
|
42 return path; |
|
43 } |
|
44 } |