@Test
  public void testShuffled() {

    for (Integer[] perm : perms) {
      Group group = new Group("group");

      for (Integer i : perm) {
        Item item = new Item(group, i);
        group.add(item);
      }

      Queueable[] elems = group.getQueue();
      for (Queueable elem : elems) {
        Item item = (Item) elem;
        //        System.out.print( " " + item.getSalience() + "/"  + item.getActivationNumber() +
        // "/" + item.getIndex() );
        if (item.getIndex() % 2 == 0) {
          group.remove(item);
          group.add(item);
        }
      }
      boolean ok = true;
      StringBuilder sb = new StringBuilder("queue:");
      for (int i = max - 1; i >= 0; i--) {
        int sal = group.getNext().getSalience();
        sb.append(" ").append(sal);
        if (sal != i) ok = false;
      }
      assertTrue("incorrect order in " + sb.toString(), ok);
      //      System.out.println( sb.toString() );
    }
  }
  public int load(Group group) throws IOException {
    int amount = 0;

    BufferedReader reader = new BufferedReader(new FileReader("src//football.dat"));
    RowReader loader = new RowReader();

    boolean firstLine = true;
    String line;
    String[] params;
    while ((line = reader.readLine()) != null) {
      if (firstLine) {
        firstLine = false;
        continue;
      }

      if ((params = loader.getParameters(line)) == null) {
        continue;
      }

      group.add(
          new FootballClub(
              params[1], // Team column
              Integer.parseInt(params[6]), // F column
              Integer.parseInt(params[7]) // A column
              ));
      amount++;
    }
    return amount;
  }
Example #3
0
 protected void mergeGroups(Group g1, Group g2) {
   System.err.println("mergeGroups(): seq " + g1.identity + " and " + g2.identity);
   // System.err.println("mergeGroups(): seq "+g1.sequenceNumber+" and "+g2.sequenceNumber);
   if (g1.sequenceNumber > g2.sequenceNumber) {
     // System.err.println("mergeGroups(): swapping before merging into "+g2.sequenceNumber);
     // swap them, since earliest encountered context takes priority
     Group gt = g1;
     g1 = g2;
     g2 = gt;
   }
   mergePatientContext(g1, g2.context);
   for (String sopInstanceUID : g2) {
     g1.add(sopInstanceUID);
     assert (mapOfSOPInstanceUIDToGroup.get(sopInstanceUID) == g2);
     mapOfSOPInstanceUIDToGroup.put(sopInstanceUID, g1);
   }
   for (String studyInstanceUID : mapOfStudyInstanceUIDToGroup.keySet()) {
     Group g = mapOfStudyInstanceUIDToGroup.get(studyInstanceUID);
     if (g == g2) {
       mapOfStudyInstanceUIDToGroup.put(studyInstanceUID, g1);
     }
   }
   groups.remove(g2);
 }
Example #4
0
  protected Group addToGroups(AttributeList list) throws DicomException {
    Group group = null;
    String studyInstanceUID =
        Attribute.getSingleStringValueOrEmptyString(list, TagFromName.StudyInstanceUID);
    String sopInstanceUID =
        Attribute.getSingleStringValueOrEmptyString(list, TagFromName.SOPInstanceUID);
    if (sopInstanceUID.length() > 0) {
      // System.err.println("addToGroups(): checking "+sopInstanceUID);
      group = mapOfSOPInstanceUIDToGroup.get(sopInstanceUID);
      // System.err.println("addToGroups(): mapOfSOPInstanceUIDToGroup.get() = "+group);
      Set<String> referencedSOPInstanceUIDs = list.findAllNestedReferencedSOPInstanceUIDs();
      if (group == null) {
        // not already there, so before creating a new group ...
        if (studyInstanceUID.length() > 0) {
          group = mapOfStudyInstanceUIDToGroup.get(studyInstanceUID);
          // System.err.println("addToGroups(): mapOfStudyInstanceUIDToGroup.get() = "+group);
          if (group == null) {
            // no group with instance in same study, so now try to put it in the same group as any
            // referenced instances
            if (referencedSOPInstanceUIDs != null) {
              for (String referencedSOPInstanceUID : referencedSOPInstanceUIDs) {
                group = mapOfSOPInstanceUIDToGroup.get(referencedSOPInstanceUID);
                // System.err.println("addToGroups(): mapOfSOPInstanceUIDToGroup.get() = "+group);
                if (group != null) {
                  System.err.println(
                      "Adding SOP Instance UID "
                          + sopInstanceUID
                          + " of StudyInstanceUID "
                          + studyInstanceUID
                          + " based on contained Referenced SOP Instance UID "
                          + referencedSOPInstanceUID
                          + " to group "
                          + group.identity);
                  break;
                }
              }
            }
          } else {
            System.err.println(
                "Adding SOP Instance UID "
                    + sopInstanceUID
                    + " based on StudyInstanceUID "
                    + studyInstanceUID
                    + " to group "
                    + group.identity);
          }
        } else {
          throw new DicomException("Missing StudyInstanceUID");
        }

        if (group
            == null) { // i.e., no references or did not find any of the references in existing
                       // groups
          // System.err.println("addToGroups(): creating new group");
          group = new Group();
          System.err.println(
              "Creating new group for SOP Instance UID "
                  + sopInstanceUID
                  + " based on StudyInstanceUID "
                  + studyInstanceUID
                  + " group "
                  + group.identity);
          groups.add(group);
        }
      }

      if (studyInstanceUID.length() > 0) {
        Group studyGroup = mapOfStudyInstanceUIDToGroup.get(studyInstanceUID);
        if (studyGroup == null) {
          System.err.println(
              "addToGroups(): mapOfStudyInstanceUIDToGroup.put(studyInstanceUID "
                  + studyInstanceUID
                  + ")");
          mapOfStudyInstanceUIDToGroup.put(studyInstanceUID, group);
        } else if (studyGroup != group) {
          System.err.println(
              "addToGroups(): mapOfStudyInstanceUIDToGroup.get(studyInstanceUID "
                  + studyInstanceUID
                  + ") != null and != current group");
          mergeGroups(group, studyGroup);
        }
      }

      group.add(sopInstanceUID);
      Group instanceGroup = mapOfSOPInstanceUIDToGroup.get(sopInstanceUID);
      if (instanceGroup == null) {
        mapOfSOPInstanceUIDToGroup.put(sopInstanceUID, group);
      } else if (instanceGroup != group) {
        System.err.println(
            "addToGroups(): mapOfSOPInstanceUIDToGroup.get(sopInstanceUID "
                + sopInstanceUID
                + ") != null and != current group");
        mergeGroups(group, instanceGroup);
      }

      if (referencedSOPInstanceUIDs != null) {
        // group.addAll(referencedSOPInstanceUIDs);
        for (String referencedSOPInstanceUID : referencedSOPInstanceUIDs) {
          group.add(referencedSOPInstanceUID);
          instanceGroup = mapOfSOPInstanceUIDToGroup.get(referencedSOPInstanceUID);
          if (instanceGroup == null) {
            mapOfSOPInstanceUIDToGroup.put(referencedSOPInstanceUID, group);
          } else if (instanceGroup != group) {
            System.err.println(
                "addToGroups(): mapOfSOPInstanceUIDToGroup.get(referencedSOPInstanceUID "
                    + referencedSOPInstanceUID
                    + ") != null and != current group");
            mergeGroups(group, instanceGroup);
          }
        }
      }
    } else {
      throw new DicomException("Missing SOPInstanceUID");
    }
    return group;
  }