/// <summary>recursively tokenize "guts" (a segment, or part of one) into tokens, /// according to separators (aka delimiters) which are different at each level /// of recursion, and to a recursive depth which is discovered through "handler" /// via handler.delim(int) and handler.specDepth() As tokens are found, they /// are reported to handler via handler.putDatum(), which presumably stashes them /// away somewhere. We tell the handler about the location in the message via /// putDatum()'s key argument, which is a List of Integers representing the /// position in the parse tree (size() == depth of recursion). /// TODO: say more. /// </summary> protected internal static void parseSegmentGuts(NuGenER7.Handler handler, System.String guts, System.Collections.ArrayList nodeKey) { char thisDepthsDelim = handler.delim(nodeKey.Count - 1); //nodeKey.add(new Integer(0)); // will change nodeKey back before function exits SupportClass.Tokenizer gutsTokenizer = new SupportClass.Tokenizer(guts, System.Convert.ToString(thisDepthsDelim), true); while (gutsTokenizer.HasMoreTokens()) { System.String gutsToken = gutsTokenizer.NextToken(); if (gutsToken[0] == thisDepthsDelim) { // gutsToken is all delims -- skipping over as many fields or // components or whatevers as there are characters in the token: int oldvalue = ((System.Int32)nodeKey[nodeKey.Count - 1]); nodeKey[nodeKey.Count - 1] = (System.Int32)(oldvalue + gutsToken.Length); } else { if (nodeKey.Count < handler.specDepth()) { nodeKey.Add(0); parseSegmentGuts(handler, gutsToken, nodeKey); SupportClass.SetCapacity(nodeKey, nodeKey.Count - 1); } else { handler.putDatum(nodeKey, gutsToken); } } } //nodeKey.setSize(nodeKey.size()-1); // undoing add done at top of this func }
/** * @return the 3 best {@link FinderPattern}s from our list of candidates. The "best" are * those that have been detected at least {@link #CENTER_QUORUM} times, and whose module * size differs from the average among those patterns the least * @throws ReaderException if 3 such finder patterns do not exist */ private FinderPattern[] selectBestPatterns() { Collections.insertionSort(possibleCenters, new CenterComparator()); int size = 0; int max = possibleCenters.Count; while (size < max) { if (((FinderPattern)possibleCenters[size]).getCount() < CENTER_QUORUM) { break; } size++; } if (size < 3) { // Couldn't find enough finder patterns throw new ReaderException(); } if (size > 3) { // Throw away all but those first size candidate points we found. SupportClass.SetCapacity(possibleCenters, size); // We need to pick the best three. Find the most // popular ones whose module size is nearest the average float averageModuleSize = 0.0f; for (int i = 0; i < size; i++) { averageModuleSize += ((FinderPattern)possibleCenters[i]).getEstimatedModuleSize(); } averageModuleSize /= (float)size; // We don't have java.util.Collections in J2ME Collections.insertionSort(possibleCenters, new ClosestToAverageComparator(averageModuleSize)); } return(new FinderPattern[] { (FinderPattern)possibleCenters[0], (FinderPattern)possibleCenters[1], (FinderPattern)possibleCenters[2] }); }
/// <returns> the 3 best {@link FinderPattern}s from our list of candidates. The "best" are /// those that have been detected at least {@link #CENTER_QUORUM} times, and whose module /// size differs from the average among those patterns the least /// </returns> /// <throws> ReaderException if 3 such finder patterns do not exist </throws> private FinderPattern[] selectBestPatterns() { int startSize = possibleCenters.Count; if (startSize < 3) { // Couldn't find enough finder patterns return(null); } // Filter outlier possibilities whose module size is too different if (startSize > 3) { // But we can only afford to do so if we have at least 4 possibilities to choose from float totalModuleSize = 0.0f; for (int i = 0; i < startSize; i++) { totalModuleSize += ((FinderPattern)possibleCenters[i]).EstimatedModuleSize; } //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" float average = totalModuleSize / (float)startSize; for (int i = 0; i < possibleCenters.Count && possibleCenters.Count > 3; i++) { FinderPattern pattern = (FinderPattern)possibleCenters[i]; if (System.Math.Abs(pattern.EstimatedModuleSize - average) > 0.2f * average) { possibleCenters.RemoveAt(i); i--; } } } if (possibleCenters.Count > 3) { // Throw away all but those first size candidate points we found. Collections.insertionSort(possibleCenters, new CenterComparator()); SupportClass.SetCapacity(possibleCenters, 3); } return(new FinderPattern[] { (FinderPattern)possibleCenters[0], (FinderPattern)possibleCenters[1], (FinderPattern)possibleCenters[2] }); }
/// <summary>setSize(): resize. If this will grow the object, then we put default /// values into the new elements: "" into the String element, Integer(1) into the /// elements 2, 4, and 5, and Integer(0) into elements 1 and 3. /// returns this. /// </summary> public virtual NuGenDatumPath setSize(int newSize) { int oldSize = m_path.Count; SupportClass.SetCapacity(m_path, newSize); if (newSize > oldSize) { // give the new elements some default values: for (int i = oldSize; i < newSize; ++i) { if (i == 0) { set_Renamed(i, ""); } else { set_Renamed(i, (System.Object)((i == 1 || i == 3)?0:1)); } } } return(this); }
/// <summary>add() grows this by 1, inserting newValue at the end. /// newValue must be a String or an Integer depending on the index where it will /// be inserted, as noted at DatumPath.set(). /// returns this. /// (newValue == null) => NullPointerException /// </summary> public virtual NuGenDatumPath add(System.Object newValue) { SupportClass.SetCapacity(m_path, m_path.Count + 1); set_Renamed(m_path.Count - 1, newValue); return(this); }