Example usage for com.google.common.collect Range open

List of usage examples for com.google.common.collect Range open

Introduction

In this page you can find the example usage for com.google.common.collect Range open.

Prototype

public static <C extends Comparable<?>> Range<C> open(C lower, C upper) 

Source Link

Document

Returns a range that contains all values strictly greater than lower and strictly less than upper .

Usage

From source file:com.rockhoppertech.music.series.time.TimeEvent.java

/**
 * @return an open {@code Range}//from w w  w .  j  av  a  2 s .c  o  m
 */
public Range<Double> getOpenRange() {
    return Range.open(this.startBeat, this.startBeat + this.duration);
}

From source file:ddf.catalog.filter.impl.SimpleFilterDelegate.java

public T propertyIsEqualTo(String propertyName, Date startDate, Date endDate) {
    return propertyIsEqualTo(propertyName, Range.open(startDate, endDate), Range.class,
            ComparisonPropertyOperation.IS_EQUAL_TO);
}

From source file:dollar.api.types.DollarRange.java

public DollarRange(boolean lowerBounds, boolean upperBounds, boolean closedLeft, boolean closedRight,
        @Nullable Value lower, @Nullable Value upper) {
    super();/*from   w w w  .jav  a2  s .  c  om*/
    Value lowerBound;
    Value upperBound;
    if ((lower != null) && (upper != null) && (lower.compareTo(upper) > 0)) {
        lowerBound = upper;
        upperBound = lower;
        reversed = true;
    } else {
        lowerBound = lower;
        upperBound = upper;
    }
    if (!lowerBounds && !upperBounds) {
        range = Range.all();
    } else if (!lowerBounds) {
        if (closedRight) {
            range = Range.atMost(upperBound);
        } else {
            range = Range.lessThan(upperBound);
        }
    } else if (!upperBounds) {
        if (closedLeft) {
            range = Range.atLeast(lowerBound);
        } else {
            range = Range.greaterThan(lowerBound);
        }
    } else if (closedLeft) {
        if (closedRight) {
            range = Range.closed(lowerBound, upperBound);
        } else {
            //openRight
            range = Range.closedOpen(lowerBound, upperBound);
        }
    } else if (!closedLeft) {
        //openLeft
        if (closedRight) {
            range = Range.openClosed(lowerBound, upperBound);
        } else {
            //openRight
            if (lowerBound.equals(upperBound)) {
                throw new IllegalArgumentException(
                        "Cannot have an open range with lower bounds being the same as upper " + "bounds");
            } else {
                range = Range.open(lowerBound, upperBound);
            }
        }
    } else {
        throw new IllegalStateException();
    }
}

From source file:com.wealdtech.jackson.modules.DateTimeRangeDeserializer.java

