Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//   Licensed under the Apache License, Version 2.0 (the "License");

public class Main {
    public static int getStepsCount(String xPathAbs) {
        if ((xPathAbs == null) || xPathAbs.isEmpty()) {
            return 0;
        }
        int result = 0;

        if (!xPathAbs.startsWith("/")) {
            xPathAbs = "/" + xPathAbs;
        }

        do {
            xPathAbs = removeLastStep(xPathAbs);
            ++result;
        } while ((xPathAbs != null) && !xPathAbs.isEmpty());

        return result;
    }

    public static String removeLastStep(String xpStr) {
        int lastSlash = xpStr.lastIndexOf("/");

        if (lastSlash != -1) {
            xpStr = xpStr.substring(0, lastSlash);
        }

        return xpStr;
    }
}