Java Number Multiply multiplyForLong(final Number operand1, final int operand2)

Here you can find the source of multiplyForLong(final Number operand1, final int operand2)

Description

Multiplies an object number by a primitive int and returns a Long.

License

Apache License

Parameter

Parameter Description
operand1 The first operand, required.
operand2 The second operand.

Return

The result of the multiplication as a Long.

Declaration

public static Long multiplyForLong(final Number operand1, final int operand2) 

Method Source Code

//package com.java2s;
/*//from   ww  w . j  a v  a 2 s.  co m
 *  Copyright 2011 Eric F. Savage, code@efsavage.com
 *
 *   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 {
    /**
     * Multiplies an object number by a primitive int and returns a Long.
     * 
     * @param operand1
     *            The first operand, required.
     * @param operand2
     *            The second operand.
     * @return The result of the multiplication as a Long.
     */
    public static Long multiplyForLong(final Number operand1, final int operand2) {
        if (operand1 instanceof Double) {
            return Long.valueOf(Math.round(operand1.doubleValue() * operand2));
        }
        throw new IllegalArgumentException(operand1.getClass() + " not supported");
    }
}

Related

  1. multiply(Number a, Number b)
  2. multiply(Number a, Number b, Class cl)
  3. multiply(Number n1, Number n2)
  4. multiply(Number n1, Number n2)
  5. multiply(V1 value1, V2 value2)
  6. multiplyLongs(Long a, Long b)
  7. multiplyNumbers(Number a, Number b)