public static Range<DateTime> deserialize(final String txt) throws IOException {
      final int txtLen = txt.length();

      final int firstDateChar;
      boolean lowerClosed;
      if (txt.charAt(0) == '[') {
          firstDateChar = 1;//from w w w  .  j a  va2 s . c o  m
          lowerClosed = true;
      } else if (txt.charAt(0) == '(') {
          firstDateChar = 1;
          lowerClosed = false;
      } else if (txt.charAt(0) >= '0' && txt.charAt(0) <= '9') {
          // Lazy version
          firstDateChar = 0;
          lowerClosed = true;
      } else {
          throw new DataError.Bad("Unexpected first character in range \"" + txt + "\"");
      }

      boolean upperClosed;
      if (txt.charAt(txtLen - 1) == ']') {
          upperClosed = true;
      } else if (txt.charAt(txtLen - 1) == ')') {
          upperClosed = false;
      } else if (firstDateChar == 0) {
          upperClosed = false;
      } else {
          throw new DataError.Bad("Unexpected last character in range \"" + txt + "\"");
      }

      final Iterator<String> dateTimes;
      if (txt.indexOf(WEALD_SPLITTER_CHAR) != -1) {
          dateTimes = WEALD_SPLITTER.split(txt.substring(firstDateChar, txtLen - firstDateChar)).iterator();
      } else if (txt.indexOf(GUAVA_SPLITTER_CHAR) != -1) {
          dateTimes = GUAVA_SPLITTER.split(txt.substring(firstDateChar, txtLen - firstDateChar)).iterator();
      } else {
          throw new DataError.Bad("Cannot find a range separator in range \"" + txt + "\"");
      }
      String start = dateTimes.next();
      String end = dateTimes.next();

      boolean lowerBound;
      final DateTime lowerPoint;
      if (start.equals(NEGATIVE_INFINITY)) {
          lowerBound = false;
          lowerPoint = null;
      } else {
          lowerBound = true;
          lowerPoint = DateTimeDeserializer.deserialize(start);
      }

      boolean upperBound;
      final DateTime upperPoint;
      if (end.equals(POSITIVE_INFINITY)) {
          upperBound = false;
          upperPoint = null;
      } else {
          upperBound = true;
          upperPoint = DateTimeDeserializer.deserialize(end);
      }

      if (lowerBound == false && upperBound == false) {
          return Range.all();
      } else if (lowerBound == false) {
          // Upper present
          if (upperClosed == true) {
              return Range.lessThan(upperPoint);
          } else {
              return Range.atMost(upperPoint);
          }
      } else if (upperBound == false) {
          // Lower present
          if (lowerClosed == true) {
              return Range.atLeast(lowerPoint);
          } else {
              return Range.greaterThan(lowerPoint);
          }
      } else {
          // Both present
          if (lowerClosed == true) {
              if (upperClosed == true) {
                  return Range.closed(lowerPoint, upperPoint);
              } else {
                  return Range.closedOpen(lowerPoint, upperPoint);
              }
          } else {
              if (upperClosed == true) {
                  return Range.openClosed(lowerPoint, upperPoint);
              } else {
                  return Range.open(lowerPoint, upperPoint);
              }
          }
      }
  }

From source file:org.apache.brooklyn.entity.nosql.riak.RiakNodeImpl.java

@Override
protected Collection<Integer> getRequiredOpenPorts() {
    // TODO this creates a huge list of inbound ports; much better to define on a security group using range syntax!
    int erlangRangeStart = getConfig(ERLANG_PORT_RANGE_START).iterator().next();
    int erlangRangeEnd = getConfig(ERLANG_PORT_RANGE_END).iterator().next();

    Set<Integer> ports = MutableSet.copyOf(super.getRequiredOpenPorts());
    Set<Integer> erlangPorts = ContiguousSet.create(Range.open(erlangRangeStart, erlangRangeEnd),
            DiscreteDomain.integers());//from w w w .ja v a2s . c  om
    ports.addAll(erlangPorts);

    return ports;
}

From source file:org.noroomattheinn.visibletesla.data.StatsCollector.java

/**
 * Return an index on a set of rows covered by the period [startTime..endTime].
 * // w  w w.  j  a  v a2  s  .co  m
 * @param startTime Starting time for the period
 * @param endTime   Ending time for the period
 * @return A map from time -> Row for all rows in the time range
 */
NavigableMap<Long, Row> getRangeOfLoadedRows(long startTime, long endTime) {
    return getLoadedTimeSeries().getIndex(Range.open(startTime, endTime));
}

From source file:org.cinchapi.concourse.server.model.Ranges.java

/**
 * Return a new {@link Range} that is the merger (e.g. union) of {@code a}
 * and {@code b}. The new {@link Range} maintains both the lower and higher
 * endpoint/bound between the two inputs.
 * /*from  w  ww .  ja  va  2s  .co m*/
 * @param a
 * @param b
 * @return the union of {@code a} and {@code b}
 */
public static Range<Value> merge(Range<Value> a, Range<Value> b) {
    if (a.isConnected(b)) {
        boolean aStart = compareToLower(a, b) < 0;
        boolean aEnd = compareToUpper(a, b) > 0;
        boolean lower = getLowerBoundType(aStart ? a : b) == BoundType.CLOSED;
        boolean upper = getUpperBoundType(aStart ? a : b) == BoundType.CLOSED;
        if (lower && upper) {
            return Range.closed(getLowerEndpoint(aStart ? a : b), getUpperEndpoint(aEnd ? a : b));
        } else if (!lower && upper) {
            return Range.closedOpen(getLowerEndpoint(aStart ? a : b), getUpperEndpoint(aEnd ? a : b));
        } else if (lower && !upper) {
            return Range.openClosed(getLowerEndpoint(aStart ? a : b), getUpperEndpoint(aEnd ? a : b));
        } else {
            return Range.open(getLowerEndpoint(aStart ? a : b), getUpperEndpoint(aEnd ? a : b));
        }
    } else {
        return null;
    }
}

