1 46 47 package org.jfree.chart.axis; 48 49 import java.io.Serializable ; 50 import java.util.ArrayList ; 51 import java.util.Calendar ; 52 import java.util.Collections ; 53 import java.util.Date ; 54 import java.util.GregorianCalendar ; 55 import java.util.Iterator ; 56 import java.util.List ; 57 import java.util.SimpleTimeZone ; 58 import java.util.TimeZone ; 59 60 164 public class SegmentedTimeline implements Timeline, Cloneable , Serializable { 165 166 167 private static final long serialVersionUID = 1093779862539903110L; 168 169 173 174 public static final long DAY_SEGMENT_SIZE = 24 * 60 * 60 * 1000; 175 176 177 public static final long HOUR_SEGMENT_SIZE = 60 * 60 * 1000; 178 179 180 public static final long FIFTEEN_MINUTE_SEGMENT_SIZE = 15 * 60 * 1000; 181 182 183 public static final long MINUTE_SEGMENT_SIZE = 60 * 1000; 184 185 189 195 public static long FIRST_MONDAY_AFTER_1900; 196 197 202 public static TimeZone NO_DST_TIME_ZONE; 203 204 210 public static TimeZone DEFAULT_TIME_ZONE = TimeZone.getDefault(); 211 212 216 private Calendar workingCalendarNoDST 217 = new GregorianCalendar (NO_DST_TIME_ZONE); 218 219 222 private Calendar workingCalendar = Calendar.getInstance(); 223 224 228 229 private long segmentSize; 230 231 232 private int segmentsIncluded; 233 234 235 private int segmentsExcluded; 236 237 238 private int groupSegmentCount; 239 240 244 private long startTime; 245 246 247 private long segmentsIncludedSize; 248 249 250 private long segmentsExcludedSize; 251 252 253 private long segmentsGroupSize; 254 255 259 private List exceptionSegments = new ArrayList (); 260 261 271 private SegmentedTimeline baseTimeline; 272 273 274 private boolean adjustForDaylightSaving = false; 275 276 280 static { 281 int offset = TimeZone.getDefault().getRawOffset(); 283 NO_DST_TIME_ZONE = new SimpleTimeZone (offset, "UTC-" + offset); 284 285 Calendar cal = new GregorianCalendar (NO_DST_TIME_ZONE); 288 cal.set(1900, 0, 1, 0, 0, 0); 289 cal.set(Calendar.MILLISECOND, 0); 290 while (cal.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) { 291 cal.add(Calendar.DATE, 1); 292 } 293 FIRST_MONDAY_AFTER_1900 = cal.getTime().getTime(); 296 } 297 298 302 315 public SegmentedTimeline(long segmentSize, 316 int segmentsIncluded, 317 int segmentsExcluded) { 318 319 this.segmentSize = segmentSize; 320 this.segmentsIncluded = segmentsIncluded; 321 this.segmentsExcluded = segmentsExcluded; 322 323 this.groupSegmentCount = this.segmentsIncluded + this.segmentsExcluded; 324 this.segmentsIncludedSize = this.segmentsIncluded * this.segmentSize; 325 this.segmentsExcludedSize = this.segmentsExcluded * this.segmentSize; 326 this.segmentsGroupSize = this.segmentsIncludedSize 327 + this.segmentsExcludedSize; 328 329 } 330 331 339 public static SegmentedTimeline newMondayThroughFridayTimeline() { 340 SegmentedTimeline timeline 341 = new SegmentedTimeline(DAY_SEGMENT_SIZE, 5, 2); 342 timeline.setStartTime(FIRST_MONDAY_AFTER_1900); 343 return timeline; 344 } 345 346 363 public static SegmentedTimeline newFifteenMinuteTimeline() { 364 SegmentedTimeline timeline 365 = new SegmentedTimeline(FIFTEEN_MINUTE_SEGMENT_SIZE, 28, 68); 366 timeline.setStartTime( 367 FIRST_MONDAY_AFTER_1900 + 36 * timeline.getSegmentSize() 368 ); 369 timeline.setBaseTimeline(newMondayThroughFridayTimeline()); 370 return timeline; 371 } 372 373 379 public boolean getAdjustForDaylightSaving() { 380 return this.adjustForDaylightSaving; 381 } 382 383 389 public void setAdjustForDaylightSaving(boolean adjust) { 390 this.adjustForDaylightSaving = adjust; 391 } 392 393 397 403 public void setStartTime(long millisecond) { 404 this.startTime = millisecond; 405 } 406 407 413 public long getStartTime() { 414 return this.startTime; 415 } 416 417 422 public int getSegmentsExcluded() { 423 return this.segmentsExcluded; 424 } 425 426 432 public long getSegmentsExcludedSize() { 433 return this.segmentsExcludedSize; 434 } 435 436 442 public int getGroupSegmentCount() { 443 return this.groupSegmentCount; 444 } 445 446 452 public long getSegmentsGroupSize() { 453 return this.segmentsGroupSize; 454 } 455 456 461 public int getSegmentsIncluded() { 462 return this.segmentsIncluded; 463 } 464 465 470 public long getSegmentsIncludedSize() { 471 return this.segmentsIncludedSize; 472 } 473 474 479 public long getSegmentSize() { 480 return this.segmentSize; 481 } 482 483 489 public List getExceptionSegments() { 490 return Collections.unmodifiableList(this.exceptionSegments); 491 } 492 493 498 public void setExceptionSegments(List exceptionSegments) { 499 this.exceptionSegments = exceptionSegments; 500 } 501 502 507 public SegmentedTimeline getBaseTimeline() { 508 return this.baseTimeline; 509 } 510 511 516 public void setBaseTimeline(SegmentedTimeline baseTimeline) { 517 518 if (baseTimeline != null) { 520 if (baseTimeline.getSegmentSize() < this.segmentSize) { 521 throw new IllegalArgumentException ( 522 "baseTimeline.getSegmentSize() is smaller than segmentSize" 523 ); 524 } 525 else if (baseTimeline.getStartTime() > this.startTime) { 526 throw new IllegalArgumentException ( 527 "baseTimeline.getStartTime() is after startTime" 528 ); 529 } 530 else if ((baseTimeline.getSegmentSize() % this.segmentSize) != 0) { 531 throw new IllegalArgumentException ( 532 "baseTimeline.getSegmentSize() is not multiple of " 533 + "segmentSize" 534 ); 535 } 536 else if (((this.startTime 537 - baseTimeline.getStartTime()) % this.segmentSize) != 0) { 538 throw new IllegalArgumentException ( 539 "baseTimeline is not aligned" 540 ); 541 } 542 } 543 544 this.baseTimeline = baseTimeline; 545 } 546 547 556 public long toTimelineValue(long millisecond) { 557 558 long result; 559 long rawMilliseconds = millisecond - this.startTime; 560 long groupMilliseconds = rawMilliseconds % this.segmentsGroupSize; 561 long groupIndex = rawMilliseconds / this.segmentsGroupSize; 562 563 if (groupMilliseconds >= this.segmentsIncludedSize) { 564 result = toTimelineValue( 565 this.startTime + this.segmentsGroupSize * (groupIndex + 1) 566 ); 567 } 568 else { 569 Segment segment = getSegment(millisecond); 570 if (segment.inExceptionSegments()) { 571 result = toTimelineValue(segment.getSegmentEnd() + 1); 572 } 573 else { 574 long shiftedSegmentedValue = millisecond - this.startTime; 575 long x = shiftedSegmentedValue % this.segmentsGroupSize; 576 long y = shiftedSegmentedValue / this.segmentsGroupSize; 577 578 long wholeExceptionsBeforeDomainValue = 579 getExceptionSegmentCount(this.startTime, millisecond - 1); 580 581 588 if (x < this.segmentsIncludedSize) { 589 result = this.segmentsIncludedSize * y 590 + x - wholeExceptionsBeforeDomainValue 591 * this.segmentSize; 592 } 594 else { 595 result = this.segmentsIncludedSize * (y + 1) 596 - wholeExceptionsBeforeDomainValue 597 * this.segmentSize; 598 } 600 } 601 } 602 603 return result; 604 } 605 606 615 public long toTimelineValue(Date date) { 616 return toTimelineValue(getTime(date)); 617 } 619 620 627 public long toMillisecond(long timelineValue) { 628 629 Segment result = new Segment(this.startTime + timelineValue 631 + (timelineValue / this.segmentsIncludedSize) 632 * this.segmentsExcludedSize); 633 634 long lastIndex = this.startTime; 635 636 while (lastIndex <= result.segmentStart) { 638 639 long exceptionSegmentCount; 641 while ((exceptionSegmentCount = getExceptionSegmentCount( 642 lastIndex, (result.millisecond / this.segmentSize) 643 * this.segmentSize - 1)) > 0 644 ) { 645 lastIndex = result.segmentStart; 646 for (int i = 0; i < exceptionSegmentCount; i++) { 649 do { 650 result.inc(); 651 } 652 while (result.inExcludeSegments()); 653 } 654 } 655 lastIndex = result.segmentStart; 656 657 while (result.inExceptionSegments() || result.inExcludeSegments()) { 659 result.inc(); 660 lastIndex += this.segmentSize; 661 } 662 663 lastIndex++; 664 } 665 666 return getTimeFromLong(result.millisecond); 667 } 668 669 676 public long getTimeFromLong(long date) { 677 long result = date; 678 if (this.adjustForDaylightSaving) { 679 this.workingCalendarNoDST.setTime(new Date (date)); 680 this.workingCalendar.set( 681 this.workingCalendarNoDST.get(Calendar.YEAR), 682 this.workingCalendarNoDST.get(Calendar.MONTH), 683 this.workingCalendarNoDST.get(Calendar.DATE), 684 this.workingCalendarNoDST.get(Calendar.HOUR_OF_DAY), 685 this.workingCalendarNoDST.get(Calendar.MINUTE), 686 this.workingCalendarNoDST.get(Calendar.SECOND) 687 ); 688 this.workingCalendar.set( 689 Calendar.MILLISECOND, 690 this.workingCalendarNoDST.get(Calendar.MILLISECOND) 691 ); 692 result = this.workingCalendar.getTime().getTime(); 695 } 696 return result; 697 } 698 699 706 public boolean containsDomainValue(long millisecond) { 707 Segment segment = getSegment(millisecond); 708 return segment.inIncludeSegments(); 709 } 710 711 718 public boolean containsDomainValue(Date date) { 719 return containsDomainValue(getTime(date)); 720 } 721 722 732 public boolean containsDomainRange(long domainValueStart, 733 long domainValueEnd) { 734 if (domainValueEnd < domainValueStart) { 735 throw new IllegalArgumentException ( 736 "domainValueEnd (" + domainValueEnd 737 + ") < domainValueStart (" + domainValueStart + ")" 738 ); 739 } 740 Segment segment = getSegment(domainValueStart); 741 boolean contains = true; 742 do { 743 contains = (segment.inIncludeSegments()); 744 if (segment.contains(domainValueEnd)) { 745 break; 746 } 747 else { 748 segment.inc(); 749 } 750 } 751 while (contains); 752 return (contains); 753 } 754 755 765 public boolean containsDomainRange(Date dateDomainValueStart, 766 Date dateDomainValueEnd) { 767 return containsDomainRange( 768 getTime(dateDomainValueStart), getTime(dateDomainValueEnd) 769 ); 770 } 771 772 784 public void addException(long millisecond) { 785 addException(new Segment(millisecond)); 786 } 787 788 803 public void addException(long fromDomainValue, long toDomainValue) { 804 addException(new SegmentRange(fromDomainValue, toDomainValue)); 805 } 806 807 818 public void addException(Date exceptionDate) { 819 addException(getTime(exceptionDate)); 820 } 822 823 835 public void addExceptions(List exceptionList) { 836 for (Iterator iter = exceptionList.iterator(); iter.hasNext();) { 837 addException((Date ) iter.next()); 838 } 839 } 840 841 851 private void addException(Segment segment) { 852 if (segment.inIncludeSegments()) { 853 int p = binarySearchExceptionSegments(segment); 854 this.exceptionSegments.add(-(p + 1), segment); 855 } 856 } 857 858 874 public void addBaseTimelineException(long domainValue) { 875 876 Segment baseSegment = this.baseTimeline.getSegment(domainValue); 877 if (baseSegment.inIncludeSegments()) { 878 879 Segment segment = getSegment(baseSegment.getSegmentStart()); 882 while (segment.getSegmentStart() <= baseSegment.getSegmentEnd()) { 883 if (segment.inIncludeSegments()) { 884 885 long fromDomainValue = segment.getSegmentStart(); 887 long toDomainValue; 888 do { 889 toDomainValue = segment.getSegmentEnd(); 890 segment.inc(); 891 } 892 while (segment.inIncludeSegments()); 893 894 addException(fromDomainValue, toDomainValue); 896 897 } 898 else { 899 segment.inc(); 901 } 902 } 903 } 904 } 905 906 918 public void addBaseTimelineException(Date date) { 919 addBaseTimelineException(getTime(date)); 920 } 921 922 931 public void addBaseTimelineExclusions(long fromBaseDomainValue, 932 long toBaseDomainValue) { 933 934 Segment baseSegment = this.baseTimeline.getSegment(fromBaseDomainValue); 936 while (baseSegment.getSegmentStart() <= toBaseDomainValue 937 && !baseSegment.inExcludeSegments()) { 938 939 baseSegment.inc(); 940 941 } 942 943 while (baseSegment.getSegmentStart() <= toBaseDomainValue) { 945 946 long baseExclusionRangeEnd = baseSegment.getSegmentStart() 947 + this.baseTimeline.getSegmentsExcluded() 948 * this.baseTimeline.getSegmentSize() - 1; 949 950 Segment segment = getSegment(baseSegment.getSegmentStart()); 953 while (segment.getSegmentStart() <= baseExclusionRangeEnd) { 954 if (segment.inIncludeSegments()) { 955 956 long fromDomainValue = segment.getSegmentStart(); 958 long toDomainValue; 959 do { 960 toDomainValue = segment.getSegmentEnd(); 961 segment.inc(); 962 } 963 while (segment.inIncludeSegments()); 964 965 addException(new BaseTimelineSegmentRange( 967 fromDomainValue, toDomainValue 968 )); 969 } 970 else { 971 segment.inc(); 973 } 974 } 975 976 baseSegment.inc(this.baseTimeline.getGroupSegmentCount()); 978 } 979 } 980 981 990 public long getExceptionSegmentCount(long fromMillisecond, 991 long toMillisecond) { 992 if (toMillisecond < fromMillisecond) { 993 return (0); 994 } 995 996 int n = 0; 997 for (Iterator iter = this.exceptionSegments.iterator(); 998 iter.hasNext();) { 999 Segment segment = (Segment) iter.next(); 1000 Segment intersection 1001 = segment.intersect(fromMillisecond, toMillisecond); 1002 if (intersection != null) { 1003 n += intersection.getSegmentCount(); 1004 } 1005 } 1006 1007 return (n); 1008 } 1009 1010 1021 public Segment getSegment(long millisecond) { 1022 return new Segment(millisecond); 1023 } 1024 1025 1039 public Segment getSegment(Date date) { 1040 return (getSegment(getTime(date))); 1041 } 1042 1043 1053 private boolean equals(Object o, Object p) { 1054 return (o == p || ((o != null) && o.equals(p))); 1055 } 1056 1057 1064 public boolean equals(Object o) { 1065 if (o instanceof SegmentedTimeline) { 1066 SegmentedTimeline other = (SegmentedTimeline) o; 1067 1068 boolean b0 = (this.segmentSize == other.getSegmentSize()); 1069 boolean b1 = (this.segmentsIncluded == other.getSegmentsIncluded()); 1070 boolean b2 = (this.segmentsExcluded == other.getSegmentsExcluded()); 1071 boolean b3 = (this.startTime == other.getStartTime()); 1072 boolean b4 = equals( 1073 this.exceptionSegments, other.getExceptionSegments() 1074 ); 1075 return b0 && b1 && b2 && b3 && b4; 1076 } 1077 else { 1078 return (false); 1079 } 1080 } 1081 1082 1087 public int hashCode() { 1088 int result = 19; 1089 result = 37 * result 1090 + (int) (this.segmentSize ^ (this.segmentSize >>> 32)); 1091 result = 37 * result + (int) (this.startTime ^ (this.startTime >>> 32)); 1092 return result; 1093 } 1094 1095 1110 private int binarySearchExceptionSegments(Segment segment) { 1111 int low = 0; 1112 int high = this.exceptionSegments.size() - 1; 1113 1114 while (low <= high) { 1115 int mid = (low + high) / 2; 1116 Segment midSegment = (Segment) this.exceptionSegments.get(mid); 1117 1118 if (segment.contains(midSegment) || midSegment.contains(segment)) { 1120 return mid; 1121 } 1122 1123 if (midSegment.before(segment)) { 1124 low = mid + 1; 1125 } 1126 else if (midSegment.after(segment)) { 1127 high = mid - 1; 1128 } 1129 else { 1130 throw new IllegalStateException ("Invalid condition."); 1131 } 1132 } 1133 return -(low + 1); } 1135 1136 1146 public long getTime(Date date) { 1147 long result = date.getTime(); 1148 if (this.adjustForDaylightSaving) { 1149 this.workingCalendar.setTime(date); 1150 this.workingCalendarNoDST.set( 1151 this.workingCalendar.get(Calendar.YEAR), 1152 this.workingCalendar.get(Calendar.MONTH), 1153 this.workingCalendar.get(Calendar.DATE), 1154 this.workingCalendar.get(Calendar.HOUR_OF_DAY), 1155 this.workingCalendar.get(Calendar.MINUTE), 1156 this.workingCalendar.get(Calendar.SECOND) 1157 ); 1158 this.workingCalendarNoDST.set( 1159 Calendar.MILLISECOND, 1160 this.workingCalendar.get(Calendar.MILLISECOND) 1161 ); 1162 Date revisedDate = this.workingCalendarNoDST.getTime(); 1163 result = revisedDate.getTime(); 1164 } 1165 1166 return result; 1167 } 1168 1169 1176 public Date getDate(long value) { 1177 this.workingCalendarNoDST.setTime(new Date (value)); 1178 return (this.workingCalendarNoDST.getTime()); 1179 } 1180 1181 1188 public Object clone() throws CloneNotSupportedException { 1189 SegmentedTimeline clone = (SegmentedTimeline) super.clone(); 1190 return clone; 1191 } 1192 1193 1201 public class Segment implements Comparable , Cloneable , Serializable { 1202 1203 1204 protected long segmentNumber; 1205 1206 1207 protected long segmentStart; 1208 1209 1210 protected long segmentEnd; 1211 1212 1213 protected long millisecond; 1214 1215 1218 protected Segment() { 1219 } 1221 1222 1227 protected Segment(long millisecond) { 1228 this.segmentNumber = calculateSegmentNumber(millisecond); 1229 this.segmentStart = SegmentedTimeline.this.startTime 1230 + this.segmentNumber * SegmentedTimeline.this.segmentSize; 1231 this.segmentEnd 1232 = this.segmentStart + SegmentedTimeline.this.segmentSize - 1; 1233 this.millisecond = millisecond; 1234 } 1235 1236 1243 public long calculateSegmentNumber(long millis) { 1244 if (millis >= SegmentedTimeline.this.startTime) { 1245 return (millis - SegmentedTimeline.this.startTime) 1246 / SegmentedTimeline.this.segmentSize; 1247 } 1248 else { 1249 return ((millis - SegmentedTimeline.this.startTime) 1250 / SegmentedTimeline.this.segmentSize) - 1; 1251 } 1252 } 1253 1254 1259 public long getSegmentNumber() { 1260 return this.segmentNumber; 1261 } 1262 1263 1269 public long getSegmentCount() { 1270 return 1; 1271 } 1272 1273 1278 public long getSegmentStart() { 1279 return this.segmentStart; 1280 } 1281 1282 1287 public long getSegmentEnd() { 1288 return this.segmentEnd; 1289 } 1290 1291 1297 public long getMillisecond() { 1298 return this.millisecond; 1299 } 1300 1301 1307 public Date getDate() { 1308 return SegmentedTimeline.this.getDate(this.millisecond); 1309 } 1310 1311 1320 public boolean contains(long millis) { 1321 return (this.segmentStart <= millis && millis <= this.segmentEnd); 1322 } 1323 1324 1334 public boolean contains(long from, long to) { 1335 return (this.segmentStart <= from && to <= this.segmentEnd); 1336 } 1337 1338 1346 public boolean contains(Segment segment) { 1347 return contains(segment.getSegmentStart(), segment.getSegmentEnd()); 1348 } 1349 1350 1360 public boolean contained(long from, long to) { 1361 return (from <= this.segmentStart && this.segmentEnd <= to); 1362 } 1363 1364 1373 public Segment intersect(long from, long to) { 1374 if (from <= this.segmentStart && this.segmentEnd <= to) { 1375 return this; 1376 } 1377 else { 1378 return null; 1379 } 1380 } 1381 1382 1390 public boolean before(Segment other) { 1391 return (this.segmentEnd < other.getSegmentStart()); 1392 } 1393 1394 1402 public boolean after(Segment other) { 1403 return (this.segmentStart > other.getSegmentEnd()); 1404 } 1405 1406 1414 public boolean equals(Object object) { 1415 if (object instanceof Segment) { 1416 Segment other = (Segment) object; 1417 return (this.segmentNumber == other.getSegmentNumber() 1418 && this.segmentStart == other.getSegmentStart() 1419 && this.segmentEnd == other.getSegmentEnd() 1420 && this.millisecond == other.getMillisecond()); 1421 } 1422 else { 1423 return false; 1424 } 1425 } 1426 1427 1433 public Segment copy() { 1434 try { 1435 return (Segment) this.clone(); 1436 } 1437 catch (CloneNotSupportedException e) { 1438 return null; 1439 } 1440 } 1441 1442 1451 public int compareTo(Object object) { 1452 Segment other = (Segment) object; 1453 if (this.before(other)) { 1454 return -1; 1455 } 1456 else if (this.after(other)) { 1457 return +1; 1458 } 1459 else { 1460 return 0; 1461 } 1462 } 1463 1464 1470 public boolean inIncludeSegments() { 1471 if (getSegmentNumberRelativeToGroup() 1472 < SegmentedTimeline.this.segmentsIncluded) { 1473 return !inExceptionSegments(); 1474 } 1475 else { 1476 return false; 1477 } 1478 } 1479 1480 1485 public boolean inExcludeSegments() { 1486 return getSegmentNumberRelativeToGroup() 1487 >= SegmentedTimeline.this.segmentsIncluded; 1488 } 1489 1490 1498 private long getSegmentNumberRelativeToGroup() { 1499 long p = (this.segmentNumber 1500 % SegmentedTimeline.this.groupSegmentCount); 1501 if (p < 0) { 1502 p += SegmentedTimeline.this.groupSegmentCount; 1503 } 1504 return p; 1505 } 1506 1507 1518 public boolean inExceptionSegments() { 1519 return binarySearchExceptionSegments(this) >= 0; 1520 } 1521 1522 1528 public void inc(long n) { 1529 this.segmentNumber += n; 1530 long m = n * SegmentedTimeline.this.segmentSize; 1531 this.segmentStart += m; 1532 this.segmentEnd += m; 1533 this.millisecond += m; 1534 } 1535 1536 1540 public void inc() { 1541 inc(1); 1542 } 1543 1544 1550 public void dec(long n) { 1551 this.segmentNumber -= n; 1552 long m = n * SegmentedTimeline.this.segmentSize; 1553 this.segmentStart -= m; 1554 this.segmentEnd -= m; 1555 this.millisecond -= m; 1556 } 1557 1558 1562 public void dec() { 1563 dec(1); 1564 } 1565 1566 1569 public void moveIndexToStart() { 1570 this.millisecond = this.segmentStart; 1571 } 1572 1573 1576 public void moveIndexToEnd() { 1577 this.millisecond = this.segmentEnd; 1578 } 1579 1580 } 1581 1582 1589 protected class SegmentRange extends Segment { 1590 1591 1592 private long segmentCount; 1593 1594 1600 public SegmentRange(long fromMillisecond, long toMillisecond) { 1601 1602 Segment start = getSegment(fromMillisecond); 1603 Segment end = getSegment(toMillisecond); 1604 1610 this.millisecond = fromMillisecond; 1611 this.segmentNumber = calculateSegmentNumber(fromMillisecond); 1612 this.segmentStart = start.segmentStart; 1613 this.segmentEnd = end.segmentEnd; 1614 this.segmentCount 1615 = (end.getSegmentNumber() - start.getSegmentNumber() + 1); 1616 } 1617 1618 1623 public long getSegmentCount() { 1624 return this.segmentCount; 1625 } 1626 1627 1636 public Segment intersect(long from, long to) { 1637 1638 long start = Math.max(from, this.segmentStart); 1643 long end = Math.min(to, this.segmentEnd); 1644 if (start <= end) { 1649 return new SegmentRange(start, end); 1650 } 1651 else { 1652 return null; 1653 } 1654 } 1655 1656 1662 public boolean inIncludeSegments() { 1663 for (Segment segment = getSegment(this.segmentStart); 1664 segment.getSegmentStart() < this.segmentEnd; 1665 segment.inc()) { 1666 if (!segment.inIncludeSegments()) { 1667 return (false); 1668 } 1669 } 1670 return true; 1671 } 1672 1673 1678 public boolean inExcludeSegments() { 1679 for (Segment segment = getSegment(this.segmentStart); 1680 segment.getSegmentStart() < this.segmentEnd; 1681 segment.inc()) { 1682 if (!segment.inExceptionSegments()) { 1683 return (false); 1684 } 1685 } 1686 return true; 1687 } 1688 1689 1695 public void inc(long n) { 1696 throw new IllegalArgumentException ( 1697 "Not implemented in SegmentRange" 1698 ); 1699 } 1700 1701 } 1702 1703 1706 protected class BaseTimelineSegmentRange extends SegmentRange { 1707 1708 1714 public BaseTimelineSegmentRange(long fromDomainValue, 1715 long toDomainValue) { 1716 super(fromDomainValue, toDomainValue); 1717 } 1718 1719 } 1720 1721} 1722 | Popular Tags |