org.eclipse.ditto.placeholders.ImmutablePlaceholderResolver Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ditto-placeholders Show documentation
Show all versions of ditto-placeholders Show documentation
Eclipse Ditto is a framework for creating and managing digital twins in the IoT.
/*
* Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.placeholders;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import javax.annotation.concurrent.Immutable;
/**
* Immutable implementation of {@link PlaceholderResolver}.
*/
@Immutable
final class ImmutablePlaceholderResolver implements PlaceholderResolver {
private final Placeholder placeholder;
private final List placeholderSource;
ImmutablePlaceholderResolver(final Placeholder placeholder, final List placeholderSource) {
this.placeholder = placeholder;
this.placeholderSource = Collections.unmodifiableList(new ArrayList<>(placeholderSource));
}
@Override
public List getPlaceholderSources() {
return placeholderSource;
}
@Override
public List resolveValues(final T placeholderSource, final String name) {
return placeholder.resolveValues(placeholderSource, name);
}
@Override
public String getPrefix() {
return placeholder.getPrefix();
}
@Override
public List getSupportedNames() {
return placeholder.getSupportedNames();
}
@Override
public boolean supports(final String name) {
return placeholder.supports(name);
}
@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (!(o instanceof ImmutablePlaceholderResolver)) {
return false;
}
final ImmutablePlaceholderResolver> that = (ImmutablePlaceholderResolver>) o;
return Objects.equals(placeholder, that.placeholder) &&
Objects.equals(placeholderSource, that.placeholderSource);
}
@Override
public int hashCode() {
return Objects.hash(placeholder, placeholderSource);
}
@Override
public String toString() {
return getClass().getSimpleName() + " [" +
"placeholder=" + placeholder +
", value=" + placeholderSource +
"]";
}
}