com.fitbur.assertj.data.MapEntry Maven / Gradle / Ivy
/**
* 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.
*
* Copyright 2012-2016 the original author or authors.
*/
package com.fitbur.assertj.data;
import static com.fitbur.assertj.presentation.DefaultToString.toStringOf;
import static com.fitbur.assertj.presentation.StandardRepresentation.STANDARD_REPRESENTATION;
import java.util.Map;
import java.util.Objects;
/**
* Understands an entry in a {@link Map}
.
*
* @author Yvonne Wang
*/
public class MapEntry implements Map.Entry {
public final K key;
public final V value;
/**
* Creates a new {@link MapEntry}.
*
* @param key the key of the entry to create.
* @param value the value of the entry to create.
* @return the created {@code MapEntry}.
*/
public static MapEntry entry(K key, V value) {
return new MapEntry<>(key, value);
}
private MapEntry(K key, V value) {
this.key = key;
this.value = value;
}
@Override
public boolean equals(Object object) {
if (!(object instanceof Map.Entry)) return false;
Map.Entry, ?> that = (Map.Entry, ?>) object;
return Objects.equals(this.getKey(), that.getKey())
&& Objects.equals(this.getValue(), that.getValue());
}
@Override
public int hashCode() {
return Objects.hashCode(getKey()) ^ Objects.hashCode(getValue());
}
@Override
public String toString() {
return toStringOf(this, STANDARD_REPRESENTATION);
}
@Override
public K getKey() {
return key;
}
@Override
public V getValue() {
return value;
}
/**
* Always throws UnsupportedOperationException,
* as this class represents an immutable map entry.
*
* @param value ignored
* @return (Does not return)
* @throws UnsupportedOperationException always
*/
@Override
public V setValue(V value) {
throw new UnsupportedOperationException();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy