Here you can find the source of modifyValue(long value, char op, long modifier, long max, long min)
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 |
public static long modifyValue(long value, char op, long modifier, long max, long min)
//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; } }