Checks that replacementSegments provided are consistent with the segments that are currently being used.
@param replacedSegment The segment on which EOS was reached
@param replacementSegments The StreamSegmentsWithPredecessors to verify
428483
private void verifyReplacementRange(SegmentWithRange replacedSegment, StreamSegmentsWithPredecessors replacementSegments) {
        log.debug("Verification of replacement segments {} with the current segments {}", replacementSegments, segments);
        Map<Long, List<SegmentWithRange>> replacementRanges = replacementSegments.getReplacementRanges();
        List<SegmentWithRange> replacements = replacementRanges.get(replacedSegment.getSegment().getSegmentId());
        Preconditions.checkArgument(replacements != null, "Replacement segments did not contain replacements for segment being replaced");
        if (replacementRanges.size() == 1) {
            //Simple split
            Preconditions.checkArgument(replacedSegment.getHigh() == getUpperBound(replacements));
            Preconditions.checkArgument(replacedSegment.getLow() == getLowerBound(replacements));
        } else {
            Preconditions.checkArgument(replacedSegment.getHigh() <= getUpperBound(replacements));
            Preconditions.checkArgument(replacedSegment.getLow() >= getLowerBound(replacements));
        }
        for (Entry<Long, List<SegmentWithRange>> ranges : replacementRanges.entrySet()) {
            Entry<Double, SegmentWithRange> upperReplacedSegment = segments.floorEntry(getUpperBound(ranges.getValue()));
            Entry<Double, SegmentWithRange> lowerReplacedSegment = segments.higherEntry(getLowerBound(ranges.getValue()));
            Preconditions.checkArgument(upperReplacedSegment != null, "Missing replaced replacement segments %s",
                                        replacementSegments);
            Preconditions.checkArgument(lowerReplacedSegment != null, "Missing replaced replacement segments %s",
                                        replacementSegments);
        }
    }
550283
private void evaluateSubtreeReplacement() {

        if (this.hypothesis.size() == 1) {
            // skip replacement if only one node is discovered
            return;
        }

        final Set<ReplacementResult<ADTState<I, O>, I, O>> potentialReplacements =
                this.subtreeReplacer.computeReplacements(this.hypothesis, this.alphabet, this.adt);
        final List<ReplacementResult<ADTState<I, O>, I, O>> validReplacements =
                new ArrayList<>(potentialReplacements.size());
        final Set<ADTNode<ADTState<I, O>, I, O>> cachedLeaves =
                potentialReplacements.isEmpty() ? Collections.emptySet() : ADTUtil.collectLeaves(this.adt.getRoot());

        for (final ReplacementResult<ADTState<I, O>, I, O> potentialReplacement : potentialReplacements) {
            final ADTNode<ADTState<I, O>, I, O> proposedReplacement = potentialReplacement.getReplacement();
            final ADTNode<ADTState<I, O>, I, O> nodeToReplace = potentialReplacement.getNodeToReplace();

            assert this.validateADS(nodeToReplace, proposedReplacement, potentialReplacement.getCutoutNodes());

            final ADTNode<ADTState<I, O>, I, O> replacement = this.verifyADS(nodeToReplace,
                                                                             proposedReplacement,
                                                                             cachedLeaves,
                                                                             potentialReplacement.getCutoutNodes());

            // verification may have introduced reset nodes
            final int oldCosts = ADTUtil.computeEffectiveResets(nodeToReplace);
            final int newCosts = ADTUtil.computeEffectiveResets(replacement);

            if (newCosts >= oldCosts) {
                continue;
            }

            validReplacements.add(new ReplacementResult<>(nodeToReplace, replacement));
        }

        for (final ReplacementResult<ADTState<I, O>, I, O> potentialReplacement : validReplacements) {
            final ADTNode<ADTState<I, O>, I, O> replacement = potentialReplacement.getReplacement();
            final ADTNode<ADTState<I, O>, I, O> nodeToReplace = potentialReplacement.getNodeToReplace();

            this.adt.replaceNode(nodeToReplace, replacement);

            this.resiftAffectedTransitions(ADTUtil.collectLeaves(replacement), ADTUtil.getStartOfADS(replacement));
        }

        this.closeTransitions();
    }
