@Test public void parseOrderUnit() throws Exception { OrderUnit ou = MethodNameParser.parseOrderUnit("AgeAndNameOrderByIdDesc"); assertThat(ou.getProperty(), equalTo("id")); assertThat(ou.getOrderType(), equalTo(OrderType.DESC)); assertThat(ou.getOrderStrSize(), equalTo("OrderByIdDesc".length())); ou = MethodNameParser.parseOrderUnit("AgeAndNameOrderByUserNameAsc"); assertThat(ou.getProperty(), equalTo("userName")); assertThat(ou.getOrderType(), equalTo(OrderType.ASC)); assertThat(ou.getOrderStrSize(), equalTo("OrderByUserNameAsc".length())); ou = MethodNameParser.parseOrderUnit("AgeAndNameOrderByAgeU"); assertThat(ou.getProperty(), equalTo("ageU")); assertThat(ou.getOrderType(), equalTo(OrderType.NONE)); assertThat(ou.getOrderStrSize(), equalTo("OrderByAgeU".length())); }
@Nullable static OrderUnit parseOrderUnit(String str) { Pattern p = Pattern.compile(ORDER_BY_REGEX); Matcher m = p.matcher(str); if (m.find()) { String tailStr = Strings.firstLetterToLowerCase(str.substring(m.end() - 1)); int size = ORDER_BY.length() + tailStr.length(); String property; OrderType orderType; if (tailStr.endsWith(DESC)) { property = tailStr.substring(0, tailStr.length() - DESC.length()); orderType = OrderType.DESC; } else if (tailStr.endsWith(ASC)) { property = tailStr.substring(0, tailStr.length() - ASC.length()); orderType = OrderType.ASC; } else { property = tailStr; orderType = OrderType.NONE; } return new OrderUnit(property, orderType, size); } return null; }
MethodNameParser { @Nullable static OrderUnit parseOrderUnit(String str) { Pattern p = Pattern.compile(ORDER_BY_REGEX); Matcher m = p.matcher(str); if (m.find()) { String tailStr = Strings.firstLetterToLowerCase(str.substring(m.end() - 1)); int size = ORDER_BY.length() + tailStr.length(); String property; OrderType orderType; if (tailStr.endsWith(DESC)) { property = tailStr.substring(0, tailStr.length() - DESC.length()); orderType = OrderType.DESC; } else if (tailStr.endsWith(ASC)) { property = tailStr.substring(0, tailStr.length() - ASC.length()); orderType = OrderType.ASC; } else { property = tailStr; orderType = OrderType.NONE; } return new OrderUnit(property, orderType, size); } return null; } }
MethodNameParser { @Nullable static OrderUnit parseOrderUnit(String str) { Pattern p = Pattern.compile(ORDER_BY_REGEX); Matcher m = p.matcher(str); if (m.find()) { String tailStr = Strings.firstLetterToLowerCase(str.substring(m.end() - 1)); int size = ORDER_BY.length() + tailStr.length(); String property; OrderType orderType; if (tailStr.endsWith(DESC)) { property = tailStr.substring(0, tailStr.length() - DESC.length()); orderType = OrderType.DESC; } else if (tailStr.endsWith(ASC)) { property = tailStr.substring(0, tailStr.length() - ASC.length()); orderType = OrderType.ASC; } else { property = tailStr; orderType = OrderType.NONE; } return new OrderUnit(property, orderType, size); } return null; }  }
MethodNameParser { @Nullable static OrderUnit parseOrderUnit(String str) { Pattern p = Pattern.compile(ORDER_BY_REGEX); Matcher m = p.matcher(str); if (m.find()) { String tailStr = Strings.firstLetterToLowerCase(str.substring(m.end() - 1)); int size = ORDER_BY.length() + tailStr.length(); String property; OrderType orderType; if (tailStr.endsWith(DESC)) { property = tailStr.substring(0, tailStr.length() - DESC.length()); orderType = OrderType.DESC; } else if (tailStr.endsWith(ASC)) { property = tailStr.substring(0, tailStr.length() - ASC.length()); orderType = OrderType.ASC; } else { property = tailStr; orderType = OrderType.NONE; } return new OrderUnit(property, orderType, size); } return null; }  static MethodNameInfo parse(String str); }
MethodNameParser { @Nullable static OrderUnit parseOrderUnit(String str) { Pattern p = Pattern.compile(ORDER_BY_REGEX); Matcher m = p.matcher(str); if (m.find()) { String tailStr = Strings.firstLetterToLowerCase(str.substring(m.end() - 1)); int size = ORDER_BY.length() + tailStr.length(); String property; OrderType orderType; if (tailStr.endsWith(DESC)) { property = tailStr.substring(0, tailStr.length() - DESC.length()); orderType = OrderType.DESC; } else if (tailStr.endsWith(ASC)) { property = tailStr.substring(0, tailStr.length() - ASC.length()); orderType = OrderType.ASC; } else { property = tailStr; orderType = OrderType.NONE; } return new OrderUnit(property, orderType, size); } return null; }  static MethodNameInfo parse(String str);  }