Java Long Number Mod modifyValue(long value, char op, long modifier, long max, long min)

Here you can find the source of modifyValue(long value, char op, long modifier, long max, long min)

Description

Modify the value, return = op(value, modifier).

License

Open Source License

Parameter

Parameter Description
value the value to be modified
op the operation, now there are only '+', '-', '*' and '/'
modifier the modifier
max the value's maximum
min the value's minimum

Return

The modified value, or max/min if the modified value is greater/smaller than the max/min

Declaration

public static long modifyValue(long value, char op, long modifier, long max, long min) 

Method Source Code

//package com.java2s;
/*******************************************************************************
* Copyright (c) 2016 ARM Ltd. and others
* 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
*
* Contributors:/* ww w  .  j  a v  a2  s .  c  o  m*/
* ARM Ltd and ARM Germany GmbH - Initial API and implementation
*******************************************************************************/

public class Main {
    /**
     * Modify the value, return = op(value, modifier).
     * <br>
     * E.g. if op='+', value = 10, modifier = 5, then return = 10 + 5 = 15
     * @param value the value to be modified
     * @param op the operation, now there are only '+', '-', '*' and '/'
     * @param modifier the modifier
     * @param max the value's maximum
     * @param min the value's minimum
     * @return The modified value,
     * or max/min if the modified value is greater/smaller than the max/min
     */
    public static long modifyValue(long value, char op, long modifier, long max, long min) {
        long realValue = value;
        if (realValue > max) {
            realValue = max;
        }
        if (realValue < min) {
            realValue = min;
        }
        switch (op) {
        case '+':
            realValue += modifier;
            break;
        case '-':
            realValue -= modifier;
            break;
        case '*':
            realValue *= modifier;
            break;
        case '/':
            realValue /= modifier;
            break;
        default:
            break;
        }
        return realValue;
    }
}

Related

  1. mod(long pNum, long pDivisor)
  2. mod(long v, long m)
  3. mod(long x, long y)
  4. modDivide(long a, long b, long m)
  5. modifiedCalcElementOffset(long index, long mask)
  6. mods(long v, long m)
  7. modularReciprocal(long a, long mod)
  8. modulo(final long x, final long y)
  9. modulo(long a, long n)