Java tutorial
/** * Copyright (c) Acroquest Technology Co, Ltd. All Rights Reserved. * Please read the associated COPYRIGHTS file for more details. * * THE SOFTWARE IS PROVIDED BY Acroquest Technolog Co., Ltd., * WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDER BE LIABLE FOR ANY * CLAIM, DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING * OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. */ package acromusashi.stream.config; import java.net.URI; import java.net.URISyntaxException; import org.apache.commons.lang.StringUtils; /** * ??? * * @author kimura */ public class ConfigValidation { /** ????IP?????*/ private static final String SERVER_ADDRESS_SEPARATER = ":"; /** * ??? */ private ConfigValidation() { // Do nothing. } /** * ????<br> * ??:??????????????????? * * @param value * @return ???true?????false */ public static boolean isServerAddress(Object value) { //null????? if (value == null) { return false; } // String???? if (String.class.isAssignableFrom(value.getClass()) == false) { return false; } // ????? String valueString = (String) value; if (StringUtils.isEmpty(valueString)) { return false; } // :???????? String[] redisConfig = valueString.split(SERVER_ADDRESS_SEPARATER); if (redisConfig.length < 2) { return false; } // ???int??????? try { Integer.valueOf(redisConfig[1]); return true; } catch (NumberFormatException ex) { return false; } } /** * URI??????<br> * URI??????????????? * * @param value * @return ???true?????false */ public static boolean isUriFilePath(Object value) { // null????? if (value == null) { return false; } // String???? if (String.class.isAssignableFrom(value.getClass()) == false) { return false; } // ????? String valueString = (String) value; if (StringUtils.isEmpty(valueString)) { return false; } // ????? try { new URI(valueString); return true; } catch (URISyntaxException ex) { return false; } } /** * ????? * * @param value * @return ???true?????false */ public static boolean isFilePath(Object value) { // null????? if (value == null) { return false; } // String???? if (String.class.isAssignableFrom(value.getClass()) == false) { return false; } // ????? String valueString = (String) value; if (StringUtils.isEmpty(valueString)) { return false; } return true; } }