1024654
public void setSegmentFactory(SegmentFactory segmentFactory) {
        if(segmentFactory == null) {
            throw new IllegalArgumentException("Invalid segmentFactory: " + segmentFactory);
        }
        
        this._segmentFactory = segmentFactory;
        this._properties.setProperty(PARAM_SEGMENT_FACTORY_CLASS, segmentFactory.getClass().getName());
    }
1073111
void acceptAsSourceSegment(MergeSegmentOperation operation) {
        Exceptions.checkArgument(this.id == operation.getSourceSegmentId(),
                "operation", "Invalid Operation Source Segment Id.");

        this.sealed = true;
        this.merged = true;
        this.isChanged = true;
    }
1027521
@Override
  public boolean validateSegmentBoundary(Object o) throws IOException {
    if (o instanceof Long) {
      return validateWithSegmentBoundary((Long) o);
    } else {
      throw new IOException("incorrect type ");
    }
  }
792399
@Override
  public boolean validateSegmentBoundary(Object o) throws IOException {
    if (o instanceof Double) {
      return validateWithSegmentBoundary((Double) o);
    } else {
      throw new IOException("incorrect type");
    }
  }
600556
protected void setLayoutToEndSegment(int segmentLength,
                                        int priority,
                                        boolean isPooled,
                                        boolean isExchange,
                                        int packetNumber,
                                        int conversationId,
                                        int requestNumber,
                                        Conversation conversation,
                                        SendListener sendListener)
   {
      if (tc.isEntryEnabled()) SibTr.entry(this, tc, "setLayoutToSegmentEnd", new Object[]{""+segmentLength, ""+priority, ""+isPooled, ""+isExchange, ""+packetNumber, ""+conversationId, ""+requestNumber, conversation, sendListener});
      setLayoutToConversation(segmentLength, priority, isPooled, isExchange, packetNumber, JFapChannelConstants.SEGMENT_SEGMENTED_FLOW_END, conversationId, requestNumber, conversation, sendListener);
      layout = JFapChannelConstants.XMIT_SEGMENT_END;
      transmissionRemaining = segmentLength;
   }
1368515
function(segments) {
        var previousSegment = [-1, -1];
        var segmentIndicesToRemove = [];
        var cleanedSegmentArray = [];
        var i, ii;
        for (i = 0, ii = segments.length; i < ii; ++i) {
            if (!(previousSegment[0] <= segments[i][0] &&
                    previousSegment[1] >= segments[i][1])) {
                cleanedSegmentArray.push(segments[i]);
            }
            previousSegment = segments[i];
        }

        segments.length = 0;
        for (i = 0, ii = cleanedSegmentArray.length; i < ii; ++i) {
            segments.push(cleanedSegmentArray[i]);
        }
    }
309354
protected void fireSegmentRemoved(RoadSegment segment) {
		if (this.listeners != null && isEventFirable()) {
			for (final RoadNetworkListener listener : this.listeners) {
				listener.onRoadSegmentRemoved(this, segment);
			}
		}
	}
546724
private synchronized void resetCurrentSegment() {
    JournalSegment<E> lastSegment = getLastSegment();
    if (lastSegment != null) {
      currentSegment = lastSegment;
    } else {
      JournalSegmentDescriptor descriptor = JournalSegmentDescriptor.builder()
          .withId(1)
          .withIndex(1)
          .withMaxSegmentSize(maxSegmentSize)
          .withMaxEntries(maxEntriesPerSegment)
          .build();

      currentSegment = createSegment(descriptor);

      segments.put(1L, currentSegment);
    }
  }
863348
public static void decodePathSegment(List<PathSegment> segments, String segment, boolean decode) {
        int colon = segment.indexOf(';');
        if (colon != -1) {
            segments.add(new PathSegmentImpl(
                    (colon == 0) ? "" : segment.substring(0, colon),
                    decode,
                    decodeMatrix(segment, decode)));
        } else {
            segments.add(new PathSegmentImpl(
                    segment,
                    decode));
        }
    }
1097840
protected void fireSegmentChanged(RoadSegment segment) {
		if (this.listeners != null && isEventFirable()) {
			for (final RoadNetworkListener listener : this.listeners) {
				listener.onRoadSegmentChanged(this, segment);
			}
		}
	}
