Here you can find the source of assertValidItemName(String itemName)
Parameter | Description |
---|---|
itemName | the name of the item to be checked (could be null or empty) |
Parameter | Description |
---|---|
IllegalArgumentException | if the name of the item is invalid |
public static void assertValidItemName(String itemName) throws IllegalArgumentException
//package com.java2s; /**/*from w ww.ja v a 2 s . c o m*/ * Copyright (c) 2014-2017 by the respective copyright holders. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ public class Main { /** * Ensures that the specified name of the item is valid. * <p> * If the name of the item is invalid an {@link IllegalArgumentException} is thrown, otherwise this method returns * silently. * <p> * A valid item name must <i>only</i> only consists of the following characters: * <ul> * <li>a-z</li> * <li>A-Z</li> * <li>0..9</li> * <li>_ (underscore)</li> * </ul> * * @param itemName the name of the item to be checked (could be null or empty) * * @throws IllegalArgumentException if the name of the item is invalid */ public static void assertValidItemName(String itemName) throws IllegalArgumentException { if (!isValidItemName(itemName)) { throw new IllegalArgumentException("The specified name of the item '" + itemName + "' is not valid!"); } } /** * Returns {@code true} if the specified name is a valid item name, otherwise {@code false}. * <p> * A valid item name must <i>only</i> only consists of the following characters: * <ul> * <li>a-z</li> * <li>A-Z</li> * <li>0..9</li> * <li>_ (underscore)</li> * </ul> * * @param itemName the name of the item to be checked (could be null or empty) * * @return true if the specified name is a valid item name, otherwise false */ public static boolean isValidItemName(final String itemName) { if (itemName != null && !itemName.isEmpty()) { return itemName.matches("[a-zA-Z0-9_]*"); } return false; } }