Java Integer Mod modifyPublicPortCheckRange(String modifiedVal, int dashCnt)

Here you can find the source of modifyPublicPortCheckRange(String modifiedVal, int dashCnt)

Description

modify Public Port Check Range

License

Apache License

Declaration

public static boolean modifyPublicPortCheckRange(String modifiedVal, int dashCnt) 

Method Source Code

//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;
    }
}

Related

  1. mode(final StringBuilder buffer, final int mode)
  2. ModEuclidean(int D, int d)
  3. modifyAlpha(int color, int alpha)
  4. modifyBase32AtIndex(final String s, final int index)
  5. modifyDummyString(String dummyString, int beginTag, int endTag)
  6. modifyString(char firstCharacter, String srcString, int indexOfSubstring)
  7. modInverse(int a, int n)
  8. modInverse(int n, int mod)
  9. modMultiply(long a, long b, int m)