@Override
    public String toString() {
        StringBuilder out = new StringBuilder();
        DataType prevType = null;
        for (FieldPathEntry entry : this) {
            FieldPathEntry.Type type = entry.getType();
            switch (type) {
            case STRUCT_FIELD:
                if (!out.isEmpty()) {
                    out.append(".");
                }
                Field field = entry.getFieldRef();
                out.append(field.getName());
                prevType = field.getDataType();
                break;
            case ARRAY_INDEX:
                out.append("[").append(entry.getLookupIndex()).append("]");
                break;
            case MAP_KEY:
                out.append("{").append(entry.getLookupKey()).append("}");
                break;
            case MAP_ALL_KEYS:
                out.append(".key");
                break;
            case MAP_ALL_VALUES:
                out.append(".value");
                break;
            case VARIABLE:
                if (prevType instanceof ArrayDataType) {
                    out.append("[$").append(entry.getVariableName()).append("]");
                } else if (prevType instanceof WeightedSetDataType || prevType instanceof MapDataType) {
                    out.append("{$").append(entry.getVariableName()).append("}");
                } else {
                    out.append("$").append(entry.getVariableName());
                }
            }
        }
        return out.toString();
    }
Convenience method to build a field path from a path string. This is a simple proxy for {@link
DataType#buildFieldPath(String)}.

@param fieldType The data type of the value to build a path for.
@param fieldPath The path string to parse.
@return The corresponding field path object.
document/src/main/java/com/yahoo/document/FieldPath.java