2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.bgpcep.pcep.topology.provider;
10 import com.google.common.base.Function;
11 import com.google.common.collect.Lists;
12 import com.google.common.util.concurrent.Futures;
13 import com.google.common.util.concurrent.ListenableFuture;
15 import java.util.Collections;
16 import java.util.List;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.Errors;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.FailureType;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.OperationResult;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.operation.result.Error;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.operation.result.ErrorBuilder;
23 import org.opendaylight.yangtools.yang.binding.DataContainer;
28 final class OperationResults implements OperationResult {
29 static final OperationResults NOACK = new OperationResults(FailureType.NoAck);
30 static final OperationResults SUCCESS = new OperationResults((FailureType)null);
31 static final OperationResults UNSENT = new OperationResults(FailureType.Unsent);
33 private static final Function<Errors, Error> CONVERT_ERRORS = new Function<Errors, Error>() {
35 public Error apply(final Errors input) {
36 return new ErrorBuilder(input).build();
40 private final FailureType failure;
41 private final List<Error> error;
43 private OperationResults(final FailureType failure) {
44 this.failure = failure;
48 private OperationResults(final List<Error> error) {
49 this.failure = FailureType.Failed;
53 ListenableFuture<OperationResult> future() {
54 return Futures.<OperationResult> immediateFuture(this);
57 public static OperationResults createFailed(final List<Errors> errors) {
58 final List<Errors> e = errors != null ? errors : Collections.<Errors>emptyList();
59 return new OperationResults(Lists.transform(e, CONVERT_ERRORS));
63 public FailureType getFailure() {
68 public List<Error> getError() {
73 public Class<? extends DataContainer> getImplementedInterface() {
74 return OperationResult.class;