Java Code Examples for org.apache.commons.lang3.Range#getMaximum()

The following examples show how to use org.apache.commons.lang3.Range#getMaximum() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParallelAsync.java    From azure-cosmosdb-java with MIT License 6 votes vote down vote up
static Completable forEachAsync(Range<Integer> range, int partition, Action1<Integer> func) {

        int partitionSize = (range.getMaximum() - range.getMinimum()) / partition;
        List<Completable> task = new ArrayList<>();
        int startRange = range.getMinimum();
        for (int i = 0; i < partition; i++) {
            Range<Integer> integerRange = Range.between(startRange, startRange + partitionSize);
            task.add(Completable.defer(() -> {
                for(int j = integerRange.getMinimum(); j < integerRange.getMaximum();j++) {
                    func.call(j);
                }
                return Completable.complete();
            }));
            startRange = startRange + partitionSize ;
        }
        return Completable.mergeDelayError(task);
    }
 
Example 2
Source File: FeatureAttributeDimensionField.java    From geowave with Apache License 2.0 6 votes vote down vote up
public FeatureAttributeDimensionField(
    final AttributeDescriptor attributeDescriptor,
    final Range<Double> range) {
  super(
      range == null ? null
          : new BasicDimensionDefinition(range.getMinimum(), range.getMaximum()));
  writer =
      new FeatureAttributeWriterWrapper(
          (FieldWriter) FieldUtils.getDefaultWriterForClass(
              attributeDescriptor.getType().getBinding()));
  reader =
      new FeatureAttributeReaderWrapper(
          (FieldReader) FieldUtils.getDefaultReaderForClass(
              attributeDescriptor.getType().getBinding()));
  attributeName = attributeDescriptor.getLocalName();
}
 
Example 3
Source File: GameClass.java    From CodeDefenders with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Returns the empty lines which are covered by any of the already covered lines. An empty line
 * can be covered if it belongs to a method and is followed by a covered line (either empty or not)
 */
public List<Integer> getCoveredEmptyLines(List<Integer> alreadyCoveredLines) {
    visitCode();
    List<Integer> collect = new ArrayList<>();
    for (Range<Integer> linesOfMethod : linesOfMethods) {
        for (int line = linesOfMethod.getMinimum(); line < linesOfMethod.getMaximum(); line++) {
            if (emptyLines.contains(line)) {
                if (alreadyCoveredLines.contains(linesCoveringEmptyLines.get(line))) {
                    collect.add(line);
                }
            }
        }
    }
    return Collections.unmodifiableList(collect);
}
 
Example 4
Source File: TimeSpan.java    From dsworkbench with Apache License 2.0 4 votes vote down vote up
public boolean intersects(TimeSpan pSpan) {
  if (!this.getDirection().equals(pSpan.getDirection())) {
    //different directions
    return false;
  }
  
  //one of the spans uses manual Time (new intersect)
  Range<Long> thisSpan = this.getSpan();
  Range<Long> theOtherSpan = pSpan.getSpan();
  
  if(this.isValidAtEveryDay() || pSpan.isValidAtEveryDay()) {
      if(this.isValidAtSpecificDay() || pSpan.isValidAtSpecificDay()) {
        //remove day Information
        Long thisStart = DateUtils.getFragmentInMilliseconds(new Date(thisSpan.getMinimum()), Calendar.DATE);
        Long thisEnd = DateUtils.getFragmentInMilliseconds(new Date(thisSpan.getMaximum()), Calendar.DATE);
        thisSpan = Range.between(thisStart, thisEnd);
        
        Long otherStart = DateUtils.getFragmentInMilliseconds(new Date(theOtherSpan.getMinimum()), Calendar.DATE);
        Long otherEnd = DateUtils.getFragmentInMilliseconds(new Date(theOtherSpan.getMaximum()), Calendar.DATE);
        
        theOtherSpan = Range.between(otherStart, otherEnd);
        
        return thisSpan.isOverlappedBy(theOtherSpan);
      } else if(this.isValidAtEveryDay() && pSpan.isValidAtEveryDay()) {
        //both valid at every Day - just compare spans
        return thisSpan.isOverlappedBy(theOtherSpan);
      } else {
          //one span is for everyDay the other is over multiple Days
          //manual intersect
          Range<Long> always;
          Range<Long> manual;
          if(this.isValidAtEveryDay()) {
              always = thisSpan;
              manual = theOtherSpan;
          } else {
              always = theOtherSpan;
              manual = thisSpan;
          }
          
          long manualDate = DateUtils.truncate(new Date(manual.getMinimum()), Calendar.DATE).getTime();
          long manualStart = manual.getMinimum() - manualDate;
          long manualEnd = manual.getMaximum() - manualDate;
          
          if(manualEnd - manualStart > DateUtils.MILLIS_PER_DAY) {
              //must intersect somehow because span is longer than 1 Day
              return true;
          }
          //direct intersection
          manual = Range.between(manualStart, manualEnd);
          if(always.isOverlappedBy(manual)) return true;
          
          //should not be possible, because it should be handeld by isValidAtSpecificDay
          if(manualEnd <= DateUtils.MILLIS_PER_DAY) return false;
          
          //maybe intersection at next day
          manual = Range.between(new Long(0), manualEnd - DateUtils.MILLIS_PER_DAY);
          return always.isOverlappedBy(manual);
      }
  }
  
  return thisSpan.isOverlappedBy(theOtherSpan);
}
 
Example 5
Source File: TimeFrame.java    From dsworkbench with Apache License 2.0 4 votes vote down vote up
public List<Range<Long>> startTimespansToRanges() {
  List<Range<Long>> ranges = new LinkedList<>();
  Date startDate = DateUtils.truncate(new Date(startNotBefore), Calendar.DATE);

  for (TimeSpan span : sendTimeSpans) {
    if(!span.isValidAtEveryDay()) {
        Range<Long> range;
        //just copy range
        if(span.isValidAtExactTime()) {
          range = Range.between(span.getSpan().getMinimum(), span.getSpan().getMaximum() + fixedStartTimeRangeSize);
        } else {
          range = Range.between(span.getSpan().getMinimum(), span.getSpan().getMaximum());
        }
        
        if (range.getMaximum() > System.currentTimeMillis()) {
          if(range.getMinimum() <= System.currentTimeMillis()) {
              //rebuild Range
              range = Range.between(System.currentTimeMillis(), range.getMaximum());
          }
          //add range only if it is in future
          ranges.add(range);
        }
    }
    else {
      //span is valid for every day
      Date thisDate = new Date(startDate.getTime());
      //go through all days from start to end
      while (thisDate.getTime() < startNotAfter) {
        long spanStart = thisDate.getTime() + span.getSpan().getMinimum();
        long spanEnd = thisDate.getTime() + span.getSpan().getMaximum();
        Range<Long> newRange = null;
        //check span location relative to start frame
        if (spanStart >= startNotBefore && spanEnd > startNotBefore
            && spanStart < startNotAfter && spanEnd <= startNotAfter) {
          //|----------| (startNotBefore - startNotAfter)
          //  |----| (SpanStart - SpanEnd)
          newRange = Range.between(spanStart, spanEnd);
        } else if (spanStart < startNotBefore && spanEnd > startNotBefore
            && spanStart < startNotAfter && spanEnd <= startNotAfter) {
          //  |----------| (startNotBefore - startNotAfter)
          //|----| (SpanStart - SpanEnd)
          //set span start to 'startNotBefore'
          newRange = Range.between(startNotBefore, spanEnd);
        } else if (spanStart <= startNotBefore && spanEnd > startNotBefore
            && spanStart > startNotAfter && spanEnd >= startNotAfter) {
          //  |----------| (startNotBefore - startNotAfter)
          //|--------------| (SpanStart - SpanEnd)
          //set span start to 'startNotBefore'
          newRange = Range.between(startNotBefore, startNotAfter);
        } else if (spanStart >= startNotBefore && spanEnd > startNotBefore
            && spanStart < startNotAfter && spanEnd >= startNotAfter) {
          //|----------| (startNotBefore - startNotAfter)
          //    |---------| (SpanStart - SpanEnd)
          //set span start to 'startNotBefore'
          newRange = Range.between(spanStart, startNotAfter);
        }

        if (newRange != null) {
          if (newRange.getMinimum() < System.currentTimeMillis()) {
            //check minimum as current minimum is in past
            if (newRange.getMaximum() > System.currentTimeMillis()) {
              newRange = Range.between(System.currentTimeMillis(), newRange.getMaximum());
              ranges.add(newRange);
            }//ignore as entire range is in past
          } else {
            //add range as it is in future
            ranges.add(newRange);
          }
        }
        //increment current date by one day
        thisDate = DateUtils.addDays(thisDate, 1);
      }
    }
  }
  Collections.sort(ranges, new Comparator<Range<Long>>() {
    @Override
    public int compare(Range<Long> o1, Range<Long> o2) {
      return o1.getMinimum().compareTo(o2.getMinimum());
    }
  });
  return ranges;
}
 
