2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.fmiweather;
15 import java.math.BigDecimal;
16 import java.util.Arrays;
17 import java.util.Objects;
18 import java.util.stream.Stream;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.hamcrest.Description;
23 import org.hamcrest.TypeSafeMatcher;
26 * Hamcrest matcher for values
28 * @author Sami Salonen - Initial contribution
31 public class ValuesMatcher extends TypeSafeMatcher<@Nullable BigDecimal[]> {
33 private Object[] values;
35 public ValuesMatcher(@Nullable String... values) {
36 this.values = Stream.of(values).map(s -> stringToBigDecimal(s)).toArray();
39 private static @Nullable BigDecimal stringToBigDecimal(@Nullable String s) {
40 return s == null ? null : new BigDecimal(s);
43 @SuppressWarnings("null")
45 public void describeTo(@Nullable Description description) {
46 if (description == null) {
49 description.appendText(Arrays.deepToString(values));
53 protected boolean matchesSafely(@Nullable BigDecimal[] data) {
54 return Objects.deepEquals(data, values);