public final class TextFragmentUtil extends Object
| Modifier and Type | Field and Description |
|---|---|
static CodeComparatorOnData |
CMP_DATA |
static CodeComparatorOnId |
CMP_ID |
static CodeComparatorOnTagType |
CMP_TAG_TYPE |
static int |
MAX_INLINE_CODES |
| Constructor and Description |
|---|
TextFragmentUtil() |
| Modifier and Type | Method and Description |
|---|---|
static void |
addMissingCodes(TextFragment from,
TextFragment to,
CodeMatches codeMatches)
Add missing leading and trailing codes on target (aka 'to').
|
static CodeMatches |
alignAndCopyCodeMetadata(TextFragment from,
TextFragment to)
Update the meta fields in
Code "to" that match those of
"from" But only if the "to" code has empty data. |
static CodeMatches |
alignAndCopyCodeMetadata(TextFragment from,
TextFragment to,
boolean addMissingCodes)
Update the meta fields in
Code "to" that match those of
"from" But only if the "to" code has empty data (@see{forceCopy}). |
static CodeMatches |
alignAndCopyCodeMetadata(TextFragment from,
TextFragment to,
boolean addMissingCodes,
boolean forceCopy)
Update the meta fields in
Code "to" that match those of
"from" But only if the "to" code has empty data (@see{forceCopy}). |
static void |
copyCodeMetadata(Code sc,
Code tc,
boolean forceCopy) |
static void |
copyCodeMetadata(TextFragment sf,
TextFragment tf,
boolean forceCopy,
CodeMatches cm) |
static int |
findMatch(Code orig,
List<Code> codes,
int[] fromMatches,
Comparator<Code>... cmps)
Find a match in codes based on the list of
Comparator |
static boolean |
isLeadingCode(Code code,
TextFragment source)
Determine if the code is at the beginning of the
TextFragment without
intervening text. |
static void |
logCodeMismatchErrors(CodeMatches matches,
TextFragment from,
TextFragment to,
String textUnitId)
Log all code mismatch issues
|
static boolean |
moreThanMaxCodes(TextFragment tf) |
static TextFragment |
removeMoreThanMaxCodes(TextFragment tf) |
static CodeMatches |
synchronizeCodeIds(TextFragment from,
TextFragment to)
Matches the code IDs of the
from |
static String |
toText(TextFragment tf)
Render the
TextFragment including all Codes. |
public static final int MAX_INLINE_CODES
public static final CodeComparatorOnData CMP_DATA
public static final CodeComparatorOnId CMP_ID
public static final CodeComparatorOnTagType CMP_TAG_TYPE
public static CodeMatches alignAndCopyCodeMetadata(TextFragment from, TextFragment to, boolean addMissingCodes, boolean forceCopy)
Code "to" that match those of
"from" But only if the "to" code has empty data (@see{forceCopy}).
Otherwise keep the to code data as-is. Codes match if both Code.data
and Code.tagType are the same.from - TextFragment codes are used to match codes in
"to"to - TextFragment that has its code id's updated to
matchaddMissingCodes - indicates if codes that are in the original source but
not in the new target should be automatically added at
the end of the new target copy (even if they are
removable) if there are references in the original
source and/or empty codes in the new target.forceCopy - if true always overwrite the target code data.
WARNING: This will overwrite any code data changes
in the target and force them to be like the source
This may be needed for some simplified formats that
only display the tagType and id. For example: A
letter-coded format like:
"<g1>text<x2/></g1><b3/>".public static void logCodeMismatchErrors(CodeMatches matches, TextFragment from, TextFragment to, String textUnitId)
matches - holds matchesfrom - base or original fragment (aka source)to - new fragment (aka target)public static CodeMatches alignAndCopyCodeMetadata(TextFragment from, TextFragment to)
Code "to" that match those of
"from" But only if the "to" code has empty data. Otherwise keep the
to code data as-is. Codes match if both Code.data and
Code.tagType are the same.from - TextFragment codes are used to match codes in "to"to - TextFragment that has its code id's updated to matchpublic static CodeMatches alignAndCopyCodeMetadata(TextFragment from, TextFragment to, boolean addMissingCodes)
Code "to" that match those of
"from" But only if the "to" code has empty data (@see{forceCopy}).
Otherwise keep the to code data as-is. Codes match if both Code.data
and Code.tagType are the same.from - TextFragment codes are used to match codes in
"to"to - TextFragment that has its code id's updated to
matchaddMissingCodes - indicates if codes that are in the original source but
not in the new target should be automatically added at
the end of the new target copy (even if they are
removable) if there are references in the original
source and/or empty codes in the new target.public static void addMissingCodes(TextFragment from, TextFragment to, CodeMatches codeMatches)
from - object which has the missing codesto - object where we need to add the missing codescodeMatches - CodeMatches shows us what is missingpublic static boolean isLeadingCode(Code code, TextFragment source)
TextFragment without
intervening text.code - the code we are testing.source - the source (aka 'from') fragment we are searching.@SafeVarargs public static int findMatch(Code orig, List<Code> codes, int[] fromMatches, Comparator<Code>... cmps)
Comparatororig - the code we are looking forcodes - the code list we are looking infromMatches - boolean arrays marking the fromMatches already foundcmps - the list of Comparatorpublic static void copyCodeMetadata(TextFragment sf, TextFragment tf, boolean forceCopy, CodeMatches cm)
public static CodeMatches synchronizeCodeIds(TextFragment from, TextFragment to)
from fragment with the ones of the to fragment.
This method re-assigns the IDs of the in-line codes of this fragment based on the
code data of the provided fragment. If there is a code with the same data, then
prefer the first code as this is the matching target code in the majority of cases.
An example of usage is when source and target fragments have codes generated
from regular expressions and not in the same order.
For example if the source is %d equals %s and the target is
%s equals %d and %s and %d are codes.
You want their IDs to match for the code with the same content.from - the fragment to use as the base for the synchronization.to - the fragment who's id's will be adjusted.public static boolean moreThanMaxCodes(TextFragment tf)
public static TextFragment removeMoreThanMaxCodes(TextFragment tf)
public static String toText(TextFragment tf)
TextFragment including all Codes. differs from
TextFragment.toText() by also using outerData.tf - The TextFragment to renderCopyright © 2021. All rights reserved.