1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.vfs.test;
18  
19  import org.apache.commons.vfs.FileType;
20  
21  import java.util.HashMap;
22  import java.util.Map;
23  
24  /***
25   * Info about a file.
26   */
27  class FileInfo
28  {
29      String baseName;
30      FileType type;
31      String content;
32      Map children = new HashMap();
33      FileInfo parent;
34  
35      public FileInfo(final String name, final FileType type)
36      {
37          baseName = name;
38          this.type = type;
39          this.content = null;
40      }
41  
42      public FileInfo(final String name, final FileType type, final String content)
43      {
44          baseName = name;
45          this.type = type;
46          this.content = content;
47      }
48  
49      public FileInfo getParent()
50      {
51          return parent;
52      }
53  
54      /***
55       * Adds a child.
56       */
57      public void addChild(final FileInfo child)
58      {
59          children.put(child.baseName, child);
60          child.parent = this;
61      }
62  
63      /***
64       * Adds a child file.
65       */
66      public FileInfo addFile(final String baseName, final String content)
67      {
68          final FileInfo child = new FileInfo(baseName, FileType.FILE, content);
69          addChild(child);
70          return child;
71      }
72  
73      /***
74       * Adds a child folder.
75       */
76      public FileInfo addFolder(final String baseName)
77      {
78          final FileInfo child = new FileInfo(baseName, FileType.FOLDER, null);
79          addChild(child);
80          return child;
81      }
82  }