public boolean isValid(Object object) { Arguments arguments = new EditorArguments((String) object); String arg = arguments.toString(); if (arg.startsWith("edit ")) { String[] parts = arg.split("[ ]+"); Integer id = Integer.parseInt(parts[1]); StringBuilder builder = new StringBuilder(""); for (int i = 2; i < parts.length - 1; ++i) { builder.append(parts[i] + " "); } String name = builder.toString().trim(); String phoneNumber = parts[parts.length - 1]; boolean correctId = (id <= PersonIdGenerator.getMaxId() && id > 0); if (!correctId) { RuntimeException e = new RuntimeException("Invalid id!"); log.error(e.getMessage()); throw e; } boolean correctName = NameValidator.isValid(name); if (!correctName) { RuntimeException e = new RuntimeException("Invalid name!"); log.error(e.getMessage()); throw e; } boolean correctPhoneNumber = PhoneNumberValidator.isValid(phoneNumber); if (!correctPhoneNumber) { RuntimeException e = new RuntimeException("Invalid phone number!"); log.error(e.getMessage()); throw e; } log.info("Editor's arguments are valid"); return true; } else { return false; } }