com.ocadotechnology.scenario.ValidationStep Maven / Gradle / Ivy
The newest version!
/*
* Copyright © 2017-2024 Ocado (Ocava)
*
* 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 com.ocadotechnology.scenario;
import java.util.function.Consumer;
class ValidationStep extends NamedStep implements Executable {
protected final Class type;
protected final NotificationCache notificationCache;
final Consumer consumer;
private T lastSeen;
ValidationStep(Class type, NotificationCache notificationCache, Consumer consumer) {
super(type);
this.type = type;
this.notificationCache = notificationCache;
this.consumer = consumer;
}
Class getType() {
return type;
}
@Override
public final boolean isRequired() {
return false;
}
@Override
public boolean isFinished() {
return false;
}
@Override
public void execute() {
Object notification = notificationCache.getUnorderedNotification();
if (notification != null && type.isAssignableFrom(notification.getClass())) {
lastSeen = type.cast(notification);
consumer.accept(lastSeen);
}
}
@Override
public boolean isMergeable() {
return false;
}
@Override
public void merge(Executable step) {}
@Override
public String info() {
return "Validation step last saw " + lastSeen;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy