/* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.bgpcep.pcep.topology.provider; import com.google.common.base.Function; import com.google.common.collect.Lists; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import java.util.Collections; import java.util.List; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.Errors; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.FailureType; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.OperationResult; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.operation.result.Error; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.operation.result.ErrorBuilder; import org.opendaylight.yangtools.yang.binding.DataContainer; /** * */ final class OperationResults implements OperationResult { static final OperationResults NOACK = new OperationResults(FailureType.NoAck); static final OperationResults SUCCESS = new OperationResults((FailureType)null); static final OperationResults UNSENT = new OperationResults(FailureType.Unsent); private static final Function CONVERT_ERRORS = new Function() { @Override public Error apply(final Errors input) { return new ErrorBuilder(input).build(); } }; private final FailureType failure; private final List error; private OperationResults(final FailureType failure) { this.failure = failure; this.error = null; } private OperationResults(final List error) { this.failure = FailureType.Failed; this.error = error; } ListenableFuture future() { return Futures. immediateFuture(this); } public static OperationResults createFailed(final List errors) { final List e = errors != null ? errors : Collections.emptyList(); return new OperationResults(Lists.transform(e, CONVERT_ERRORS)); } @Override public FailureType getFailure() { return failure; } @Override public List getError() { return error; } @Override public Class getImplementedInterface() { return OperationResult.class; } }