Finds a "valley" in this timeline that fits the given duration.
<p>
More formally, find smallest x that:
<ul>
<li>x >= start
<li>q(t) <= n for all t \in [x,x+duration)
</ul>

@return null
if no such x was found.
486850
Long fit(long start, long duration, int n) {
        OUTER:
        while (true) {
            long t = start;
            // check if 'start' satisfies the two conditions by moving t across [start,start+duration)
            while ((t-start)<duration) {
                if (at(t)>n) {
                    // value too big. what's the next t that's worth trying?
                    Long nxt = next(t);
                    if (nxt==null)  return null;
                    start = nxt;
                    continue OUTER;
                } else {
                    Long nxt = next(t);
                    if (nxt==null) t = Long.MAX_VALUE;
                    else           t = nxt;
                }
            }
            // q(t) looks good at the entire [start,start+duration)
            return start;
        }
    }
1356253
public LocalDateTime getStartAsLocalDateTime() {

        PlainTimestamp tsp = this.getStartAsTimestamp();
        return ((tsp == null) ? null : tsp.toTemporalAccessor());

    }
444842
public function min(Verta $v = null)
    {
        $v = $v ?: static::now($this->getTimezone());

        return $this->lt($v) ? $this : $v;
    }
348270
public Duration getUptime()
	{
		final DateTime startup = getStartupDate();
		if (null != startup)
		{
			return Duration.elapsed(Time.valueOf(startup.toDate()));
		}
		return Duration.NONE;
	}
289770
public int find(int cur) {
    assert (cur >= 0 && cur < parent.length);
    int p = parent[cur], tmp;
    while(cur != p) {
      tmp = p;
      p = parent[cur] = parent[p]; // Perform simple path compression.
      cur = tmp;
    }
    return cur;
  }
1098106
@Override
    protected Path findNext(){
        E elem = delegate.next();
        return elem==null ? null : path.append(elem, index()+1);
    }
1343576
public Long getPosition() {
        Interval interval = getInterval();
        if (interval != null) {
            return interval.getMinStart();
        } else {
            return null;
        }
    }
559451
public Date getFrom() {
        final TimeInterval first = intervals.first();
        if (first != null) {
            return new Date(first.getFrom());
        }
        return null;
    }
818253
public int find(double x) {
		if (x < xMinRangeLimit) return Integer.MIN_VALUE;
		else if (x >= xMaxRangeLimit) return Integer.MAX_VALUE;
		return findSmaller(ranges, x);
	}
1297610
public A next() {
        A x = elems.head;
        if (!elems.isEmpty()) {
            elems = elems.tail;
            if (elems.isEmpty()) last = null;
            count--;
        }
        return x;
    }
142288
T getClosedFiniteEnd() {

        T temporal = this.end.getTemporal();

        if ((temporal != null) && this.end.isOpen()) {
            return this.getTimeLine().stepBackwards(temporal);
        } else {
            return temporal;
        }

    }
1053082
@Override
    public LogRepositoryBrowser findByMillis(long timestamp) {
        File[] files = listFiles(instanceFilter);
        if (files == null) {
            return null;
        }

        File result = null;
        long max = Long.MIN_VALUE;
        for (File file : files) {
            long time = parseTimeStamp(file.getName());
            // Select file with a maximum time stamp which is smaller than 'timestamp'.
            if (max < time && (timestamp < 0 || time <= timestamp)) {
                max = time;
                result = file;
            }
        }

        // If all files has timestamp bigger than 'timestamp' return null.
        if (result == null) {
            return null;
        } else {
            return new LogRepositoryBrowserImpl(result, new String[] { result.getName() });
        }
    }
98829
@Override
    public LogRepositoryBrowser findNext(LogRepositoryBrowser current, long timelimit) {
        long cur;
        if (current == null) {
            cur = Long.MIN_VALUE;
        } else if (current instanceof LogRepositoryBrowserImpl) {
            // Check if it's an instance browser.
            if (((LogRepositoryBrowserImpl) current).getIds().length == 1) {
                cur = parseTimeStamp(((LogRepositoryBrowserImpl) current).getLocation().getName());
            } else {
                // 'subprocess' browsers are not ordered and as such do not have 'next'.
                return null;
            }
        } else {
            return null;
        }

        return findNext(cur, timelimit);
    }
1214970
public long getFirstTimeout()
    {
        long lastTimeout = Math.max(System.currentTimeMillis(), start); // d666295

        // If we're already past the end date, then there is no timeout.
        if (lastTimeout > end)
        {
            return -1;
        }

        return getTimeout(lastTimeout, false);
    }
864290
public static boolean isBetween(final Date start, final Date end, final Date between)
	{
		final long min = start.getTime();
		final long max = end.getTime();
		final long index = between.getTime();
		return min <= index && index <= max;
	}
1030169
def find_closest(pts, time)
      return pts.first if pts.size == 1
      midpoint = pts.size / 2
      if pts.size == 2
        diff_1 = pts[0].time - time
        diff_2 = pts[1].time - time
        return (diff_1 < diff_2 ? pts[0] : pts[1])
      end
      if (time >= pts[midpoint].time) && (time <= pts[midpoint + 1].time)
        return pts[midpoint]
      elsif time <= pts[midpoint].time
        return find_closest(pts[0..midpoint], time)
      else
        return find_closest(pts[(midpoint + 1)..-1], time)
      end
    end
526037
public ChronoInterval<T> getRange() {

        Boundary<T> start = Boundary.infinitePast();
        Boundary<T> end = Boundary.infiniteFuture();

        T min = this.getMinimum();
        T max = this.getMaximum();

        if (min != null) {
            start = Boundary.ofClosed(min);
        }

        if (max != null) {
            if (this.isCalendrical()) {
                end = Boundary.ofClosed(max);
            } else {
                T max2 = this.getTimeLine().stepForward(max);
                if (max2 != null) {
                    end = Boundary.ofOpen(max2);
                } else {
                    end = Boundary.ofClosed(max);
                }
            }
        }

        return this.newInterval(start, end);

    }