code: public StorageKey toKey(Path fromPath, StorageKey storage) {
      final List<FieldPartitioner> partitioners =
              Accessor.getDefault().getFieldPartitioners(storage.getPartitionStrategy());
  
      //Strip off the root directory to get partition segments
      String truncatedPath = fromPath.toString();
      if(truncatedPath.startsWith(rootPath.toString())){
        truncatedPath = truncatedPath.substring(rootPath.toString().length());
      }
  
      List<String> pathParts = new LinkedList<String>();
      //Check that there are segments to parse.
      if(!truncatedPath.isEmpty()) {
        Path currentPath = new Path(truncatedPath);
        while (currentPath != null) {
          String name = currentPath.getName();
          if(!name.isEmpty()) {
            pathParts.add(currentPath.getName());
          }
          currentPath = currentPath.getParent();
        }
  
        //list is now last -> first so reverse the list to be first -> last
        Collections.reverse(pathParts);
      }
  
  
      final List<Object> values = Lists.newArrayList(
              new Object[pathParts.size()]);
      //for each segment we have get the value for the key
      for(int  i = 0; i < pathParts.size(); i++){
        values.set(i, valueForDirname(
                (FieldPartitioner<?, ?>) partitioners.get(i),
                pathParts.get(i)));
      }
  
      storage.replaceValues(values);
      return storage;
    }
docs: Supposed to build keys from start to finish vs end to start