/** * Tell whether the string contains a positive or negative semitones delta, i.e., a semitones number with an obligatory + or - * sign, such as "+3.2st" or "-13.2st". * * @param string * string * @return s.substring(s.length() - 2).equals("st") and isNumberDelta(s.substring(0, s.length() - 2)) */ public static boolean isSemitonesDelta(String string) { String s = string.trim(); if (s.length() < 4) return false; return s.substring(s.length() - 2).equals("st") && isNumberDelta(s.substring(0, s.length() - 2)); }
/** * Tell whether the string contains a positive or negative percentage delta, i.e., a percentage number with an obligatory + or * - sign. * * @param string * string * @return s.substring */ public static boolean isPercentageDelta(String string) { String s = string.trim(); if (s.length() < 3) return false; return s.substring(s.length() - 1).equals("%") && isNumberDelta(s.substring(0, s.length() - 1)); }
/** * Tell whether the string contains a positive or negative percentage delta, i.e., a percentage number with an obligatory + or * - sign. * * @param string * string * @return s.substring */ public static boolean isPercentageDelta(String string) { String s = string.trim(); if (s.length() < 3) return false; return s.substring(s.length() - 1).equals("%") && isNumberDelta(s.substring(0, s.length() - 1)); }
/** * Tell whether the string contains a positive or negative semitones delta, i.e., a semitones number with an obligatory + or - * sign, such as "+3.2st" or "-13.2st". * * @param string * string * @return s.substring(s.length() - 2).equals("st") and isNumberDelta(s.substring(0, s.length() - 2)) */ public static boolean isSemitonesDelta(String string) { String s = string.trim(); if (s.length() < 4) return false; return s.substring(s.length() - 2).equals("st") && isNumberDelta(s.substring(0, s.length() - 2)); }
/** * For a string containing a number delta as judged by <code>isNumberDelta()</code>, return the numerical value, rounded to an * integer. * * @param string * string * @return the numeric value, rounded to an integer, or 0 if the string is not a valid number delta. */ public static int getNumberDelta(String string) { String s = string.trim(); if (!isNumberDelta(s)) return 0; double value = 0; try { value = Double.parseDouble(s); } catch (NumberFormatException e) { // logger.warn("Unexpected number value `" + s + "'"); } return (int) Math.round(value); }
/** * For a string containing a number delta as judged by <code>isNumberDelta()</code>, return the numerical value, rounded to an * integer. * * @param string * string * @return the numeric value, rounded to an integer, or 0 if the string is not a valid number delta. */ public static int getNumberDelta(String string) { String s = string.trim(); if (!isNumberDelta(s)) return 0; double value = 0; try { value = Double.parseDouble(s); } catch (NumberFormatException e) { // logger.warn("Unexpected number value `" + s + "'"); } return (int) Math.round(value); }