本文整理了Java中org.onosproject.yang.compiler.datamodel.YangRangeRestriction
类的一些代码示例,展示了YangRangeRestriction
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YangRangeRestriction
类的具体详情如下:
包路径:org.onosproject.yang.compiler.datamodel.YangRangeRestriction
类名称:YangRangeRestriction
[英]Represents ascending range restriction information.
[中]表示升序范围限制信息。
代码示例来源:origin: org.onosproject/onos-yang-compiler-datamodel
/**
* Creates a YANG length restriction object.
*/
public YangLengthRestriction() {
setLengthRestriction(new YangRangeRestriction<>(null));
yangAppErrorInfo = new YangAppErrorInfo();
}
代码示例来源:origin: org.onosproject/onos-yang-compiler-datamodel
/**
* Returns the minimum valid value as per the restriction.
*
* @return minimum restricted value
* @throws DataModelException data model exception for minimum restriction
*/
public T getMinRestrictedValue() throws DataModelException {
if (getAscendingRangeIntervals() == null) {
throw new DataModelException(getErrorMsg(
"No range restriction info ",
"", getLineNumber(), getCharPosition(), getFileName() + "\""));
}
if (getAscendingRangeIntervals().isEmpty()) {
throw new DataModelException(getErrorMsg(
"No range interval info ",
"", getLineNumber(), getCharPosition(), getFileName() + "\""));
}
return getAscendingRangeIntervals().get(0).getStartValue();
}
代码示例来源:origin: org.onosproject/onos-yang-compiler-datamodel
/**
* Validates if the given interval is correct as per the restriction.
*
* @param rangeInterval range interval
* @param fileName file name
* @return true, if the interval is confirming to restriction, false otherwise
* @throws DataModelException data model error
*/
boolean isValidInterval(YangRangeInterval rangeInterval, String fileName)
throws DataModelException {
if (getAscendingRangeIntervals() == null
|| getAscendingRangeIntervals().isEmpty()) {
// Throw exception, At least one default range needs to be set in
// constructor or in linker.
throw new DataModelException(getErrorMsg(
"Range interval missing in range restriction. ",
"restriction ranges.", getLineNumber(), getCharPosition(), fileName + "\""));
}
for (YangRangeInterval<T> interval : getAscendingRangeIntervals()) {
int rangeStartCompareRes = interval.getStartValue().compareTo((T) rangeInterval.getStartValue());
int rangeEndCompareRes = interval.getEndValue().compareTo((T) rangeInterval.getEndValue());
if (rangeStartCompareRes <= 0 && rangeEndCompareRes >= 0) {
return true;
}
}
throw new DataModelException(getErrorMsg(
"Range interval doesn't fall within the referred restriction ranges ",
"restriction ranges.", getLineNumber(), getCharPosition(), fileName + "\""));
}
代码示例来源:origin: org.onosproject/onos-yang-compiler-parser
YangDataTypes dataType = type.getDataType();
YangRangeRestriction ranRes = new YangRangeRestriction(txt);
ranRes.setFileName(lis.getFileName());
ranRes.setCharPosition(pos);
ranRes.setLineNumber(line);
lis.getParsedDataStack().push(ranRes);
代码示例来源:origin: org.onosproject/onos-yang-compiler-datamodel
YangBuiltInDataTypeInfo<?> endValue;
String rangeArg = removeQuotesAndHandleConcat(curR.getRangeValue());
String[] rangeArguments = rangeArg.trim().split(quote(PIPE));
refR.getMinRestrictedValue() != null) {
startValue = refR.getMinRestrictedValue();
} else if (hasRefR && startInterval.equals(MAX_KEYWORD) &&
refR.getMaxRestrictedValue() != null) {
startValue = refR.getMaxRestrictedValue();
} else {
startValue = getDataObjectFromString(startInterval, type);
refR.getMinRestrictedValue() != null) {
endValue = refR.getMinRestrictedValue();
} else if (hasRefR && endInterval.equals(MAX_KEYWORD) &&
refR.getMaxRestrictedValue() != null) {
endValue = refR.getMaxRestrictedValue();
} else {
endValue = getDataObjectFromString(endInterval, type);
rangeInterval.setEndValue(endValue);
try {
curR.addRangeRestrictionInterval(rangeInterval);
} catch (DataModelException ex) {
ex.setLine(line);
代码示例来源:origin: org.onosproject/onos-yang-compiler-datamodel
/**
* Returns decimal64 default range restriction based on fraction-digits.
* If range restriction is not provided then this default range value will be applicable.
*
* @return range restriction
* @throws DataModelException a violation of data model rules
*/
public YangRangeRestriction getDefaultRangeRestriction() throws DataModelException {
YangRangeRestriction refRangeRestriction = new YangRangeRestriction(null);
YangRangeInterval rangeInterval = new YangRangeInterval<>();
rangeInterval.setCharPosition(getCharPosition());
rangeInterval.setLineNumber(getLineNumber());
rangeInterval.setFileName(getFileName());
FractionDigits.Range range = FractionDigits.getRange(fractionDigit);
rangeInterval.setStartValue(new YangDecimal64(new BigDecimal((range.getMin()))));
rangeInterval.setEndValue(new YangDecimal64(new BigDecimal((range.getMax()))));
refRangeRestriction.addRangeRestrictionInterval(rangeInterval);
return refRangeRestriction;
}
代码示例来源:origin: org.onosproject/onos-yang-compiler-datamodel
/**
* Resolves the length/range self and referred restriction, to check whether
* the all the range interval in self restriction is stricter than the
* referred typedef's restriction.
*
* @param refRestriction referred restriction
* @param curRestriction self restriction
*/
private void resolveLengthAndRangeRestriction(YangRangeRestriction refRestriction,
YangRangeRestriction curRestriction)
throws DataModelException {
for (Object curInterval : curRestriction.getAscendingRangeIntervals()) {
if (!(curInterval instanceof YangRangeInterval)) {
throw new DataModelException(getErrorMsg(
"Linker error: Current range intervals not processed correctly.",
"type.", getLineNumber(), getCharPosition(), getFileName()));
}
try {
refRestriction.isValidInterval((YangRangeInterval)
curInterval, getFileName());
} catch (DataModelException e) {
throw new DataModelException(getErrorMsg(
e.getMessage(), "type.", getLineNumber(), getCharPosition(),
getFileName()));
}
}
}
代码示例来源:origin: org.onosproject/onos-yang-compiler-datamodel
/**
* Validates if the given value is correct as per the length restriction.
*
* @param valueInString value
* @return true, if the value is confirming to length restriction, false otherwise
*/
boolean isValidStringOnLengthRestriction(String valueInString) {
if (lengthRestriction == null || lengthRestriction.getAscendingRangeIntervals() == null
|| lengthRestriction.getAscendingRangeIntervals().isEmpty()) {
// Length restriction is optional
return true;
}
ListIterator<YangRangeInterval<YangUint64>> rangeListIterator =
lengthRestriction.getAscendingRangeIntervals().listIterator();
boolean isMatched = false;
while (rangeListIterator.hasNext()) {
YangRangeInterval rangeInterval = rangeListIterator.next();
rangeInterval.setCharPosition(getCharPosition());
rangeInterval.setLineNumber(getLineNumber());
rangeInterval.setFileName(getFileName());
BigInteger startValue = ((YangUint64) rangeInterval.getStartValue()).getValue();
BigInteger endValue = ((YangUint64) rangeInterval.getEndValue()).getValue();
if (valueInString.length() >= startValue.intValue() &&
valueInString.length() <= endValue.intValue()) {
isMatched = true;
break;
}
}
return isMatched;
}
代码示例来源:origin: org.onosproject/onos-yang-compiler-parser
YangDataTypes dataType = type.getDataType();
YangRangeRestriction lenRes = new YangRangeRestriction(txt);
lenRes.setFileName(lis.getFileName());
lenRes.setCharPosition(pos);
lenRes.setLineNumber(line);
lis.getParsedDataStack().push(lenRes);
代码示例来源:origin: org.onosproject/onos-yang-compiler-datamodel
if (lengthRestriction == null || lengthRestriction.getAscendingRangeIntervals() == null
|| lengthRestriction.getAscendingRangeIntervals().isEmpty()) {
ListIterator<YangRangeInterval<YangUint64>> rangeListIterator = lengthRestriction.getAscendingRangeIntervals()
.listIterator();
boolean isMatched = false;
代码示例来源:origin: org.onosproject/onos-yang-compiler-datamodel
/**
* Returns the maximum valid value as per the restriction.
*
* @return minimum maximum value
* @throws DataModelException data model exception for maximum restriction
*/
public T getMaxRestrictedValue() throws DataModelException {
if (getAscendingRangeIntervals() == null) {
throw new DataModelException(getErrorMsg(
"No range restriction info ",
"", getLineNumber(), getCharPosition(), getFileName() + "\""));
}
if (getAscendingRangeIntervals().isEmpty()) {
throw new DataModelException(getErrorMsg(
"No range interval info ",
"", getLineNumber(), getCharPosition(), getFileName() + "\""));
}
return getAscendingRangeIntervals()
.get(getAscendingRangeIntervals().size() - 1).getEndValue();
}
代码示例来源:origin: org.onosproject/onos-yang-compiler-datamodel
rangeRestriction.getAscendingRangeIntervals().listIterator();
代码示例来源:origin: org.onosproject/onos-yang-compiler-datamodel
/**
* Adds new interval to extend its range in the last. i.e. newly added
* interval needs to be bigger than the biggest interval in the list.
*
* @param newInterval restricted length interval
* @throws DataModelException data model exception for range restriction
*/
public void addRangeRestrictionInterval(YangRangeInterval<T> newInterval)
throws DataModelException {
checkNotNull(newInterval);
checkNotNull(newInterval.getStartValue());
if (ascendingRangeIntervals == null) {
/*
* First interval that is being added, and it must be the smallest
* interval.
*/
ascendingRangeIntervals = new LinkedList<>();
ascendingRangeIntervals.add(newInterval);
return;
}
T curMaxvalue = getMaxRestrictedValue();
if (newInterval.getStartValue().compareTo(curMaxvalue) < 1) {
throw new DataModelException(getErrorMsg(
"New added range interval is lesser than the old interval(s) ",
"", getLineNumber(), getCharPosition(), getFileName() + "\""));
}
getAscendingRangeIntervals().add(getAscendingRangeIntervals().size(), newInterval);
}
代码示例来源:origin: org.onosproject/onos-yang-compiler-datamodel
rangeRestriction.getAscendingRangeIntervals().listIterator();
while (rangeListIterator.hasNext()) {
YangRangeInterval rangeInterval = rangeListIterator.next();
代码示例来源:origin: org.onosproject/onos-yang-compiler-datamodel
/**
* Validates if the given value is correct as per the restriction.
*
* @param valueInString value
* @return true, if the value is confirming to restriction, false otherwise
* @throws DataModelException data model error
*/
boolean isValidValueString(String valueInString) throws DataModelException {
if (getAscendingRangeIntervals() == null
|| getAscendingRangeIntervals().isEmpty()) {
// Throw exception, At least one default range needs to be set in
// constructor or in linker.
throw new DataModelException(getErrorMsg(
"Range interval missing in range restriction. ",
"", getLineNumber(), getCharPosition(), getFileName() + "\""));
}
YangDataTypes type = getAscendingRangeIntervals().get(0).getStartValue().getYangType();
YangBuiltInDataTypeInfo<?> value = getDataObjectFromString(valueInString, type);
for (YangRangeInterval<T> interval : getAscendingRangeIntervals()) {
int rangeStartCompareRes = interval.getStartValue().compareTo((T) value);
int rangeEndCompareRes = interval.getEndValue().compareTo((T) value);
if (rangeStartCompareRes <= 0 && rangeEndCompareRes >= 0) {
return true;
}
}
return false;
}
内容来源于网络,如有侵权,请联系作者删除!