aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib/src/main/java/com/yahoo/tensor/impl/Convert.java
blob: e2cb64fdd1fc3055c6ae87e18167bc08dfb97b04 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.tensor.impl;

/**
 * Utility to make common conversions safe
 *
 * @author baldersheim
 */
public class Convert {
    public static int safe2Int(long value) {
        if (value > Integer.MAX_VALUE || value < Integer.MIN_VALUE) {
            throw new IndexOutOfBoundsException("value = " + value + ", which is too large to fit in an int");
        }
        return (int) value;
    }
}