Exported package for classifier-definitions and action-definitions
[groupbasedpolicy.git] / renderers / ofoverlay / src / main / java / org / opendaylight / groupbasedpolicy / renderer / ofoverlay / sf / ClassificationResult.java
1 /*
2  * Copyright (c) 2014 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
9 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf;
10
11 import java.util.List;
12
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
14
15 import com.google.common.base.Preconditions;
16
17 public class ClassificationResult {
18
19     private final String errorMessage;
20     private final boolean isSuccessful;
21     private final List<MatchBuilder> matchBuilders;
22
23     /**
24      * @param errorMessage cannot be {@code null}
25      */
26     public ClassificationResult(String errorMessage) {
27         this.errorMessage = Preconditions.checkNotNull(errorMessage);
28         this.isSuccessful = false;
29         matchBuilders = null;
30     }
31
32     /**
33      * @param matches cannot be {@code null}
34      */
35     public ClassificationResult(List<MatchBuilder> matches) {
36         errorMessage = "";
37         this.matchBuilders = Preconditions.checkNotNull(matches);
38         this.isSuccessful = true;
39     }
40
41     /**
42      * @return list of {@link MatchBuilder}
43      * @throws IllegalStateException if this method is called and {@link #isSuccessfull()} == {@code false}
44      */
45     public List<MatchBuilder> getMatchBuilders() {
46         if (isSuccessful == false) {
47             throw new IllegalStateException("Classification was not successfull.");
48         }
49         return matchBuilders;
50     }
51
52     /**
53      * @return contains error message if {@link #isSuccessfull()} == {@code false}
54      */
55     public String getErrorMessage() {
56         return errorMessage;
57     }
58
59     /**
60      * @return {@code true} if {@link ClassificationResult} contains result. {@code false} if {@link ClassificationResult} contains error message.
61      */
62     public boolean isSuccessfull() {
63         return isSuccessful;
64     }
65 }