From source file:ddf.catalog.filter.impl.SimpleFilterDelegate.java

public T propertyIsNotEqualTo(String propertyName, Date startDate, Date endDate) {
    return propertyIsNotEqualTo(propertyName, Range.open(startDate, endDate), Range.class,
            ComparisonPropertyOperation.IS_NOT_EQUAL_TO);
}

From source file:org.cinchapi.concourse.server.model.Ranges.java

/**
 * Return the ranges that include the points that are in {@code a} or the
 * {@code b} one and not in their intersection. The return set will include
 * between 0 and 2 ranges that together include all the points that meet
 * this criteria.// w  w w  . j a v  a 2 s .  com
 * <p>
 * <strong>NOTE:</strong> If the two ranges do not intersect, then a
 * collection containing both of them is returned (since they already form
 * their xor).
 * </p>
 * 
 * @param a
 * @param b
 * @return the set or ranges that make uValue the symmetric difference
 *         between this range and the {@code other} one
 */
public static Iterable<Range<Value>> xor(Range<Value> a, Range<Value> b) {
    List<Range<Value>> ranges = Lists.newArrayList();
    try {
        Range<Value> intersection = a.intersection(b);
        boolean aStart = compareToLower(a, b) < 0;
        boolean aEnd = compareToUpper(a, b) > 0;
        boolean lower = getLowerBoundType(aStart ? a : b) == BoundType.CLOSED;
        boolean upper = getUpperBoundType(aEnd ? a : b) == BoundType.CLOSED;
        boolean interLower = getLowerBoundType(intersection) == BoundType.OPEN;
        boolean interUpper = getUpperBoundType(intersection) == BoundType.OPEN;
        Range<Value> first;
        if (lower && interLower) {
            first = Range.closed(getLowerEndpoint(aStart ? a : b), getLowerEndpoint(intersection));
        } else if (!lower && interLower) {
            first = Range.openClosed(getLowerEndpoint(aStart ? a : b), getLowerEndpoint(intersection));
        } else if (lower && !interLower) {
            first = Range.closedOpen(getLowerEndpoint(aStart ? a : b), getLowerEndpoint(intersection));
        } else {
            first = Range.open(getLowerEndpoint(aStart ? a : b), getLowerEndpoint(intersection));
        }
        Range<Value> second;
        if (interUpper && upper) {
            second = Range.closed(getUpperEndpoint(intersection), getUpperEndpoint(aEnd ? a : b));
        } else if (!interUpper && upper) {
            second = Range.openClosed(getUpperEndpoint(intersection), getUpperEndpoint(aEnd ? a : b));
        } else if (interUpper && !interUpper) {
            second = Range.closedOpen(getUpperEndpoint(intersection), getUpperEndpoint(aEnd ? a : b));
        } else {
            second = Range.open(getUpperEndpoint(intersection), getUpperEndpoint(aEnd ? a : b));
        }
        if (!first.isEmpty()) {
            ranges.add(first);
        }
        if (!second.isEmpty()) {
            ranges.add(second);
        }
    } catch (IllegalArgumentException e) { // ranges dont intersect
        ranges.add(a);
        ranges.add(b);
    }
    return ranges;
}

From source file:net.sf.mzmine.modules.masslistmethods.ADAPchromatogrambuilder.ChromatogramBuilderTask.java

/**
 * @see Runnable#run()//from ww w. j a  va2 s  .co  m
 */
