Compute and return the destination text (all equalities and insertions).

@param diffs
LinkedList of Diff objects.
@return Destination text.
439688
public String diff_text2(LinkedList<Diff> diffs) {
        StringBuilder text = new StringBuilder();
        for (Diff aDiff : diffs) {
            if (aDiff.operation != Operation.DELETE) {
                text.append(aDiff.text);
            }
        }
        return text.toString();
    }
415128
public List<InlineDiffChunk<Character>> inline(String previous, String next)
    {
        setError(null);

        try {
            return this.inlineDiffDisplayer
                .display(this.diffManager.diff(this.charSplitter.split(previous), this.charSplitter.split(next), null));
        } catch (DiffException e) {
            setError(e);
            return null;
        }
    }
939988
public List<JsonDelta> computeDiff(JsonNode node1, JsonNode node2) {
        List<JsonDelta> list = new ArrayList<>();
        computeDiff(list, new ArrayList<String>(), node1, node2);
        return list;
    }
86535
protected String getTextLineNumber(int rowStartOffset) {
    Element root = component.getDocument().getDefaultRootElement();
    int index = root.getElementIndex(rowStartOffset);
    Element line = root.getElement(index);

    if (line.getStartOffset() == rowStartOffset)
      return String.valueOf(index + 1);
    else
      return "";
  }
35695
private String[] getEquivalents(String segment) {
        Set<String> result = new HashSet<String>();
        Set<String> basic = getEquivalents2(segment);
        Set<String> permutations = new HashSet<String>();

        // now get all the permutations
        // add only the ones that are canonically equivalent
        // TODO: optimize by not permuting any class zero.
        Iterator<String> it = basic.iterator();
        while (it.hasNext()) {
            String item = it.next();
            permutations.clear();
            permute(item, SKIP_ZEROS, permutations);
            Iterator<String> it2 = permutations.iterator();
            while (it2.hasNext()) {
                String possible = it2.next();

/*
                String attempt = Normalizer.normalize(possible, Normalizer.DECOMP, 0);
                if (attempt.equals(segment)) {
*/
                if (Normalizer.compare(possible, segment,0)==0) {

                    if (PROGRESS) System.out.println("Adding Permutation: " + Utility.hex(possible));
                    result.add(possible);

                } else {
                    if (PROGRESS) System.out.println("-Skipping Permutation: " + Utility.hex(possible));
                }
            }
        }

        // convert into a String[] to clean up storage
        String[] finalResult = new String[result.size()];
        result.toArray(finalResult);
        return finalResult;
    }
1332093
public String getDestinationName(Destination destination) {
        try {
            if (destination instanceof Queue) {
                return ((Queue) destination).getQueueName();
            } else if (destination instanceof Topic) {
                return ((Topic) destination).getTopicName();
            } else {
                return destination.toString();
            }
        } catch (JMSException e) {
            log.error("Unable to resolve destination name", e);
            return "";
        }
    }
623698
public String diff_prettyHtml(LinkedList<Diff> diffs) {
        StringBuilder html = new StringBuilder();
        for (Diff aDiff : diffs) {
            String text = aDiff.text.replace("&", "&amp;").replace("<", "&lt;")
                    .replace(">", "&gt;").replace("\n", "&para;<br>");
            switch (aDiff.operation) {
            case INSERT:
                html.append("<ins style=\"background:#e6ffe6;\">").append(text)
                        .append("</ins>");
                break;
            case DELETE:
                html.append("<del style=\"background:#ffe6e6;\">").append(text)
                        .append("</del>");
                break;
            case EQUAL:
                html.append("<span>").append(text).append("</span>");
                break;
            }
        }
        return html.toString();
    }
567085
protected String applyTextReplacements(Iterable<ITextReplacement> replacements) {
		ITextSegment region = getRegion();
		String input = region.getText();
		ArrayList<ITextReplacement> list = Lists.newArrayList(replacements);
		Collections.sort(list);
		int startOffset = region.getOffset();
		int lastOffset = 0;
		StringBuilder result = new StringBuilder();
		for (ITextReplacement r : list) {
			int offset = r.getOffset() - startOffset;
			result.append(input.subSequence(lastOffset, offset));
			result.append(r.getReplacementText());
			lastOffset = offset + r.getLength();
		}
		result.append(input.subSequence(lastOffset, input.length()));
		return result.toString();
	}
