<K, V> void testNavigationAgainstExpected(
     NavigableMap<K, V> expected, NavigableMap<K, V> navigableMap, Iterable<K> keysToTest) {
   for (K key : keysToTest) {
     assertEquals(expected.lowerEntry(key), navigableMap.lowerEntry(key));
     assertEquals(expected.floorEntry(key), navigableMap.floorEntry(key));
     assertEquals(expected.ceilingEntry(key), navigableMap.ceilingEntry(key));
     assertEquals(expected.higherEntry(key), navigableMap.higherEntry(key));
     for (boolean inclusive : new boolean[] {false, true}) {
       ASSERT
           .that(navigableMap.headMap(key, inclusive).entrySet())
           .has()
           .allFrom(expected.headMap(key, inclusive).entrySet())
           .inOrder();
       ASSERT
           .that(navigableMap.tailMap(key, inclusive).entrySet())
           .has()
           .allFrom(expected.tailMap(key, inclusive).entrySet())
           .inOrder();
       ASSERT
           .that(navigableMap.headMap(key, inclusive).descendingMap().entrySet())
           .has()
           .allFrom(expected.headMap(key, inclusive).descendingMap().entrySet())
           .inOrder();
       ASSERT
           .that(navigableMap.tailMap(key, inclusive).descendingMap().entrySet())
           .has()
           .allFrom(expected.tailMap(key, inclusive).descendingMap().entrySet())
           .inOrder();
     }
   }
 }
Пример #2
0
 @CollectionSize.Require(SEVERAL)
 public void testHigher() {
   resetWithHole();
   assertEquals(c, navigableMap.higherEntry(a.getKey()));
   assertEquals(c.getKey(), navigableMap.higherKey(a.getKey()));
   assertEquals(c, navigableMap.higherEntry(b.getKey()));
   assertEquals(c.getKey(), navigableMap.higherKey(b.getKey()));
   assertEquals(null, navigableMap.higherEntry(c.getKey()));
   assertEquals(null, navigableMap.higherKey(c.getKey()));
 }
Пример #3
0
 @CollectionSize.Require(ZERO)
 public void testEmptyMapNearby() {
   assertNull(navigableMap.lowerEntry(samples.e0.getKey()));
   assertNull(navigableMap.lowerKey(samples.e0.getKey()));
   assertNull(navigableMap.floorEntry(samples.e0.getKey()));
   assertNull(navigableMap.floorKey(samples.e0.getKey()));
   assertNull(navigableMap.ceilingEntry(samples.e0.getKey()));
   assertNull(navigableMap.ceilingKey(samples.e0.getKey()));
   assertNull(navigableMap.higherEntry(samples.e0.getKey()));
   assertNull(navigableMap.higherKey(samples.e0.getKey()));
 }
