| 1 |
/* |
| 2 |
* Copyright (C) 2015 The Android Open Source Project |
| 3 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
* you may not use this file except in compliance with the License. |
| 5 |
* You may obtain a copy of the License at |
| 6 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 7 |
* Unless required by applicable law or agreed to in writing, software |
| 8 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 9 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 |
* See the License for the specific language governing permissions and |
| 11 |
* limitations under the License. |
| 12 |
*/ |
| 13 |
|
| 14 |
package android.databinding.tool.expr; |
| 15 |
|
| 16 |
public class Dependency { |
| 17 |
final Expr mDependant; |
| 18 |
final Expr mOther; |
| 19 |
final Expr mCondition; |
| 20 |
final boolean mExpectedOutput;// ! |
| 21 |
// set only if this is conditional. Means it has been resolved so that it can be used in |
| 22 |
// should get calculations |
| 23 |
boolean mElevated; |
| 24 |
|
| 25 |
// this means that trying to calculate the dependant expression w/o |
| 26 |
// will crash the app unless "Other" has a non-null value |
| 27 |
boolean mMandatory = false; |
| 28 |
|
| 29 |
public Dependency(Expr dependant, Expr other) { |
| 30 |
mDependant = dependant; |
| 31 |
mOther = other; |
| 32 |
mCondition = null; |
| 33 |
mOther.addDependant(this); |
| 34 |
mExpectedOutput = false; |
| 35 |
} |
| 36 |
|
| 37 |
public Dependency(Expr dependant, Expr other, Expr condition, boolean expectedOutput) { |
| 38 |
mDependant = dependant; |
| 39 |
mOther = other; |
| 40 |
mCondition = condition; |
| 41 |
mOther.addDependant(this); |
| 42 |
mExpectedOutput = expectedOutput; |
| 43 |
} |
| 44 |
|
| 45 |
public void setMandatory(boolean mandatory) { |
| 46 |
mMandatory = mandatory; |
| 47 |
} |
| 48 |
|
| 49 |
public boolean isMandatory() { |
| 50 |
return mMandatory; |
| 51 |
} |
| 52 |
|
| 53 |
public boolean isConditional() { |
| 54 |
return mCondition != null && !mElevated; |
| 55 |
} |
| 56 |
|
| 57 |
public Expr getOther() { |
| 58 |
return mOther; |
| 59 |
} |
| 60 |
|
| 61 |
public Expr getDependant() { |
| 62 |
return mDependant; |
| 63 |
} |
| 64 |
|
| 65 |
public boolean getExpectedOutput() { |
| 66 |
return mExpectedOutput; |
| 67 |
} |
| 68 |
|
| 69 |
public Expr getCondition() { |
| 70 |
return mCondition; |
| 71 |
} |
| 72 |
|
| 73 |
public void elevate() { |
| 74 |
mElevated = true; |
| 75 |
} |
| 76 |
|
| 77 |
public boolean isElevated() { |
| 78 |
return mElevated; |
| 79 |
} |
| 80 |
} |