1342251
private LinkedList<Change> compute(String text1, String text2, boolean checkLines) {
        LinkedList<Change> diffs = new LinkedList<>();

        if (text1.length() == 0) {
            // Just add some text (speedup).
            diffs.add(new Change(Operation.INSERT, text2));
            return diffs;
        }

        if (text2.length() == 0) {
            // Just delete some text (speedup).
            diffs.add(new Change(Operation.DELETE, text1));
            return diffs;
        }

        String longtext = text1.length() > text2.length() ? text1 : text2;
        String shorttext = text1.length() > text2.length() ? text2 : text1;
        int i = longtext.indexOf(shorttext);
        if (i != -1) {
            // Shorter text is inside the longer text (speedup).
            Operation op = (text1.length() > text2.length()) ?
                           Operation.DELETE : Operation.INSERT;
            diffs.add(new Change(op, longtext.substring(0, i)));
            diffs.add(new Change(Operation.EQUAL, shorttext));
            diffs.add(new Change(op, longtext.substring(i + shorttext.length())));
            return diffs;
        }

        if (shorttext.length() == 1) {
            // Single character string.
            // After the previous speedup, the character can't be an equality.
            diffs.add(new Change(Operation.DELETE, text1));
            diffs.add(new Change(Operation.INSERT, text2));
            return diffs;
        }

        // Check to see if the problem can be split in two.
        String[] hm = halfMatch(text1, text2);
        if (hm != null) {
            // A half-match was found, sort out the return data.
            String text1_a = hm[0];
            String text1_b = hm[1];
            String text2_a = hm[2];
            String text2_b = hm[3];
            String mid_common = hm[4];
            // Send both pairs off for separate processing.
            LinkedList<Change> diffs_a = main(text1_a, text2_a, checkLines);
            LinkedList<Change> diffs_b = main(text1_b, text2_b, checkLines);
            // Merge the results.
            diffs = diffs_a;
            diffs.add(new Change(Operation.EQUAL, mid_common));
            diffs.addAll(diffs_b);
            return diffs;
        }

        if (checkLines && text1.length() > 100 && text2.length() > 100) {
            return lineMode(text1, text2);
        }

        return bisect(text1, text2);
    }
436869
@Override
	public Destination getDestination(PeerDescriptor peer, DestinationReferenceDescriptor destinationReference,Session session) throws JMSException
	{
		String destinationType = destinationReference.getDestinationType();
		String destinationName = destinationReference.getDestinationName();
		
		if (destinationType.equalsIgnoreCase("queue"))
		{
			return session.createQueue(destinationName);
		}
		else
		if (destinationType.equalsIgnoreCase("topic"))
		{
			return session.createTopic(destinationName);
		}
		else
			throw new IllegalArgumentException("Invalid destination type : "+destinationType);
	}
1345713
def diff_texts(left, right, diff_options=None, formatter=None):
    """"""
    return _diff(etree.fromstring, left, right,
                 diff_options=diff_options, formatter=formatter)
111591
@NonNull
    Completable overwriteUsingDiffUtil(@NonNull final List<? extends T> newContents,
                                         @NonNull final EqualityFunction<? super T> identityEqualityFunction,
                                         @NonNull final EqualityFunction<? super T> contentEqualityFunction) {
        return copyContents().switchMap(new Function<List<? extends T>, Observable<?>>() {
            @Override
            public Observable<Object> apply(List<? extends T> existingContentsCopy) throws Exception {
                return calculateDiff(existingContentsCopy, newContents, identityEqualityFunction, contentEqualityFunction)
                        .switchMap(new Function<DiffUtil.DiffResult, Observable<Object>>() {
                            @Override
                            public Observable<Object> apply(DiffUtil.DiffResult diffResult) throws Exception {
                                return applyNewContentsAndDispatchDiffNotifications(newContents, diffResult).toObservable();
                            }
                        });
            }
        }).ignoreElements();
    }
59399
def diff_levenshtein(self, diffs):
    
    levenshtein = 0
    insertions = 0
    deletions = 0
    for (op, data) in diffs:
      if op == self.DIFF_INSERT:
        insertions += len(data)
      elif op == self.DIFF_DELETE:
        deletions += len(data)
      elif op == self.DIFF_EQUAL:
        # A deletion and an insertion is one substitution.
        levenshtein += max(insertions, deletions)
        insertions = 0
        deletions = 0
    levenshtein += max(insertions, deletions)
    return levenshtein