Пример #4
0
 @CollectionSize.Require(ONE)
 public void testSingletonMapNearby() {
   assertNull(navigableMap.lowerEntry(samples.e0.getKey()));
   assertNull(navigableMap.lowerKey(samples.e0.getKey()));
   assertEquals(a, navigableMap.floorEntry(samples.e0.getKey()));
   assertEquals(a.getKey(), navigableMap.floorKey(samples.e0.getKey()));
   assertEquals(a, navigableMap.ceilingEntry(samples.e0.getKey()));
   assertEquals(a.getKey(), navigableMap.ceilingKey(samples.e0.getKey()));
   assertNull(navigableMap.higherEntry(samples.e0.getKey()));
   assertNull(navigableMap.higherKey(samples.e0.getKey()));
 }
  /**
   * This method is going to return a Map with the End template records loaded from the external
   * BaseData xml file
   *
   * @param inputDto
   * @return
   */
  public static Map<String, NavigationPointerDto> loadEndTemplatePattern(
      LoadEndTemplatePatternInputDto inputDto) {
    Map<String, NavigationPointerDto> Navigation_BaseDataDto =
        new LinkedHashMap<String, NavigationPointerDto>();

    if (LOG.isDebugEnabled()) {
      LOG.debug(
          "UtilityNavigationPointerEnd loadEndTemplatePattern() inputDto.getMapOptionSetIdNumber() : "
              + inputDto.getMapOptionSetIdNumber());
    }

    UtilityNavigationPointerEnd.validateInputDto(inputDto);

    if (UtilityNavigationPointerEnd.validateInputDtoData(inputDto)) {
      try {
        Map<String, BaseDataDto> listBaseData =
            inputDto.getEndTemplateList().get(inputDto.getPrinterType());

        /**
         * We are going to group all the end BaseData Records on the map of navigateEndDataMap,
         * using the page xml node data as a key and as a value the list of baseData records
         */
        Map<String, Map<String, BaseDataDto>> navigateEndDataMap =
            UtilityNavigationPointerEnd.groupLastRecords(listBaseData);

        String endTemplateStartPage =
            UtilityNavigationPointerEnd.getFirstEndTemplatePageNumber(inputDto);
        int countInitOptionSetId =
            UtilityNavigationPointerEnd.getLastFirstOptionSetId(inputDto, endTemplateStartPage);
        int lastEndProdAccOptionSetId =
            inputDto.getMapOptionSetIdNumber().get(endTemplateStartPage).getOptionSetId();

        /*
                        if (LOG.isDebugEnabled()) {
                            LOG.debug("UtilityNavigationPointerEnd loadEndTemplatePattern() endTemplateStartPage : " + endTemplateStartPage);
                            LOG.debug("UtilityNavigationPointerEnd loadEndTemplatePattern() countInitOptionSetId : " + countInitOptionSetId);
                            LOG.debug("UtilityNavigationPointerEnd loadEndTemplatePattern() navigateEndDataMap.size : " + navigateEndDataMap.size());
                            LOG.debug("UtilityNavigationPointerEnd loadEndTemplatePattern() lastEndProdAccOptionSetId : " + lastEndProdAccOptionSetId);
                        }
        */
        NavigableMap<String, OptionSetIdNumber> groupEndOptionSetNumbers =
            UtilityNavigationPointerEnd.getGroupEndOptionSetNumbers(inputDto, endTemplateStartPage);

        int procOptionSetIdProcInit =
            inputDto.getMapOptionSetIdNumber().get("proc").getOptionSetId();

        while (countInitOptionSetId <= lastEndProdAccOptionSetId) {

          for (Map.Entry<String, OptionSetIdNumber> entryOptionSetId :
              groupEndOptionSetNumbers.entrySet()) {

            Map<String, String> mapOptionSetIdToUpdate = new LinkedHashMap<String, String>();
            boolean panelCreated = false;

            if (LOG.isDebugEnabled()) {
              LOG.debug(
                  "UtilityNavigationPointerEnd loadEndTemplatePattern() entryOptionSetId.getKey() : "
                      + entryOptionSetId.getKey());
              LOG.debug(
                  "UtilityNavigationPointerEnd loadEndTemplatePattern() navigateEndDataMap : "
                      + navigateEndDataMap);
            }

            for (Map.Entry<String, BaseDataDto> baseDataDto :
                navigateEndDataMap.get(entryOptionSetId.getKey()).entrySet()) {
              String nextPageValue = "";

              NavigationPointerDto navigationPointerDto = new NavigationPointerDto();
              navigationPointerDto.setDatasource("" + Rp3Constants.CODES.END_TEMPLATE_DATA_SOURCE);
              navigationPointerDto.setDataSourceRefId(baseDataDto.getKey());
              navigationPointerDto.setPage(String.valueOf(entryOptionSetId.getKey()));
              navigationPointerDto.setStreamId(inputDto.getStreamId());

              if (!"proc".equalsIgnoreCase(entryOptionSetId.getKey())) {

                Map.Entry<String, OptionSetIdNumber> nextOptionSetIdPanelEntry =
                    groupEndOptionSetNumbers.higherEntry(entryOptionSetId.getKey());
                if (nextOptionSetIdPanelEntry != null
                    && !"proc".equalsIgnoreCase(nextOptionSetIdPanelEntry.getKey())) {
                  if (nextOptionSetIdPanelEntry != null && panelCreated == false) {
                    nextOptionSetIdPanelEntry.getValue().incrementOptionSetIdByOne();
                    nextPageValue =
                        nextOptionSetIdPanelEntry.getKey()
                            + "."
                            + nextOptionSetIdPanelEntry.getValue().getOptionSetId();
                    panelCreated = true;
                  } else if (nextOptionSetIdPanelEntry == null) {
                    nextPageValue = baseDataDto.getValue().getNextPanel();
                  } else if (panelCreated) {
                    nextPageValue =
                        nextOptionSetIdPanelEntry.getKey()
                            + "."
                            + nextOptionSetIdPanelEntry.getValue().getOptionSetId();
                  }
                } else if (nextOptionSetIdPanelEntry != null
                    && "proc".equalsIgnoreCase(nextOptionSetIdPanelEntry.getKey())) {
                  // We need to increment by one each proc number
                  nextOptionSetIdPanelEntry.getValue().incrementOptionSetIdByOne();
                  nextPageValue =
                      nextOptionSetIdPanelEntry.getKey()
                          + "."
                          + nextOptionSetIdPanelEntry.getValue().getOptionSetId();
                }

                navigationPointerDto.setPageOptionSetID(String.valueOf(countInitOptionSetId));
              } else {
                String pageToCheck =
                    baseDataDto.getValue().getPage()
                        + "."
                        + baseDataDto.getValue().getPageOptionSetID();
                if (!mapOptionSetIdToUpdate.containsKey(pageToCheck)) {
                  mapOptionSetIdToUpdate.put(
                      pageToCheck, String.valueOf(++procOptionSetIdProcInit));
                }

                navigationPointerDto.setPageOptionSetID(mapOptionSetIdToUpdate.get(pageToCheck));
                nextPageValue = baseDataDto.getValue().getNextPanel();
              }

              navigationPointerDto.setNextPage(nextPageValue);
              navigationPointerDto.setPrinterType(inputDto.getPrinterType());

              navigationPointerDto.inputType = baseDataDto.getValue().getHtmlInputType();
              navigationPointerDto.webFriendlyName = baseDataDto.getValue().getLabel();
              Navigation_BaseDataDto.put(UtilityRefIdGenerator.buildRefId(), navigationPointerDto);
            }
          }
          countInitOptionSetId++;
        }
      } catch (RuntimeException re) {
        LOG.error("Error UtilityTemplateEndPattern getEndTemplateMap() " + re.getMessage(), re);
        StatusMessage statusMessage =
            new StatusMessage(
                Rp3Constants.CODES_MSG.STATUS_MSG_LEVEL_METHOD.toString(),
                MsgConstants.UNPE.STATUS_MSG_ERROR.toString(),
                Arrays.asList(re.getMessage()),
                Integer.valueOf(Rp3Constants.CODES_MSG.STATUS_MSG_LEVEL_EXCEPTION.toString()));
        inputDto.getStatusMessagingList().add(statusMessage);
      }
    }

    return Navigation_BaseDataDto;
  }
