Migrate to use tcpmd5 code in its new place
[bgpcep.git] / pcep / topology-provider / src / main / java / org / opendaylight / bgpcep / pcep / topology / provider / OperationResults.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.bgpcep.pcep.topology.provider;
9
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;
14
15 import java.util.Collections;
16 import java.util.List;
17
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;
24
25 /**
26  *
27  */
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);
32
33     private static final Function<Errors, Error> CONVERT_ERRORS = new Function<Errors, Error>() {
34         @Override
35         public Error apply(final Errors input) {
36             return new ErrorBuilder(input).build();
37         }
38     };
39
40     private final FailureType failure;
41     private final List<Error> error;
42
43     private OperationResults(final FailureType failure) {
44         this.failure = failure;
45         this.error = null;
46     }
47
48     private OperationResults(final List<Error> error) {
49         this.failure = FailureType.Failed;
50         this.error = error;
51     }
52
53     ListenableFuture<OperationResult> future() {
54         return Futures.<OperationResult> immediateFuture(this);
55     }
56
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));
60     }
61
62     @Override
63     public FailureType getFailure() {
64         return failure;
65     }
66
67     @Override
68     public List<Error> getError() {
69         return error;
70
71     }
72     @Override
73     public Class<? extends DataContainer> getImplementedInterface() {
74         return OperationResult.class;
75     }
76 }