blob: 532505f6d3de7058161886373077f345f30aac41 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.query.textserialize.item;
import com.yahoo.protect.Validator;
/**
* @author Tony Vaagenes
*/
public class TypeCheck {
public static void ensureInstanceOf(Object object, Class<?> c) {
Validator.ensureInstanceOf(expectationString(c.getName(), object.getClass().getSimpleName()),
object, c);
}
public static void ensureInteger(Object value) {
ensureInstanceOf(value, Number.class);
Number number = (Number)value;
int intValue = number.intValue();
if (intValue != number.doubleValue())
throw new IllegalArgumentException("Invalid integer '" + number + "'");
}
private static String expectationString(String expected, String got) {
return "Expected " + expected + ", but got " + got;
}
}
|