List of usage examples for com.google.common.collect Range hasUpperBound
public boolean hasUpperBound()
From source file:com.wealdtech.utils.RangeComparator.java
@Override public int compare(Range<C> range1, Range<C> range2) { int result = ((Boolean) range1.hasLowerBound()).compareTo(range2.hasLowerBound()); if (result == 0) { if (range1.hasLowerBound()) { result = range1.lowerEndpoint().compareTo(range2.lowerEndpoint()); if (result == 0) { result = range1.lowerBoundType().compareTo(range2.lowerBoundType()); }//from w ww. ja v a2 s . co m } } if (result == 0) { result = ((Boolean) range1.hasUpperBound()).compareTo(range2.hasUpperBound()); if (result == 0) { if (range1.hasUpperBound()) { result = range1.upperEndpoint().compareTo(range2.upperEndpoint()); if (result == 0) { result = range1.upperBoundType().compareTo(range2.upperBoundType()); } } } } return result; }
From source file:li.klass.fhem.activities.graph.ChartingActivity.java
private void setRangeFor(Optional<Range<Double>> axisRange, com.github.mikephil.charting.components.YAxis axis) { if (axisRange.isPresent()) { Range<Double> range = axisRange.get(); if (range.hasLowerBound()) { axis.setAxisMinValue(range.lowerEndpoint().floatValue()); }/*from ww w . j a v a 2 s. co m*/ if (range.hasUpperBound()) { axis.setAxisMinValue(range.upperEndpoint().floatValue()); } } }
From source file:com.google.android.apps.forscience.whistlepunk.sensordb.SensorDatabaseImpl.java
/** * Gets the selection string and selectionArgs based on the tag, range and resolution tier. * * @return a pair where the first element is the selection string and the second element is the * array of selectionArgs.//from ww w. ja v a 2s.com */ private Pair<String, String[]> getSelectionAndArgs(String sensorTag, TimeRange range, int resolutionTier) { List<String> clauses = new ArrayList<>(); List<String> values = new ArrayList<>(); clauses.add(ScalarSensorsTable.Column.TAG + " = ?"); values.add(sensorTag); if (resolutionTier >= 0) { clauses.add(ScalarSensorsTable.Column.RESOLUTION_TIER + " = ?"); values.add(String.valueOf(resolutionTier)); } Range<Long> times = range.getTimes(); Range<Long> canonicalTimes = times.canonical(DiscreteDomain.longs()); if (canonicalTimes.hasLowerBound()) { String comparator = (canonicalTimes.lowerBoundType() == BoundType.CLOSED) ? " >= ?" : " > ?"; clauses.add(ScalarSensorsTable.Column.TIMESTAMP_MILLIS + comparator); values.add(String.valueOf(canonicalTimes.lowerEndpoint())); } if (canonicalTimes.hasUpperBound()) { String comparator = (canonicalTimes.upperBoundType() == BoundType.CLOSED) ? " =< ?" : " < ?"; clauses.add(ScalarSensorsTable.Column.TIMESTAMP_MILLIS + comparator); values.add(String.valueOf(canonicalTimes.upperEndpoint())); } return new Pair<>(Joiner.on(" AND ").join(clauses), values.toArray(new String[values.size()])); }
From source file:org.obiba.opal.web.gwt.app.client.magma.derive.helper.DerivedNumericalVariableGenerator.java
private void appendBounds(Iterable<Range<N>> ranges) { scriptBuilder.append("["); boolean first = true; Range<N> previousRange = null; N bound = null;//from www . ja v a 2 s .co m for (Range<N> range : ranges) { if (previousRange != null && !previousRange.isConnected(range)) { appendBound(previousRange.upperEndpoint(), first); first = false; } if (range.hasLowerBound()) { bound = range.lowerEndpoint(); appendBound(bound, first); first = false; } previousRange = range; } // close the last range if (previousRange != null && previousRange.hasUpperBound()) { appendBound(previousRange.upperEndpoint(), false); } scriptBuilder.append("]"); }
From source file:org.pshdl.model.validation.builtin.BuiltInValidator.java
/** * * @param accessRange/*from w w w . j av a 2 s .c o m*/ * the range in which the array/bits can be acccessed * @param indexRange * the range of the size that array size/ width of the type can * be in * @param problems * problems will be added here * @param arr * the accessing {@link HDLExpression} * @param ref * the reference that is accessed * @param bit * when true bit access errors will be reported */ private static void checkAccessBoundaries(Range<BigInteger> accessRange, Range<BigInteger> declaredRange, Set<Problem> problems, IHDLObject arr, HDLVariableRef ref, boolean bit) { // Reduce the declaredRange to the index limits Range<BigInteger> indexRange; if (declaredRange.hasUpperBound()) { final BigInteger upperEndpoint = declaredRange.upperEndpoint(); final BigInteger subtract = upperEndpoint.subtract(BigInteger.ONE); if (subtract.compareTo(BigInteger.ZERO) < 0) // Maybe generate a warning here? return; indexRange = RangeTool.createRange(BigInteger.ZERO, subtract); } else { indexRange = Range.atLeast(BigInteger.ZERO); } final String info = "Expected value range:" + indexRange; // Check if highest idx is negative (Definitely a problem) if (accessRange.hasUpperBound() && (accessRange.upperEndpoint().signum() < 0)) { problems.add(new Problem(bit ? BIT_ACCESS_NEGATIVE : ARRAY_INDEX_NEGATIVE, arr, ref, info) .addMeta(ACCESS_RANGE, accessRange).addMeta(ARRAY_RANGE, indexRange)); // Check if lowest idx is negative (Might be a problem) } else if (accessRange.hasLowerBound() && (accessRange.lowerEndpoint().signum() < 0)) { problems.add( new Problem(bit ? BIT_ACCESS_POSSIBLY_NEGATIVE : ARRAY_INDEX_POSSIBLY_NEGATIVE, arr, ref, info) .addMeta(ACCESS_RANGE, accessRange).addMeta(ARRAY_RANGE, indexRange)); } // Check whether the index and the access have at least something in // common (index 0..5 access 7..9) if (!indexRange.isConnected(accessRange)) { problems.add(new Problem(bit ? BIT_ACCESS_OUT_OF_BOUNDS : ARRAY_INDEX_OUT_OF_BOUNDS, arr, ref, info) .addMeta(ACCESS_RANGE, accessRange).addMeta(ARRAY_RANGE, indexRange)); } else if (accessRange.hasUpperBound() && indexRange.hasUpperBound() && (accessRange.upperEndpoint().compareTo(indexRange.upperEndpoint()) > 0)) { problems.add(new Problem(bit ? BIT_ACCESS_POSSIBLY_OUT_OF_BOUNDS : ARRAY_INDEX_POSSIBLY_OUT_OF_BOUNDS, arr, ref, info).addMeta(ACCESS_RANGE, accessRange).addMeta(ARRAY_RANGE, indexRange)); } }
From source file:com.wealdtech.jackson.modules.DateTimeRangeSerializer.java
@Override public void serialize(final Range<DateTime> value, final JsonGenerator gen, final SerializerProvider provider) throws IOException { if (value != null) { final StringBuilder sb = new StringBuilder(64); if (value.hasLowerBound()) { if (value.lowerBoundType().equals(BoundType.CLOSED)) { sb.append('['); } else { sb.append('('); }//from w w w .j a v a 2 s. co m sb.append(formatter.print(value.lowerEndpoint())); } else { sb.append('('); sb.append(NEGATIVE_INFINITY); } sb.append(','); if (value.hasUpperBound()) { sb.append(formatter.print(value.upperEndpoint())); if (value.upperBoundType().equals(BoundType.CLOSED)) { sb.append(']'); } else { sb.append(')'); } } else { sb.append(POSITIVE_INFINITY); sb.append(')'); } gen.writeString(sb.toString()); } }
From source file:org.noroomattheinn.timeseries.PersistentTS.java
@Override public final synchronized void streamRows(Range<Long> period, RowCollector collector) { double accumulator[] = new double[schema.nColumns]; if (period == null) period = Range.all();//from w w w .j a va2s . co m long fromTime = period.hasLowerBound() ? period.lowerEndpoint() : 0L; long toTime = period.hasUpperBound() ? period.upperEndpoint() : Long.MAX_VALUE; long prevTime = 0; BufferedReader rdr = null; try { rdr = repo.getReader(); String line; while ((line = rdr.readLine()) != null) { if (line.startsWith("#")) { continue; } String[] tokens = line.split("\t"); // The first entry on the line is the time in delta format Long time = longValue(tokens[0]); if (time == null) { continue; } // Invalid format, ignore this line time = time < 0 ? -time : time + prevTime; prevTime = time; // Keep a running tally of the current time time = inflate(time); if (time < fromTime) continue; // Out of range, ignore & move on if (time > toTime) break; // Out of range, ignore & stop Row row = new Row(time, 0L, schema.nColumns); // The second element is a bitvector corresponding to which // columns have values on this line Long bitVector = longValue("0x" + tokens[1]); if (bitVector == null) { continue; } // Invalid format, Ignore this line row.bitVector = bitVector; // The remaining entries are readings. There is one reading for // each 1 bit in the bitvector. The positions in the bitvector // correspond to the columns in the order initially specified long bit = 1; int tokenIndex = 2; for (int i = 0; i < schema.nColumns; i++) { row.values[i] = accumulator[i]; // Start off with the previous value if (row.includes(bit)) { String valString = tokens[tokenIndex++]; switch (valString) { case "*": break; case "!": row.clear(bit); break; default: Double val = doubleValue(valString); if (val == null) { row.clear(bit); } else { accumulator[i] = row.values[i] = val.doubleValue(); } break; } } else { row.values[i] = accumulator[i]; } bit = bit << 1; } if (!collector.collect(row)) break; } } catch (IOException ex) { logger.severe("Error loading from repository" + ex); } if (rdr != null) try { rdr.close(); } catch (IOException e) { logger.warning("Failure closing reader: " + e); } }
From source file:com.google.eclipse.protobuf.validation.ProtobufJavaValidator.java
private void errorOnConflicts(Range<Long> range, Multimap<EObject, Range<Long>> rangeUsages, EObject errorSource, EStructuralFeature errorFeature) { for (Map.Entry<EObject, Range<Long>> rangeUsage : rangeUsages.entries()) { Range<Long> usedRange = rangeUsage.getValue(); if (range.isConnected(usedRange)) { EObject rangeUser = rangeUsage.getKey(); boolean rangeIsSingular = range.hasUpperBound() && range.upperEndpoint() == range.lowerEndpoint(); String template = rangeIsSingular ? tagNumberConflict : tagNumberRangeConflict; String rangeUserString; String usedRangeString = rangeToString(usedRange); if (rangeUser instanceof MessageField) { rangeUserString = String.format(conflictingField, nameResolver.nameOf(rangeUser), usedRangeString); } else if (rangeUser instanceof Group) { rangeUserString = String.format(conflictingGroup, nameResolver.nameOf(rangeUser), usedRangeString); } else if (rangeUser instanceof Reserved) { rangeUserString = String.format(conflictingReservedNumber, usedRangeString); } else { rangeUserString = String.format(conflictingExtensions, usedRangeString); }/*from ww w . jav a 2s . c o m*/ String message = String.format(template, rangeToString(range), rangeUserString); error(message, errorSource, errorFeature); // Don't report more than one error per element. return; } } }
From source file:org.pshdl.model.validation.builtin.BuiltInValidator.java
private static void checkType(HDLPackage unit, Set<Problem> problems, Map<HDLQualifiedName, HDLEvaluationContext> hContext) { final HDLVariableDeclaration[] hvds = unit.getAllObjectsOf(HDLVariableDeclaration.class, true); for (final HDLVariableDeclaration hvd : hvds) { final Optional<? extends HDLType> type = hvd.resolveType(); if (type.isPresent()) { final HDLType hdlType = type.get(); if (hdlType instanceof HDLPrimitive) { final HDLPrimitive primType = (HDLPrimitive) hdlType; switch (primType.getType()) { case BIT: case INTEGER: case NATURAL: break; case STRING: if (primType.getWidth() != null) { problems.add(new Problem(TYPE_INVALID_PRIMITIVE, hvd, "Strings can not have a width")); }//ww w . ja v a 2 s. c om break; case BOOL: if (primType.getWidth() != null) { problems.add(new Problem(TYPE_INVALID_PRIMITIVE, hvd, "Booleans can not have a width")); } break; case BITVECTOR: case INT: case UINT: final Optional<Range<BigInteger>> rangeOpt = RangeExtension.rangeOf(primType.getWidth()); if (rangeOpt.isPresent()) { final Range<BigInteger> range = rangeOpt.get(); if (!range.hasLowerBound()) { problems.add(new Problem(ErrorCode.TYPE_NEGATIVE_WIDTH, hvd)); } else { final BigInteger le = range.lowerEndpoint(); if (le.compareTo(BigInteger.ZERO) < 0) { if (range.hasUpperBound() && (range.upperEndpoint().compareTo(BigInteger.ZERO) < 0)) { problems.add(new Problem(ErrorCode.TYPE_NEGATIVE_WIDTH, hvd)); } else { problems.add(new Problem(ErrorCode.TYPE_POSSIBLY_NEGATIVE_WIDTH, hvd)); } } else if (le.equals(BigInteger.ZERO) && range.hasUpperBound() && range.upperEndpoint().equals(BigInteger.ZERO)) { problems.add(new Problem(ErrorCode.TYPE_ZERO_WIDTH, hvd)); } else if (le.equals(BigInteger.ZERO)) { problems.add(new Problem(ErrorCode.TYPE_POSSIBLY_ZERO_WIDTH, hvd)); } } } break; } } } } final HDLOpExpression[] ops = unit.getAllObjectsOf(HDLOpExpression.class, true); for (final HDLOpExpression ope : ops) { if (skipExp(ope)) { continue; } checkOpExpression(problems, ope, ope); } final HDLManip[] manips = unit.getAllObjectsOf(HDLManip.class, true); for (final HDLManip manip : manips) { final Optional<? extends HDLType> targetType = TypeExtension.typeOf(manip.getTarget()); if (targetType.isPresent()) { final HDLType tt = targetType.get(); switch (manip.getType()) { case ARITH_NEG: if (tt instanceof HDLPrimitive) { final HDLPrimitive primitive = (HDLPrimitive) tt; if (!primitive.isNumber()) { problems.add(new Problem(UNSUPPORTED_TYPE_FOR_OP, manip, "Can not use arithmetic negate on a non-number")); } } else { problems.add(new Problem(UNSUPPORTED_TYPE_FOR_OP, manip, "Can not use arithmetic negate on a non-number")); } break; case BIT_NEG: if (manip.getTarget().getClassType() == HDLClass.HDLLiteral) { problems.add(new Problem(UNSUPPORTED_TYPE_FOR_OP, manip, "Can not use binary negate on literals as they have no width")); } if (tt instanceof HDLPrimitive) { final HDLPrimitive primitive = (HDLPrimitive) tt; if (!primitive.isBits()) { problems.add(new Problem(UNSUPPORTED_TYPE_FOR_OP, manip, "Can not use binary negate on a non-bits")); } } else { problems.add(new Problem(UNSUPPORTED_TYPE_FOR_OP, manip, "Can not use binary negate on a non-bits")); } break; case LOGIC_NEG: if (tt instanceof HDLPrimitive) { final HDLPrimitive primitive = (HDLPrimitive) tt; if ((primitive.getType() != HDLPrimitiveType.BOOL) && (primitive.getType() != HDLPrimitiveType.BIT)) { problems.add(new Problem(BOOL_NEGATE_NUMERIC_NOT_SUPPORTED, manip, "Can not use logic negate on a non boolean/bit")); } } else { problems.add(new Problem(UNSUPPORTED_TYPE_FOR_OP, manip, "Can not use logic negate on a non boolean")); } break; case CAST: final HDLType castTo = manip.getCastTo(); if (castTo instanceof HDLInterface) { if (!(tt instanceof HDLInterface)) { problems.add(new Problem(UNSUPPORTED_TYPE_FOR_OP, manip, "Can not cast from interface to non interface type:" + castTo)); } } if (castTo instanceof HDLEnum) { problems.add( new Problem(UNSUPPORTED_TYPE_FOR_OP, manip, "Enums can not be casted to anything")); } if (castTo instanceof HDLPrimitive) { if (!(tt instanceof HDLPrimitive)) { problems.add(new Problem(UNSUPPORTED_TYPE_FOR_OP, manip, "Can not cast from primitve to non primitive type:" + castTo)); } } break; } } } }
From source file:org.pshdl.model.extensions.RangeExtension.java
protected Optional<Range<BigInteger>> _determineRange(final HDLBitOp obj, final HDLEvaluationContext context) { HDLExpression _left = obj.getLeft(); final Optional<Range<BigInteger>> leftRange = this.determineRange(_left, context); boolean _isPresent = leftRange.isPresent(); boolean _not = (!_isPresent); if (_not) {//from www . java2 s. c o m return Optional.<Range<BigInteger>>absent(); } final Range<BigInteger> lrVal = leftRange.get(); boolean _or = false; boolean _hasLowerBound = lrVal.hasLowerBound(); boolean _not_1 = (!_hasLowerBound); if (_not_1) { _or = true; } else { boolean _hasUpperBound = lrVal.hasUpperBound(); boolean _not_2 = (!_hasUpperBound); _or = _not_2; } if (_or) { return Optional.<Range<BigInteger>>absent(); } HDLExpression _right = obj.getRight(); final Optional<Range<BigInteger>> rightRange = this.determineRange(_right, context); boolean _isPresent_1 = rightRange.isPresent(); boolean _not_3 = (!_isPresent_1); if (_not_3) { return Optional.<Range<BigInteger>>absent(); } final Range<BigInteger> rrVal = rightRange.get(); boolean _or_1 = false; boolean _hasLowerBound_1 = rrVal.hasLowerBound(); boolean _not_4 = (!_hasLowerBound_1); if (_not_4) { _or_1 = true; } else { boolean _hasUpperBound_1 = rrVal.hasUpperBound(); boolean _not_5 = (!_hasUpperBound_1); _or_1 = _not_5; } if (_or_1) { return Optional.<Range<BigInteger>>absent(); } HDLBitOp.HDLBitOpType _type = obj.getType(); final HDLBitOp.HDLBitOpType type = _type; boolean _matched = false; if (!_matched) { boolean _or_2 = false; boolean _equals = Objects.equal(type, HDLBitOp.HDLBitOpType.OR); if (_equals) { _or_2 = true; } else { boolean _equals_1 = Objects.equal(type, HDLBitOp.HDLBitOpType.XOR); _or_2 = _equals_1; } if (_or_2) { _matched = true; obj.<IHDLObject>addMeta(ProblemDescription.SOURCE, obj); obj.<ProblemDescription>addMeta(ProblemDescription.DESCRIPTION, ProblemDescription.BIT_NOT_SUPPORTED_FOR_RANGES); BigInteger _upperEndpoint = lrVal.upperEndpoint(); int _bitLength = _upperEndpoint.bitLength(); BigInteger _shiftLeft = BigInteger.ONE.shiftLeft(_bitLength); BigInteger _subtract = _shiftLeft.subtract(BigInteger.ONE); Range<BigInteger> _createRange = RangeTool.<BigInteger>createRange(BigInteger.ZERO, _subtract); return Optional.<Range<BigInteger>>of(_createRange); } } if (!_matched) { if (Objects.equal(type, HDLBitOp.HDLBitOpType.AND)) { _matched = true; obj.<IHDLObject>addMeta(ProblemDescription.SOURCE, obj); obj.<ProblemDescription>addMeta(ProblemDescription.DESCRIPTION, ProblemDescription.BIT_NOT_SUPPORTED_FOR_RANGES); BigInteger _upperEndpoint_1 = lrVal.upperEndpoint(); BigInteger _upperEndpoint_2 = rrVal.upperEndpoint(); int _bitLength_1 = _upperEndpoint_2.bitLength(); BigInteger _shiftLeft_1 = BigInteger.ONE.shiftLeft(_bitLength_1); BigInteger _subtract_1 = _shiftLeft_1.subtract(BigInteger.ONE); BigInteger _min = _upperEndpoint_1.min(_subtract_1); Range<BigInteger> _createRange_1 = RangeTool.<BigInteger>createRange(BigInteger.ZERO, _min); return Optional.<Range<BigInteger>>of(_createRange_1); } } if (!_matched) { boolean _or_3 = false; boolean _equals_2 = Objects.equal(type, HDLBitOp.HDLBitOpType.LOGI_AND); if (_equals_2) { _or_3 = true; } else { boolean _equals_3 = Objects.equal(type, HDLBitOp.HDLBitOpType.LOGI_OR); _or_3 = _equals_3; } if (_or_3) { _matched = true; obj.<IHDLObject>addMeta(ProblemDescription.SOURCE, obj); obj.<ProblemDescription>addMeta(ProblemDescription.DESCRIPTION, ProblemDescription.BOOLEAN_NOT_SUPPORTED_FOR_RANGES); Range<BigInteger> _createRange_2 = RangeTool.<BigInteger>createRange(BigInteger.ZERO, BigInteger.ONE); return Optional.<Range<BigInteger>>of(_createRange_2); } } throw new RuntimeException("Incorrectly implemented obj op"); }