476170
private void handleSuspectSegmentsBeforeStream(Object requestId, SegmentListener listener, IntSet segments) {
      LocalizedCacheTopology topology = dm.getCacheTopology();
      if (trace) {
         log.tracef("Topology for supplier is %s for id %s", topology, requestId);
      }
      ConsistentHash readCH = topology.getCurrentCH();
      ConsistentHash pendingCH = topology.getPendingCH();
      if (pendingCH != null) {
         IntSet lostSegments = IntSets.mutableEmptySet(topology.getCurrentCH().getNumSegments());
         PrimitiveIterator.OfInt iterator = segments.iterator();
         while (iterator.hasNext()) {
            int segment = iterator.nextInt();
            // If the segment is not owned by both CHs we can't use it during rehash
            if (!pendingCH.isSegmentLocalToNode(localAddress, segment)
                  || !readCH.isSegmentLocalToNode(localAddress, segment)) {
               iterator.remove();
               lostSegments.set(segment);
            }
         }
         if (!lostSegments.isEmpty()) {
            if (trace) {
               log.tracef("Lost segments %s during rehash for id %s", lostSegments, requestId);
            }
            listener.lostSegments(lostSegments);
         } else if (trace) {
            log.tracef("Currently in the middle of a rehash for id %s", requestId);
         }
      } else {
         IntSet ourSegments = topology.getLocalReadSegments();
         if (segments.retainAll(ourSegments)) {
            if (trace) {
               log.tracef("We found to be missing some segments requested for id %s", requestId);
            }
            listener.localSegments(ourSegments);
         } else if (trace) {
            log.tracef("Hash %s for id %s", readCH, requestId);
         }
      }
   }
79806
private void requestSegments(IntSet segments, Map<Address, IntSet> sources, Set<Address> excludedSources) {
      if (sources.isEmpty()) {
         findSources(segments, sources, excludedSources);
      }

      for (Map.Entry<Address, IntSet> e : sources.entrySet()) {
         addTransfer(e.getKey(), e.getValue());
      }
   }
689737
public void parseReplacedMethodSubElements(Element beanEle, MethodOverrides overrides) {
    NodeList nl = beanEle.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++) {
      Node node = nl.item(i);
      if (node instanceof Element && nodeNameEquals(node, REPLACED_METHOD_ELEMENT)) {
        Element replacedMethodEle = (Element) node;
        String name = replacedMethodEle.getAttribute(NAME_ATTRIBUTE);
        String callback = replacedMethodEle.getAttribute(REPLACER_ATTRIBUTE);
        ReplaceOverride replaceOverride = new ReplaceOverride(name, callback);
        // Look for arg-type match elements.
        List<Element> argTypeEles = DomUtils.getChildElementsByTagName(replacedMethodEle, ARG_TYPE_ELEMENT);
        for (Element argTypeEle : argTypeEles) {
          replaceOverride.addTypeIdentifier(argTypeEle.getAttribute(ARG_TYPE_MATCH_ATTRIBUTE));
        }
        replaceOverride.setSource(extractSource(replacedMethodEle));
        overrides.addOverride(replaceOverride);
      }
    }
  }
540590
function(segment) {

            var previousSegment = segment.previousSegment; // may be null
            while (segment && !segment.isSubpathStart) {

                // assign previous segment's subpath start segment to this segment
                if (previousSegment) segment.subpathStartSegment = previousSegment.subpathStartSegment; // may be null
                else segment.subpathStartSegment = null; // if segment had no previous segment, assign null - creates an invalid path!

                previousSegment = segment;
                segment = segment.nextSegment; // move on to the segment after etc.
            }
        }
1254429
public void replaceChars(int startPosition, int endPosition, String replacement) {
    try {
      sourceBuilder.replace(startPosition, endPosition, replacement);
    } catch (StringIndexOutOfBoundsException e) {
      throw new IndexOutOfBoundsException(
          String.format(
              "Replacement cannot be made. Source file %s has length %d, requested start "
                  + "position %d, requested end position %d, replacement %s",
              path, sourceBuilder.length(), startPosition, endPosition, replacement));
    }
  }