public void run() {
    boolean writeChromCDF = true;

    setStatus(TaskStatus.PROCESSING);

    logger.info("Started chromatogram builder on " + dataFile);

    scans = scanSelection.getMatchingScans(dataFile);
    int allScanNumbers[] = scanSelection.getMatchingScanNumbers(dataFile);

    List<Double> rtListForChromCDF = new ArrayList<Double>();

    // Check if the scans are properly ordered by RT
    double prevRT = Double.NEGATIVE_INFINITY;
    for (Scan s : scans) {
        if (isCanceled()) {
            return;
        }

        if (writeChromCDF) {
            rtListForChromCDF.add(s.getRetentionTime());
        }

        if (s.getRetentionTime() < prevRT) {
            setStatus(TaskStatus.ERROR);
            final String msg = "Retention time of scan #" + s.getScanNumber()
                    + " is smaller then the retention time of the previous scan."
                    + " Please make sure you only use scans with increasing retention times."
                    + " You can restrict the scan numbers in the parameters, or you can use the Crop filter module";
            setErrorMessage(msg);
            return;
        }
        prevRT = s.getRetentionTime();
    }

    // Create new peak list
    newPeakList = new SimplePeakList(dataFile + " " + suffix, dataFile);

    // make a list of all the data points
    // sort data points by intensity
    // loop through list 
    //      add data point to chromatogrm or make new one
    //      update mz avg and other stuff
    // 

    // make a list of all the data points
    List<ExpandedDataPoint> allMzValues = new ArrayList<ExpandedDataPoint>();

    for (Scan scan : scans) {
        if (isCanceled())
            return;

        MassList massList = scan.getMassList(massListName);
        if (massList == null) {
            setStatus(TaskStatus.ERROR);
            setErrorMessage("Scan " + dataFile + " #" + scan.getScanNumber() + " does not have a mass list "
                    + massListName);
            return;
        }

        DataPoint mzValues[] = massList.getDataPoints();

        if (mzValues == null) {
            setStatus(TaskStatus.ERROR);
            setErrorMessage("Mass list " + massListName + " does not contain m/z values for scan #"
                    + scan.getScanNumber() + " of file " + dataFile);
            return;
        }

        for (DataPoint mzPeak : mzValues) {
            ExpandedDataPoint curDatP = new ExpandedDataPoint(mzPeak, scan.getScanNumber());
            allMzValues.add(curDatP);
            //corespondingScanNum.add(scan.getScanNumber());
        }

    }

    //Integer[] simpleCorespondingScanNums = new Integer[corespondingScanNum.size()];
    //corespondingScanNum.toArray(simpleCorespondingScanNums );

    ExpandedDataPoint[] simpleAllMzVals = new ExpandedDataPoint[allMzValues.size()];
    allMzValues.toArray(simpleAllMzVals);

    // sort data points by intensity
    Arrays.sort(simpleAllMzVals, new DataPointSorter(SortingProperty.Intensity, SortingDirection.Descending));

    //Set<Chromatogram> buildingChromatograms;
    //buildingChromatograms = new LinkedHashSet<Chromatogram>();

    double maxIntensity = simpleAllMzVals[0].getIntensity();

    // count starts at 1 since we already have added one with a single point.

    //Stopwatch stopwatch = Stopwatch.createUnstarted(); 
    // stopwatch2 = Stopwatch.createUnstarted(); 
    //Stopwatch stopwatch3 = Stopwatch.createUnstarted(); 

    totalPoints = simpleAllMzVals.length;

    for (ExpandedDataPoint mzPeak : simpleAllMzVals) {
        if (isCanceled()) {
            return;
        }

        if (mzPeak == null) {
            //System.out.println("null Peak");
            continue;
        }

        //////////////////////////////////////////////////

        Range<Double> containsPointRange = rangeSet.rangeContaining(mzPeak.getMZ());

        Range<Double> toleranceRange = mzTolerance.getToleranceRange(mzPeak.getMZ());
        if (containsPointRange == null) {
            // skip it entierly if the intensity is not high enough
            if (mzPeak.getIntensity() < minIntensityForStartChrom) {
                continue;
            }
            // look +- mz tolerance to see if ther is a range near by. 
            // If there is use the proper boundry of that range for the 
            // new range to insure than NON OF THE RANGES OVERLAP.
            Range<Double> plusRange = rangeSet.rangeContaining(toleranceRange.upperEndpoint());
            Range<Double> minusRange = rangeSet.rangeContaining(toleranceRange.lowerEndpoint());
            Double toBeLowerBound;
            Double toBeUpperBound;

            double cur_max_testing_mz = mzPeak.getMZ();

            // If both of the above ranges are null then we make the new range spaning the full
            // mz tolerance range. 
            // If one or both are not null we need to properly modify the range of the new
            // chromatogram so that none of the points are overlapping.
            if ((plusRange == null) && (minusRange == null)) {
                toBeLowerBound = toleranceRange.lowerEndpoint();
                toBeUpperBound = toleranceRange.upperEndpoint();
            } else if ((plusRange == null) && (minusRange != null)) {
                // the upper end point of the minus range will be the lower 
                // range of the new one
                toBeLowerBound = minusRange.upperEndpoint();
                toBeUpperBound = toleranceRange.upperEndpoint();

            } else if ((minusRange == null) && (plusRange != null)) {
                toBeLowerBound = toleranceRange.lowerEndpoint();
                toBeUpperBound = plusRange.lowerEndpoint();
                //                    double tmp_this = plusRange.upperEndpoint();
                //                    System.out.println("tmp_this");
            } else if ((minusRange != null) && (plusRange != null)) {
                toBeLowerBound = minusRange.upperEndpoint();
                toBeUpperBound = plusRange.lowerEndpoint();
            } else {
                toBeLowerBound = 0.0;
                toBeUpperBound = 0.0;
            }
            Range<Double> newRange = Range.open(toBeLowerBound, toBeUpperBound);
            Chromatogram newChrom = new Chromatogram(dataFile, allScanNumbers);

            newChrom.addMzPeak(mzPeak.getScanNumber(), mzPeak);

            newChrom.setHighPointMZ(mzPeak.getMZ());

            rangeToChromMap.put(newRange, newChrom);
            // also need to put it in the set -> this is where the range can be efficiently found.

            rangeSet.add(newRange);
        } else {
            // In this case we do not need to update the rangeSet

            Chromatogram curChrom = rangeToChromMap.get(containsPointRange);

            curChrom.addMzPeak(mzPeak.getScanNumber(), mzPeak);

            //update the entry in the map
            rangeToChromMap.put(containsPointRange, curChrom);

        }

        processedPoints += 1;
    }

    //System.out.println("search chroms (ms): " +  stopwatch.elapsed(TimeUnit.MILLISECONDS));
    //System.out.println("making new chrom (ms): " +  stopwatch2.elapsed(TimeUnit.MILLISECONDS));

    // finish chromatograms
    Iterator<Range<Double>> RangeIterator = rangeSet.asRanges().iterator();

    List<Chromatogram> buildingChromatograms = new ArrayList<Chromatogram>();

    while (RangeIterator.hasNext()) {
        if (isCanceled()) {
            return;
        }

        Range<Double> curRangeKey = RangeIterator.next();

        Chromatogram chromatogram = rangeToChromMap.get(curRangeKey);

        chromatogram.finishChromatogram();

        // And remove chromatograms who dont have a certian number of continous points above the
        // IntensityThresh2 level.
        double numberOfContinuousPointsAboveNoise = chromatogram
                .findNumberOfContinuousPointsAboveNoise(IntensityThresh2);
        if (numberOfContinuousPointsAboveNoise < minimumScanSpan) {
            //System.out.println("skipping chromatogram because it does not meet the min point scan requirements");
            continue;
        } else {
            buildingChromatograms.add(chromatogram);
        }

    }

    Chromatogram[] chromatograms = buildingChromatograms.toArray(new Chromatogram[0]);

    // Sort the final chromatograms by m/z
    Arrays.sort(chromatograms, new PeakSorter(SortingProperty.MZ, SortingDirection.Ascending));

    // Add the chromatograms to the new peak list
    for (Feature finishedPeak : chromatograms) {
        SimplePeakListRow newRow = new SimplePeakListRow(newPeakID);
        newPeakID++;
        newRow.addPeak(dataFile, finishedPeak);
        newPeakList.addRow(newRow);

        //            finishedPeak.outputChromToFile();
    }

    // Add new peaklist to the project
    project.addPeakList(newPeakList);

    // Add quality parameters to peaks
    QualityParameters.calculateQualityParameters(newPeakList);

    setStatus(TaskStatus.FINISHED);

    logger.info("Finished chromatogram builder on " + dataFile);
}