Here you can find the source of modifyPublicPortCheckRange(String modifiedVal, int dashCnt)
public static boolean modifyPublicPortCheckRange(String modifiedVal, int dashCnt)
//package com.java2s; /**/*from www .j av a2 s . c om*/ * Copyright Microsoft Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { /** * End point range's minimum value. */ private final static int RANGE_MIN = 1; /** * End point range's maximum value. */ private final static int RANGE_MAX = 65535; public static boolean modifyPublicPortCheckRange(String modifiedVal, int dashCnt) { // Check for valid range 1 to 65535 Boolean isPortValid = true; try { /* * If public port contains '-' * then split string and * get two integer values out of it. * else directly check for value. */ if (dashCnt == 1) { String[] range = modifiedVal.split("-"); int rngStart = Integer.parseInt(range[0]); int rngEnd = Integer.parseInt(range[1]); if (!(rngStart >= RANGE_MIN && rngStart <= RANGE_MAX && rngEnd >= RANGE_MIN && rngEnd <= RANGE_MAX)) { isPortValid = false; } } else { int port = Integer.parseInt(modifiedVal); if (!(port >= RANGE_MIN && port <= RANGE_MAX)) { isPortValid = false; } } } catch (NumberFormatException e) { isPortValid = false; } return isPortValid; } }