/** * Indicates if it is the first time of usage of method or not (used in loops) * * @return 'true' if it is the first loop step, 'false' otherwise */ public boolean isFirstAndNext() { boolean result = index == 0; next(); return result; }
public static String[] toString(@Nonnull Enum... enums) { String[] result = new String[enums.length]; LoopData ld = new LoopData(enums); for (Enum anEnum : enums) { result[(int) ld.next()] = anEnum.name(); } return result; }
/** * Indicates if it is the last element in collection and goes to the next element * * @return 'true' if current position is last in collection, 'false' otherwise */ public boolean isLastAndNext() { boolean result = isLast(); next(); return result; }
@NotNull public static String addRequestParam (@NotNull String url, @NotNull Pair<String, ?>... properties) { StringBuilder sb = new StringBuilder(url); boolean containsOtherParams = true; if ( !url.contains("?") ) { sb.append("?"); containsOtherParams = false; } boolean isFirst = true; LoopData ld = new LoopData(properties); for (Pair<String, ?> property : properties) { ld.next(); if (!url.contains(property.getFirst())) { if (isFirst && containsOtherParams) { sb.append("&"); isFirst = false; } sb.append(property.getFirst()).append("=").append(property.getSecond()); if (!ld.isLast()) { sb.append("&"); } } } return sb.toString(); } }