Пример #6
0
    public AnnotationDTO getClosestOverlappingOfSameType(AnnotationDTO target) {
      Map<String, NavigableMap<Integer, AnnotationDTO>> typeIdx = indexMap.get(target.getDocUri());
      if (typeIdx == null) {
        return null;
      }
      NavigableMap<Integer, AnnotationDTO> positionIdx = typeIdx.get(target.getType());
      if (positionIdx == null) {
        return null;
      }
      AnnotationDTO leftClosest = null;
      Entry<Integer, AnnotationDTO> leftClosestEntry =
          positionIdx.floorEntry(target.getStartOffset());
      if (leftClosestEntry != null) {
        leftClosest = leftClosestEntry.getValue();
        if (leftClosest.getStartOffset() == target.getStartOffset()) {
          // exact match
          return leftClosest;
        }
        if (leftClosest.getEndOffset() <= target.getStartOffset()) {
          // does not overlap
          leftClosest = null;
        }
      }
      AnnotationDTO rightClosest = null;
      Entry<Integer, AnnotationDTO> rightClosestEntry =
          positionIdx.higherEntry(target.getStartOffset());
      if (rightClosestEntry != null) {
        rightClosest = rightClosestEntry.getValue();
        if (rightClosest.getStartOffset() >= target.getEndOffset()) {
          // does not overlap
          rightClosest = null;
        }
      }
      if (leftClosest != null) {
        if (rightClosest != null) {
          int targetLength = getLength(target);
          // return one with longer overlap
          int leftOverlap = leftClosest.getEndOffset() - target.getStartOffset();
          if (leftOverlap < 0) {
            throw new IllegalStateException("Assertion failed");
          }
          leftOverlap = min(leftOverlap, targetLength);

          int rightOverlap =
              min(rightClosest.getEndOffset(), target.getEndOffset())
                  - rightClosest.getStartOffset();
          if (leftOverlap > rightOverlap) {
            return leftClosest;
          } else if (rightOverlap > leftOverlap) {
            return rightClosest;
          } else {
            // equal overlap! return the longest
            int leftLength = getLength(leftClosest);
            int rightLength = getLength(rightClosest);
            if (leftLength > rightLength) {
              return leftClosest;
            } else {
              return rightClosest;
            }
          }
        } else {
          // right is null
          return leftClosest;
        }
      } else {
        // left is null
        if (rightClosest != null) {
          return rightClosest;
        } else {
          return null;
        }
      }
    }