⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 segmentedtimeline.java

📁 大家打开看看啊, 很有用的东西
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
         * @return The date.
         */
        public Date getDate() {
            return (SegmentedTimeline.this.getDate(index));
        }

        /**
         * Returns true if an index is contained in this segment.
         * @param index Index to verify
         * @return true if index is contained in the segment.
         */
        public boolean contains(long index) {
            return (segmentStart <= index && index <= segmentEnd);
        }

        /**
         * Returns true if an interval is contained in this segment.
         * 
         * @param from Begining of interval
         * @param to End of interval
         * 
         * @return true if interval is contained in the segment.
         */
        public boolean contains(long from, long to) {
            return (segmentStart <= from && to <= segmentEnd);
        }

        /**
         * Returns true if a segment is contained in this segment.
         * 
         * @param segment The segment to test for inclusion
         * 
         * @return true if the segment is contained in this segment.
         */
        public boolean contains(Segment segment) {
            return (contains(segment.getSegmentStart(), segment.getSegmentEnd()));
        }

        /**
         * Returns true if this segment is contained in an interval.
         * 
         * @param from Begining of interval
         * @param to End of interval
         * 
         * @return true this segment is contained in the interval
         */
        public boolean contained(long from, long to) {
            return (from <= segmentStart && segmentEnd <= to);
        }

        /**
         * Returns a segment that is the intersection of this segment and the interval.
         * @param from Begining of interval
         * @param to End of interval
         * @return true this segment is contained in the interval
         */
        public Segment intersect(long from, long to) {
            if (from <= segmentStart && segmentEnd <= to) {
                return (this);
            } 
            else {
                return (null);
            }
        }

        /**
         * Returns true if we are before another segment.
         * 
         * @param other The other segment to compare with us
         * 
         * @return true if we are before other
         */
        public boolean before(Segment other) {
            return (this.segmentEnd < other.getSegmentStart());
        }

        /**
         * Returns true if we are after another segment.
         * 
         * @param other The other segment to compare with us
         * 
         * @return true if we are after other
         */
        public boolean after(Segment other) {
            return (this.segmentStart > other.getSegmentEnd());
        }

        /**
         * Returns true if we are equal to another segment.
         * 
         * @param o The other segment to compare with us
         * 
         * @return true if we are the same segment
         */
        public boolean equals(Object o) {
            if (o instanceof Segment) {
                Segment other = (Segment) o;
                return (this.segmentNumber == other.getSegmentNumber() 
                        && this.segmentStart == other.getSegmentStart() 
                        && this.segmentEnd == other.getSegmentEnd() 
                        && this.index == other.getIndex());
            }
            else {
                return false;
            }
        }

        /**
         * Returns a copy of ourselves or null if there was an exception during
         * cloning.
         * 
         * @return a copy of ourselves.
         */
        public Segment copy() {
            try {
                return ((Segment) this.clone());
            } 
            catch (CloneNotSupportedException e) {
                return (null);
            }
        }

        /**
         * Will compare this Segment with another Segment (from Comparable interface).
         *
         * @param object The other Segment to compare with
         * 
         * @return -1: this < object, 0: this.equal(object) and +1: this > object
         */
        public int compareTo(Object object) {
            Segment other = (Segment) object;
            if (this.before(other)) {
                return -1;
            } 
            else if (this.after(other)) {
                return +1;
            } 
            else {
                return 0;
            }
        }

        /**
         * Returns true if we are an included segment and we are not an exception.
         * 
         * @return <code>true</code> or <code>false</code>.
         */
        public boolean inIncludeSegments() {
            if (getSegmentNumberRelativeToGroup() < segmentsIncluded) {
                return (!inExceptionSegments());
            } 
            else {
                return (false);
            }
        }

        /**
         * Returns true if we are an excluded segment.
         * 
         * @return <code>true</code> or <code>false</code>.
         */
        public boolean inExcludeSegments() {
            return (getSegmentNumberRelativeToGroup() >= segmentsIncluded);
        } 

        /**
         * Calculate the segment number relative to the segment group. This will be a number between
         * 0 and segmentsGroup-1. This value is calculated from the segmentNumber. Special care is
         * taken for negative segmentNumbers.
         * 
         * @return The segment number.
         */
        private long getSegmentNumberRelativeToGroup() {
            long p = (segmentNumber % segmentsGroup);
            if (p < 0) {
                p += segmentsGroup;
            }
            return (p);
        }

        /**
         * Returns true if we are an exception segment. This is implemented via
         * a binary search on the exceptionSegments sorted list.
         *
         * If the segment is not listed as an exception in our list and we have
         * a baseTimeline, a check is performed to see if the segment is inside
         * an excluded segment from our base. If so, it is also considered an
         * exception.
         *
         * @return true if we are an exception segment.
         */
        public boolean inExceptionSegments() {
            return (binarySearchExceptionSegments(this) >= 0);
        }

        /**
         * Increments the internal attributes of this segment by a number of
         * segments.
         *
         * @param n Number of segments to increment.
         */
        public void inc(long n) {
            segmentNumber += n;
            long m = n * segmentSize;
            segmentStart += m;
            segmentEnd += m;
            index += m;
        }

        /**
         * Increments the internal attributes of this segment by one segment.
         * The exact time incremented is segmentSize.
         */
        public void inc() {
            inc(1);
        } 

        /**
         * Moves the index of this segment to the beginning if the segment.
         */
        public void moveIndexToStart() {
            index = segmentStart;
        }

        /**
         * Moves the index of this segment to the end of the segment.
         */
        public void moveIndexToEnd() {
            index = segmentEnd;
        }

    }

    /**
     * Private internal class to represent a range of segments. This class is mainly used to
     * store in one object a range of exception segments. This optimizes certain timelines
     * that use a small segment size (like an intraday timeline) allowing them to express a day
     * exception as one SegmentRange instead of multi Segments.
     */
    protected class SegmentRange extends Segment { 

        /** The number of segments in the range. */
        private long segmentCount; 

        /**
         * Creates a SegmentRange between a start and end domain values.
         * @param fromDomainValue start of the range
         * @param toDomainValue en of the range
         */
        public SegmentRange(long fromDomainValue, long toDomainValue) {

            Segment start = getSegment(fromDomainValue);
            Segment end = getSegment(toDomainValue);
            if (start.getSegmentStart() != fromDomainValue 
                || end.getSegmentEnd() != toDomainValue) {
                throw new IllegalArgumentException("Invalid Segment Range ["
                    + fromDomainValue + "," + toDomainValue + "]");
            }

            this.index = fromDomainValue;
            this.segmentNumber = getSegmentNumber(index);
            this.segmentStart = fromDomainValue;
            this.segmentEnd = toDomainValue;
            this.segmentCount = (end.getSegmentNumber() - start.getSegmentNumber() + 1);
        }

        /**
         * Returns the number of segments contained in this range.
         * 
         * @return The segment count.
         */
        public long getSegmentCount() {
            return this.segmentCount;
        }

        /**
         * Returns a segment that is the intersection of this segment and the interval.
         * 
         * @param from Begining of interval
         * @param to End of interval
         * 
         * @return true this segment is contained in the interval
         */
        public Segment intersect(long from, long to) {
            long start = Math.max(from, segmentStart);
            long end = Math.min(to, segmentEnd);
            if (start <= end) {
                return (new SegmentRange(start, end));
            } 
            else {
                return (null);
            }
        }

        /**
         * Returns true if all Segments of this SegmentRenge are an included segment and are
         * not an exception.
         * 
         * @return <code>true</code> or </code>false</code>.
         */
        public boolean inIncludeSegments() {
            for (Segment segment = getSegment(segmentStart);
                segment.getSegmentStart() < segmentEnd;
                segment.inc()) {
                if (!segment.inIncludeSegments()) {
                    return (false);
                }
            }
            return (true);
        }

        /**
         * Returns true if we are an excluded segment.
         * 
         * @return <code>true</code> or </code>false</code>.
         */
        public boolean inExcludeSegments() {
            for (Segment segment = getSegment(segmentStart);
                segment.getSegmentStart() < segmentEnd;
                segment.inc()) {
                if (!segment.inExceptionSegments()) {
                    return (false);
                }
            }
            return (true);
        }

        /**
         * Not implemented for SegmentRange. Always throws IllegalArgumentException.
         *
         * @param n Number of segments to increment.
         */
        public void inc(long n) {
            throw new IllegalArgumentException("Not implemented in SegmentRange");
        }

    }

    /**
     * Special Segment Range that came from the BaseTimeline.
     */
    protected class BaseTimelineSegmentRange extends SegmentRange {

        /**
         * Constructor.
         * 
         * @param fromDomainValue  the start value.
         * @param toDomainValue  the end value.
         */
        public BaseTimelineSegmentRange(long fromDomainValue, long toDomainValue) {
            super(fromDomainValue, toDomainValue);
        }
       
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -