public TopologyState getTopologyState(String stateName) { Utils.requireNonEmpty(stateName, "State name cannot be empty"); TopologyState state = states.get(stateName); if (state == null) { throw new IllegalArgumentException("No such state " + stateName); } return state; }
/** * Generates the next name for the given name and suffix. * <p> * E.g. {@code getNextName("test-foo", "-foo") returns "test-foo2", * getNextName("test-foo2", "-foo") returns "test-foo3"} * </p> * @param name the current name * @param suffix the suffix without the number part * @return the next name */ public static String getNextName(String name, String suffix) { Utils.requireNonEmpty(name, "Empty name"); String prefix; String suffixWithNum; int num = getNumPart(name, suffix); if (num == -1) { prefix = name; suffixWithNum = suffix; } else { prefix = getPrefix(name, suffix); suffixWithNum = suffix + (num + 1); } return prefix + suffixWithNum; }
private void validateRole(Role role) { Utils.requireNonEmpty(role.getName(), "Role name"); if (StringUtils.isNumeric(role.getName())) { throw new IllegalArgumentException("Role name cannot be numeric"); } StorageUtils.ensureUnique(role, this::listRoles, QueryParam.params(User.NAME, role.getName())); }
private void validateUser(User user) { Utils.requireNonEmpty(user.getName(), "User name"); StorageUtils.ensureUnique(user, this::listUsers, QueryParam.params(User.NAME, user.getName())); }