JSword
  1. JSword
  2. JS-183

Comparison of TreeKeys can lead to false positives

    Details

    • Type: Bug Bug
    • Status: Open (View Workflow)
    • Priority: Critical Critical
    • Resolution: Unresolved
    • Affects Version/s: 1.6.1
    • Fix Version/s: None
    • Component/s: o.c.jsword.passage
    • Labels:
      None
    • Environment:

      All

      Description

      It could be that TreeKey comparison should also compare parents because some books like Pilgrim's Progress can have keys with identical names but different parents.

      Here is a junit
      Book book = getBook("Pilgrim");

      // flatten and cache all the keys
      List<Key> cachedKeyList = new ArrayList<Key>();
      for (Key key : book.getGlobalKeyList())

      { cachedKeyList.add(key); }

      // get Part II/First Stage key
      Key partIIFirstStage = cachedKeyList.get(20);
      assertEquals("wrong key", "THE FIRST STAGE", partIIFirstStage.getName()); // these 2 tests pass fine
      assertEquals("wrong key", "PART II", partIIFirstStage.getParent().getName()); // they just clarify which key we have

      // now try to find the above key in our cached list of keys but the wrong key is returned
      int indexOfKey = cachedKeyList.indexOf(partIIFirstStage);
      // this test fails because Part I/First Stage is returned instead of Part II/First Stage
      assertEquals("Wrong index", 20, indexOfKey);

        Activity

        Hide
        Martin Denham added a comment -

        I created a helper class in AB to compare TreeKeys that compares ancestors of keys too.

        I have attached it in case it is useful.

        Show
        Martin Denham added a comment - I created a helper class in AB to compare TreeKeys that compares ancestors of keys too. I have attached it in case it is useful.
        Hide
        DM Smith added a comment -

        Yes thanks!

        Show
        DM Smith added a comment - Yes thanks!

          People

          • Assignee:
            DM Smith
            Reporter:
            Martin Denham
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: