Skip to content

Commit

Permalink
#180 Introduced Triple record to combine key/value/type
Browse files Browse the repository at this point in the history
  • Loading branch information
openwms committed Aug 8, 2024
1 parent 8a0171d commit 5143c53
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
7 changes: 6 additions & 1 deletion org.openwms.core.util/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

<properties>
<dozer.version>6.5.2</dozer.version>
<mockito-core.version>5.7.0</mockito-core.version>
</properties>

<dependencyManagement>
Expand All @@ -42,6 +43,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito-core.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -110,7 +116,6 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2005-2024 the original author or authors.
*
* 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.
*/
package org.openwms.core.lang;

/**
* A Triple.
*
* @author Heiko Scherrer
*/
public record Triple<K, V, T>(K key, V value, T type) {

/**
* Get the stored value as class type {@code clazz}.
*
* @param clazz The type to retrieve the value as
* @return The cast value
* @param <U> The requested type
* @throws ClassCastException in case of cast error
*/
@SuppressWarnings("unchecked")
public <U> U valueAs(Class<U> clazz) {
if (clazz.equals(this.type.getClass())) {
return (U) value;
}
throw new ClassCastException("Cannot case requested type [%s] from [%s]".formatted(clazz, type.getClass()));
}
}

0 comments on commit 5143c53

Please sign in to comment.