366 }
367 else {
368 Entry[] entries = (Entry[])o;
369 for (Entry e : entries) {
370 if (isInList(e.testCase, testCase))
371 return e;
372 }
373 return null;
374 }
375 }
376
377 /**
378 * Merge the contents of another exclude list into this one.
379 * The individual entries are merged; The title of the exclude list
380 * being merged is ignored.
381 * @param other the exclude list to be merged with this one.
382 *
383 */
384 public void merge(ExcludeList other) {
385 synchronized (table) {
386 for (Iterator iter = other.getIterator(false); iter.hasNext(); ) {
387 Entry otherEntry = (Entry) (iter.next());
388 Key key = new Key(otherEntry.relativeURL);
389 Object o = table.get(key);
390 if (o == null) {
391 // Easy case: nothing already exists in the table, so just
392 // add this one
393 table.put(key, otherEntry);
394 }
395 else if (o instanceof Entry) {
396 // A single entry exists in the table
397 Entry curr = (Entry)o;
398 if (curr.testCase == null || otherEntry.testCase == null) {
399 table.put(key, new Entry(curr.relativeURL, null,
400 mergeBugIds(curr.bugIdStrings, otherEntry.bugIdStrings),
401 mergePlatforms(curr.platforms, otherEntry.platforms),
402 mergeSynopsis(curr.synopsis, otherEntry.synopsis)));
403 }
404 else
405 table.put(key, new Entry[] {curr, otherEntry});
406 }
510 if (o instanceof Entry[])
511 n += ((Entry[]) o).length;
512 else
513 n++;
514 }
515 return n;
516 }
517
518 /**
519 * Iterate over the contents of the table.
520 * @param group if <code>true</code>, entries for the same relative
521 * URL are grouped together, and if more than one, returned in an
522 * array; if <code>false</code>, the iterator always returns
523 * separate entries.
524 * @see Entry
525 * @return an iterator for the table: the entries are either
526 * single instances of @link(Entry) or a mixture of @link(Entry)
527 * and @link(Entry)[], depending on the <code>group</code>
528 * parameter.
529 */
530 public Iterator<Object> getIterator(boolean group) {
531 if (group)
532 return table.values().iterator();
533 else {
534 // flatten the enumeration into a vector, then
535 // enumerate that
536 Vector<Object> v = new Vector<>(table.size());
537 for (Object o : table.values()) {
538 if (o instanceof Entry)
539 v.addElement(o);
540 else {
541 for (Entry entry : (Entry[]) o) v.addElement(entry);
542 }
543 }
544 return v.iterator();
545 }
546
547 }
548
549 /**
550 * Get the title for this exclude list.
559 * Set the title for this exclude list.
560 * @param title the title for this exclude list
561 * @see #getTitle
562 */
563 public void setTitle(String title) {
564 this.title = title;
565 }
566
567 /**
568 * Write the table out to a file.
569 * @param f The file to which the table should be written.
570 * @throws IOException is thrown if any problems occur while the
571 * file is being written.
572 */
573 public void write(File f) throws IOException {
574 // sort the entries for convenience, and measure col widths
575 int maxURLWidth = 0;
576 int maxBugIdWidth = 0;
577 int maxPlatformWidth = 0;
578 SortedSet<Entry> entries = new TreeSet<>();
579 for (Iterator iter = getIterator(false); iter.hasNext(); ) {
580 Entry entry = (Entry) (iter.next());
581 entries.add(entry);
582 if (entry.testCase == null)
583 maxURLWidth = Math.max(entry.relativeURL.length(), maxURLWidth);
584 else
585 maxURLWidth = Math.max(entry.relativeURL.length() + entry.testCase.length() + 2, maxURLWidth);
586 maxBugIdWidth = Math.max(bugIdsToString(entry).length(), maxBugIdWidth);
587 maxPlatformWidth = Math.max(platformsToString(entry).length(), maxPlatformWidth);
588 }
589
590 BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), StandardCharsets.UTF_8));
591 out.write("# Exclude List");
592 out.newLine();
593 out.write("# SCCS %" + 'W' + "% %" + 'E' + "%"); // TAKE CARE WITH SCCS HEADERS
594 out.newLine();
595 if (title != null) {
596 out.write("### title " + title);
597 out.newLine();
598 }
599 for (Entry e : entries) {
919
920 if (c2 == sep)
921 c2 = '/';
922 else if(!caseSensitive)
923 c2 = Character.toLowerCase(c2);
924
925 if (c1 != c2)
926 return false;
927 }
928 return true;
929 }
930
931 private static final char sep = File.separatorChar;
932 private String relativeURL;
933 private int hash;
934 }
935
936 /**
937 * An entry in the exclude list.
938 */
939 public static final class Entry implements Comparable {
940 /**
941 * Create an ExcludeList entry.
942 * @param u The URL for the test, specified relative to the test suite root.
943 * @param tc One or more test cases within the test to be excluded.
944 * @param b An array of bug identifiers, justifying why the test is excluded.
945 * @param p An array of platform identifiers, on which the faults are
946 * known to occur
947 * @param s A short synopsis of the reasons why the test is excluded.
948 */
949 public Entry(String u, String tc, String[] b, String[] p, String s) {
950 if (b == null || p == null)
951 throw new NullPointerException();
952
953 // The file format cannot support platforms but no bugids,
954 // so fault that; other combinations (bugs, no platforms;
955 // no bugs, no platforms etc) are acceptable.
956 if (b.length == 0 && p.length > 0)
957 throw new IllegalArgumentException();
958
959 relativeURL = u;
977 throw new NullPointerException();
978
979 // The file format cannot support platforms but no bugids,
980 // so fault that; other combinations (bugs, no platforms;
981 // no bugs, no platforms etc) are acceptable.
982 if (b.length == 0 && p.length > 0)
983 throw new IllegalArgumentException();
984
985 relativeURL = u;
986 testCase = tc;
987
988 bugIdStrings = new String[b.length];
989 for (int i = 0; i < b.length; i++)
990 bugIdStrings[i] = String.valueOf(b[i]);
991 bugIds = b;
992
993 platforms = p;
994 synopsis = s;
995 }
996
997 public int compareTo(Object o) {
998 Entry e = (Entry) o;
999 int n = relativeURL.compareTo(e.relativeURL);
1000 if (n == 0) {
1001 if (testCase == null && e.testCase == null)
1002 return 0;
1003 else if (testCase == null)
1004 return -1;
1005 else if (e.testCase == null)
1006 return +1;
1007 else
1008 return testCase.compareTo(e.testCase);
1009 }
1010 else
1011 return n;
1012 }
1013
1014 /**
1015 * Get the relative URL identifying the test referenced by this entry.
1016 * @return the relative URL identifying the test referenced by this entry
1017 */
1018 public String getRelativeURL() {
|
366 }
367 else {
368 Entry[] entries = (Entry[])o;
369 for (Entry e : entries) {
370 if (isInList(e.testCase, testCase))
371 return e;
372 }
373 return null;
374 }
375 }
376
377 /**
378 * Merge the contents of another exclude list into this one.
379 * The individual entries are merged; The title of the exclude list
380 * being merged is ignored.
381 * @param other the exclude list to be merged with this one.
382 *
383 */
384 public void merge(ExcludeList other) {
385 synchronized (table) {
386 for (Iterator<?> iter = other.getIterator(false); iter.hasNext(); ) {
387 Entry otherEntry = (Entry) (iter.next());
388 Key key = new Key(otherEntry.relativeURL);
389 Object o = table.get(key);
390 if (o == null) {
391 // Easy case: nothing already exists in the table, so just
392 // add this one
393 table.put(key, otherEntry);
394 }
395 else if (o instanceof Entry) {
396 // A single entry exists in the table
397 Entry curr = (Entry)o;
398 if (curr.testCase == null || otherEntry.testCase == null) {
399 table.put(key, new Entry(curr.relativeURL, null,
400 mergeBugIds(curr.bugIdStrings, otherEntry.bugIdStrings),
401 mergePlatforms(curr.platforms, otherEntry.platforms),
402 mergeSynopsis(curr.synopsis, otherEntry.synopsis)));
403 }
404 else
405 table.put(key, new Entry[] {curr, otherEntry});
406 }
510 if (o instanceof Entry[])
511 n += ((Entry[]) o).length;
512 else
513 n++;
514 }
515 return n;
516 }
517
518 /**
519 * Iterate over the contents of the table.
520 * @param group if <code>true</code>, entries for the same relative
521 * URL are grouped together, and if more than one, returned in an
522 * array; if <code>false</code>, the iterator always returns
523 * separate entries.
524 * @see Entry
525 * @return an iterator for the table: the entries are either
526 * single instances of @link(Entry) or a mixture of @link(Entry)
527 * and @link(Entry)[], depending on the <code>group</code>
528 * parameter.
529 */
530 public Iterator<?> getIterator(boolean group) {
531 if (group)
532 return table.values().iterator();
533 else {
534 // flatten the enumeration into a vector, then
535 // enumerate that
536 Vector<Object> v = new Vector<>(table.size());
537 for (Object o : table.values()) {
538 if (o instanceof Entry)
539 v.addElement(o);
540 else {
541 for (Entry entry : (Entry[]) o) v.addElement(entry);
542 }
543 }
544 return v.iterator();
545 }
546
547 }
548
549 /**
550 * Get the title for this exclude list.
559 * Set the title for this exclude list.
560 * @param title the title for this exclude list
561 * @see #getTitle
562 */
563 public void setTitle(String title) {
564 this.title = title;
565 }
566
567 /**
568 * Write the table out to a file.
569 * @param f The file to which the table should be written.
570 * @throws IOException is thrown if any problems occur while the
571 * file is being written.
572 */
573 public void write(File f) throws IOException {
574 // sort the entries for convenience, and measure col widths
575 int maxURLWidth = 0;
576 int maxBugIdWidth = 0;
577 int maxPlatformWidth = 0;
578 SortedSet<Entry> entries = new TreeSet<>();
579 for (Iterator<?> iter = getIterator(false); iter.hasNext(); ) {
580 Entry entry = (Entry) (iter.next());
581 entries.add(entry);
582 if (entry.testCase == null)
583 maxURLWidth = Math.max(entry.relativeURL.length(), maxURLWidth);
584 else
585 maxURLWidth = Math.max(entry.relativeURL.length() + entry.testCase.length() + 2, maxURLWidth);
586 maxBugIdWidth = Math.max(bugIdsToString(entry).length(), maxBugIdWidth);
587 maxPlatformWidth = Math.max(platformsToString(entry).length(), maxPlatformWidth);
588 }
589
590 BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), StandardCharsets.UTF_8));
591 out.write("# Exclude List");
592 out.newLine();
593 out.write("# SCCS %" + 'W' + "% %" + 'E' + "%"); // TAKE CARE WITH SCCS HEADERS
594 out.newLine();
595 if (title != null) {
596 out.write("### title " + title);
597 out.newLine();
598 }
599 for (Entry e : entries) {
919
920 if (c2 == sep)
921 c2 = '/';
922 else if(!caseSensitive)
923 c2 = Character.toLowerCase(c2);
924
925 if (c1 != c2)
926 return false;
927 }
928 return true;
929 }
930
931 private static final char sep = File.separatorChar;
932 private String relativeURL;
933 private int hash;
934 }
935
936 /**
937 * An entry in the exclude list.
938 */
939 public static final class Entry implements Comparable<Entry> {
940 /**
941 * Create an ExcludeList entry.
942 * @param u The URL for the test, specified relative to the test suite root.
943 * @param tc One or more test cases within the test to be excluded.
944 * @param b An array of bug identifiers, justifying why the test is excluded.
945 * @param p An array of platform identifiers, on which the faults are
946 * known to occur
947 * @param s A short synopsis of the reasons why the test is excluded.
948 */
949 public Entry(String u, String tc, String[] b, String[] p, String s) {
950 if (b == null || p == null)
951 throw new NullPointerException();
952
953 // The file format cannot support platforms but no bugids,
954 // so fault that; other combinations (bugs, no platforms;
955 // no bugs, no platforms etc) are acceptable.
956 if (b.length == 0 && p.length > 0)
957 throw new IllegalArgumentException();
958
959 relativeURL = u;
977 throw new NullPointerException();
978
979 // The file format cannot support platforms but no bugids,
980 // so fault that; other combinations (bugs, no platforms;
981 // no bugs, no platforms etc) are acceptable.
982 if (b.length == 0 && p.length > 0)
983 throw new IllegalArgumentException();
984
985 relativeURL = u;
986 testCase = tc;
987
988 bugIdStrings = new String[b.length];
989 for (int i = 0; i < b.length; i++)
990 bugIdStrings[i] = String.valueOf(b[i]);
991 bugIds = b;
992
993 platforms = p;
994 synopsis = s;
995 }
996
997 public int compareTo(Entry e) {
998 int n = relativeURL.compareTo(e.relativeURL);
999 if (n == 0) {
1000 if (testCase == null && e.testCase == null)
1001 return 0;
1002 else if (testCase == null)
1003 return -1;
1004 else if (e.testCase == null)
1005 return +1;
1006 else
1007 return testCase.compareTo(e.testCase);
1008 }
1009 else
1010 return n;
1011 }
1012
1013 /**
1014 * Get the relative URL identifying the test referenced by this entry.
1015 * @return the relative URL identifying the test referenced by this entry
1016 */
1017 public String getRelativeURL() {
|