private int[] calculateMaxFieldLengths() { return Lookup.calculateMaxFieldLengths(fieldLengths, lookaheadFormats, lookbehindFormats); }
/** * Defines the format of records identified by a lookahead symbol. * * @param lookahead the lookahead value that when found in the output row, * will notify the writer to switch to a new record format, with different field lengths * @param lengths the field lengths of the record format identified by the given lookahead symbol. */ public void addFormatForLookahead(String lookahead, FixedWidthFields lengths) { Lookup.registerLookahead(lookahead, lengths, lookaheadFormats); }
/** * Defines the format of records identified by a lookbehind symbol. * * @param lookbehind the lookbehind value that when found in the previous input row, * will notify the parser to switch to a new record format, with different field lengths * @param lengths the field lengths of the record format identified by the given lookbehind symbol. */ public void addFormatForLookbehind(String lookbehind, FixedWidthFields lengths) { Lookup.registerLookbehind(lookbehind, lengths, lookbehindFormats); }
Lookup[] getLookaheadFormats() { return Lookup.getLookupFormats(lookaheadFormats, getFormat()); }
static void registerLookahead(String lookup, FixedWidthFields lengths, Map<String, FixedWidthFields> map) { registerLookup("ahead", lookup, lengths, map); }
lookupChars = new char[Lookup.calculateMaxLookupLength(lookaheadFormats, lookbehindFormats)]; rootLengths = fieldLengths; rootAlignments = fieldAlignments;
static Lookup[] getLookupFormats(Map<String, FixedWidthFields> map, FixedWidthFormat format) { if (map.isEmpty()) { return null; } Lookup[] out = new Lookup[map.size()]; int i = 0; for (Entry<String, FixedWidthFields> e : map.entrySet()) { out[i++] = new Lookup(e.getKey(), e.getValue(), format); } Arrays.sort(out, new Comparator<Lookup>() { @Override public int compare(Lookup o1, Lookup o2) { //longer values go first. return o1.value.length < o2.value.length ? 1 : o1.value.length == o2.value.length ? 0 : -1; } }); return out; }
public Record toRecord(String[] row){ if(lookupFormat != null){ if(lookupFormat.context == null){ lookupFormat.initializeLookupContext(context, lookupFormat.fieldNames); } return lookupFormat.context.toRecord(row); } else { return super.toRecord(row); } } };
if (lookaheadFormats != null) { for (int i = 0; i < lookaheadFormats.length; i++) { if (lookaheadFormats[i].matches(lookupChars)) { fieldLengths = lookaheadFormats[i].lengths; fieldAlignments = lookaheadFormats[i].alignments; lookbehindFormat = null; for (int i = 0; i < lookbehindFormats.length; i++) { if (lookbehindFormats[i].matches(lookupChars)) { lookbehindFormat = lookbehindFormats[i]; break; if (lookbehindFormats[i].matches(lookupChars)) { lookbehindFormat = lookbehindFormats[i]; matched = true;
Lookup[] getLookbehindFormats() { return Lookup.getLookupFormats(lookbehindFormats, getFormat()); }
static void registerLookbehind(String lookup, FixedWidthFields lengths, Map<String, FixedWidthFields> map) { registerLookup("behind", lookup, lengths, map); }
rootIgnore = ignore; rootKeepPaddingFlags = keepPaddingFlags; maxLookupLength = Lookup.calculateMaxLookupLength(lookaheadFormats, lookbehindFormats);
Lookup[] getLookbehindFormats() { return Lookup.getLookupFormats(lookbehindFormats, getFormat()); }
@Override public int getMaxColumns() { int max = super.getMaxColumns(); int minimum = Lookup.calculateMaxFieldLengths(fieldLengths, lookaheadFormats, lookbehindFormats).length; return max > minimum ? max : minimum; }
/** * Defines the format of records identified by a lookahead symbol. * * @param lookahead the lookahead value that when found in the input, * will notify the parser to switch to a new record format, with different field lengths * @param lengths the field lengths of the record format identified by the given lookahead symbol. */ public void addFormatForLookahead(String lookahead, FixedWidthFields lengths) { Lookup.registerLookahead(lookahead, lengths, lookaheadFormats); }
/** * Defines the format of records identified by a lookbehind symbol. * * @param lookbehind the lookbehind value that when present in the previous output row, * will notify the writer to switch to a new record format, with different field lengths * @param lengths the field lengths of the record format identified by the given lookbehind symbol. */ public void addFormatForLookbehind(String lookbehind, FixedWidthFields lengths) { Lookup.registerLookbehind(lookbehind, lengths, lookbehindFormats); }
Lookup[] getLookaheadFormats() { return Lookup.getLookupFormats(lookaheadFormats, getFormat()); }