Example 6
Source File: TimeFrame.java    From dsworkbench with Apache License 2.0 4 votes vote down vote up
public List<Range<Long>> arriveTimespansToRanges() {
  List<Range<Long>> ranges = new LinkedList<>();
  Date arriveDate = DateUtils.truncate(new Date(arriveNotBefore), Calendar.DAY_OF_MONTH);

  for (TimeSpan span : arriveTimeSpans) {
    if(!span.isValidAtEveryDay()) {
        Range<Long> range;
        //just copy range
        range = Range.between(span.getSpan().getMinimum(), span.getSpan().getMaximum());
        
        if (range.getMaximum() > System.currentTimeMillis()) {
          if(range.getMinimum() <= System.currentTimeMillis()) {
              //rebuild Range
              range = Range.between(System.currentTimeMillis(), range.getMaximum());
          }
          //add range only if it is in future
          ranges.add(range);
        }
    }
    else {
      //span is valid for every day
      Date thisDate = new Date(arriveDate.getTime());
      //go through all days from start to end
      while (thisDate.getTime() < arriveNotAfter) {
        long spanStart = thisDate.getTime() + span.getSpan().getMinimum();
        long spanEnd = thisDate.getTime() + span.getSpan().getMaximum();
        Range<Long> newRange = null;
        //check span location relative to start frame
        if (spanStart >= arriveNotBefore && spanEnd > arriveNotBefore
            && spanStart < arriveNotAfter && spanEnd <= arriveNotAfter) {
          //|----------| (startNotBefore - startNotAfter)
          //  |----| (SpanStart - SpanEnd)
          newRange = Range.between(spanStart, spanEnd);
        } else if (spanStart < arriveNotBefore && spanEnd > arriveNotBefore
            && spanStart < arriveNotAfter && spanEnd <= arriveNotAfter) {
          //  |----------| (startNotBefore - startNotAfter)
          //|----| (SpanStart - SpanEnd)
          //set span start to 'startNotBefore'
          newRange = Range.between(arriveNotBefore, spanEnd);
        } else if (spanStart <= arriveNotBefore && spanEnd > arriveNotBefore
            && spanStart > arriveNotAfter && spanEnd >= arriveNotAfter) {
          //  |----------| (startNotBefore - startNotAfter)
          //|--------------| (SpanStart - SpanEnd)
          //set span start to 'startNotBefore'
          newRange = Range.between(arriveNotBefore, arriveNotAfter);
        } else if (spanStart >= arriveNotBefore && spanEnd > arriveNotBefore
            && spanStart < arriveNotAfter && spanEnd >= arriveNotAfter) {
          //|----------| (startNotBefore - startNotAfter)
          //    |---------| (SpanStart - SpanEnd)
          //set span start to 'startNotBefore'
          newRange = Range.between(spanStart, arriveNotAfter);
        }

        if (newRange != null) {
          if (newRange.getMinimum() < System.currentTimeMillis()) {
            //check minimum as current minimum is in past
            if (newRange.getMaximum() > System.currentTimeMillis()) {
              newRange = Range.between(System.currentTimeMillis(), newRange.getMaximum());
              ranges.add(newRange);
            }//ignore as entire range is in past
          } else {
            //add range as it is in future
            ranges.add(newRange);
          }
        }
        //increment current date by one day
        thisDate = DateUtils.addDays(thisDate, 1);
      }
    }
  }
  Collections.sort(ranges, new Comparator<Range<Long>>() {
    @Override
    public int compare(Range<Long> o1, Range<Long> o2) {
      return o1.getMinimum().compareTo(o2.getMinimum());
    }
  });
  return ranges;
}
 
Example 7
Source File: IntervalPredicate.java    From metron with Apache License 2.0 4 votes vote down vote up
private boolean containsInclusive(Range<Long> interval, long ts) {
  return interval.contains(ts) || interval.getMaximum() == ts;
}
 
Example 8
Source File: MSSqlServerDialect.java    From sqlg with MIT License 4 votes vote down vote up
@Override
public String getRangeClause(Range<Long> r) {
    return "OFFSET " + r.getMinimum() + " ROWS FETCH NEXT " + (r.getMaximum() - r.getMinimum()) + " ROWS ONLY";
}
 
Example 9
Source File: SqlDialect.java    From sqlg with MIT License 2 votes vote down vote up
/**
 * range condition
 *
 * @param r range
 * @return
 */
default String getRangeClause(Range<Long> r) {
    return "LIMIT " + (r.getMaximum() - r.getMinimum()) + " OFFSET " + r.getMinimum();
}