View Javadoc

1   package org.lsst.ccs.config.utilities;
2   
3   import org.lsst.ccs.config.NamesAndTag;
4   
5   /**
6    * @author bamade
7    */
8   // Date: 19/06/13
9   
10  public class ConfigUtils {
11      /**
12       * gets subsystem name, configName and tag name from pathName
13       * @param pathName
14       * @return
15       */
16      public static NamesAndTag namesFromPath(String pathName) {
17          //split name
18          String subsystemName = "" ;
19          String configName = "" ;
20          String tag = "" ;
21          int indexDot =  pathName.lastIndexOf('.');
22          int lastPath = pathName.lastIndexOf('/');
23          String rawName = pathName.substring(lastPath + 1, indexDot);
24          String[] elements = rawName.split("_");
25          //falltrough !
26          switch(elements.length) {
27              case 3: tag = elements[2] ;
28              case 2: configName = elements[1] ;
29              case 1: subsystemName = elements[0] ;
30          }
31          return new NamesAndTag(subsystemName,configName,tag) ;
32      }
33  
34      /**
35       * creates a fileName from a NamesAndTag object (reverse operation of <TT>namesFromPath</TT>
36       * @param namesAndTag
37       * @return
38       */
39      public static String baseNameFromNames(NamesAndTag namesAndTag) {
40          return String.format("%s_%s_%s", namesAndTag.getSubsystemName(), namesAndTag.getConfigName(),
41                  namesAndTag.getTag()) ;
42      }
43  }