1163063
public static RawTextNode concat(List<RawTextNode> nodes) {
    checkArgument(!nodes.isEmpty());
    if (nodes.size() == 1) {
      return nodes.get(0);
    }
    int id = nodes.get(0).getId();
    int numChars = 0;
    int numOffsets = 0;
    for (RawTextNode node : nodes) {
      numChars += node.getRawText().length();
      // if any of the offsets are null don't try to merge offsets
      // offsets are most often null when SourceLocation.UNKNOWN is in use
      if (numOffsets != -1 && node.offsets != null) {
        // since the last index in the array refers to a pseudo end location, we drop it when
        // joining the arrays
        // we don't preserve offsets from empty nodes.
        numOffsets += node.isEmpty() ? 0 : node.offsets.indexes.length - 1;
      } else {
        numOffsets = -1;
      }
    }
    char[] chars = new char[numChars];
    int charsIndex = 0;

    int[] indexes = null;
    int[] lines = null;
    int[] columns = null;
    Reason[] reasons = null;
    // the current index into the offsets arrays
    int offsetsIndex = 0;
    // the length of the string so far

    if (numOffsets > 0) {
      // +1 because we want to preserve the end location of the last node.
      indexes = new int[numOffsets + 1];
      lines = new int[numOffsets + 1];
      columns = new int[numOffsets + 1];
      reasons = new Reason[numOffsets + 1];
    }

    for (int i = 0; i < nodes.size(); i++) {
      RawTextNode node = nodes.get(i);
      String text = node.getRawText();
      text.getChars(0, text.length(), chars, charsIndex);
      if (indexes != null && !text.isEmpty()) {
        // To concatenate we need to approximately just cat the arrays
        // since the last slot in the array corresponds to a pseudo location (the end of the string)
        // we should drop it when splicing.
        // we also need to modify all the indexes in other to be offset by the length of this
        // offset's string.
        SourceOffsets offsets = node.offsets;
        int amountToCopy = offsets.indexes.length;
        if (i < nodes.size() - 1) {
          amountToCopy--;
        }
        System.arraycopy(offsets.lines, 0, lines, offsetsIndex, amountToCopy);
        System.arraycopy(offsets.columns, 0, columns, offsetsIndex, amountToCopy);
        System.arraycopy(offsets.reasons, 0, reasons, offsetsIndex, amountToCopy);

        // do some special handling for the 'reason' of the join point.
        // If the new begin reason is NONE, then use the old end reason.
        if (offsets.reasons[0] == Reason.NONE && i > 0) {
          Reason[] prevReasons = nodes.get(i - 1).offsets.reasons;
          reasons[offsetsIndex] = prevReasons[prevReasons.length - 1];
        }
        // manually copy the indexes over so we can apply the current character index
        for (int indexIndex = 0; indexIndex < amountToCopy; indexIndex++) {
          indexes[indexIndex + offsetsIndex] = offsets.indexes[indexIndex] + charsIndex;
        }
        offsetsIndex += amountToCopy;
      }
      charsIndex += text.length();
    }
    String text = new String(chars);
    SourceLocation location =
        nodes.get(0).getSourceLocation().extend(Iterables.getLast(nodes).getSourceLocation());
    return new RawTextNode(
        id,
        text,
        location,
        indexes == null ? null : new SourceOffsets(indexes, lines, columns, reasons));
  }
240798
@Override
  public B writeTo(Destination destination) {
    super.writeTo(destination);
    fromState(destination.getProperties());
    return typedSelf();
  }
822156
def diff_text2(self, diffs):
    
    text = []
    for (op, data) in diffs:
      if op != self.DIFF_DELETE:
        text.append(data)
    return "".join(text)
864976
public List<Destination> getDestinations() {
        List<Destination> destinations = new ArrayList<Destination>();
        Iterator<JMSDestination> destinationIterator =
            jmsDestinations.values().iterator();
        while(destinationIterator.hasNext()) {
            destinations.add(destinationIterator.next().destination);
        }
        return destinations;
    }