public virtual bool hasNext() { if (current.size() > 0) { return(true); } while (bucket < root.buckets.Length) { lock (root.locks[bucket]) { Node n = root.buckets[bucket]; while (n != null) { current.add(n); n = n.next; } bucket++; if (current.size() > 0) { return(true); } } } return(false); }
public override void updateMenuView(bool cleared) { [email protected] menuView = ([email protected] )mMenuView; if (mMaxItems < 0) { mMaxItems = menuView.getMaxItems(); } java.util.ArrayList <*****@*****.**> itemsToShow = mMenu .getNonActionItems(); bool needsMore = itemsToShow.size() > mMaxItems; base.updateMenuView(cleared); if (needsMore && (mMoreView == null || mMoreView.getParent() != menuView)) { if (mMoreView == null) { mMoreView = menuView.createMoreItemView(); mMoreView.setBackgroundDrawable(menuView.getItemBackgroundDrawable()); } menuView.addView(mMoreView); } else { if (!needsMore && mMoreView != null) { menuView.removeView(mMoreView); } } menuView.setNumActualItemsShown(needsMore ? mMaxItems - 1 : itemsToShow.size()); }
/// <summary>Creates a new instance of a XML Serializer.</summary> /// <remarks> /// Creates a new instance of a XML Serializer. /// <p><b>NOTE:</b> factory features are not used for XML Serializer. /// </remarks> /// <returns>A new instance of a XML Serializer.</returns> /// <exception cref="XmlPullParserException"> /// if a parser cannot be created which satisfies the /// requested configuration. /// </exception> /// <exception cref="org.xmlpull.v1.XmlPullParserException"></exception> public virtual org.xmlpull.v1.XmlSerializer newSerializer() { if (serializerClasses == null) { throw new org.xmlpull.v1.XmlPullParserException("Factory initialization incomplete - has not tried " + classNamesLocation); } if (serializerClasses.size() == 0) { throw new org.xmlpull.v1.XmlPullParserException("No valid serializer classes found in " + classNamesLocation); } java.lang.StringBuilder issues = new java.lang.StringBuilder(); { for (int i = 0; i < serializerClasses.size(); i++) { System.Type ppClass = (System.Type)serializerClasses.get(i); try { org.xmlpull.v1.XmlSerializer ser = (org.xmlpull.v1.XmlSerializer)System.Activator.CreateInstance (ppClass); return(ser); } catch (System.Exception ex) { issues.append(ppClass.FullName + ": " + ex.ToString() + "; "); } } } throw new org.xmlpull.v1.XmlPullParserException("could not create serializer: " + issues); }
public override int getCount() { java.util.ArrayList <*****@*****.**> items = this._enclosing .mOverflowOnly ? this.mAdapterMenu.getNonActionItems() : this.mAdapterMenu.getVisibleItems (); if (this.mExpandedIndex < 0) { return(items.size()); } return(items.size() - 1); }
// Private Methods // ------------------------------------------------------------------- /** * Initializes the collating state if it hasn't been already. */ private void start() { if (values == null) { values = new java.util.ArrayList <Object>(iterators.size()); valueSet = new java.util.BitSet(iterators.size()); for (int i = 0; i < iterators.size(); i++) { values.add(null); valueSet.clear(i); } } }
static void Main() { java.util.ArrayList<int> primeNumbers = new java.util.ArrayList<int>(); primeNumbers.add(1); primeNumbers.add(2); primeNumbers.add(3); primeNumbers.add(5); primeNumbers.add(7); java.lang.SystemJ.outJ.println("Work with all collection elements"); java.lang.SystemJ.outJ.println("Using collection with for loop"); for (int i = 0; i < primeNumbers.size(); i++) java.lang.SystemJ.outJ.println(primeNumbers.get(i)); java.lang.SystemJ.outJ.println("Using collection with iterator while loop"); java.util.Iterator<int> it = primeNumbers.iterator(); while (it.hasNext()) java.lang.SystemJ.outJ.println(it.next()); java.lang.SystemJ.outJ.println("Using Java collection with .NET foreach loop"); foreach (int prime in primeNumbers) java.lang.SystemJ.outJ.println(prime); java.lang.SystemJ.outJ.print(""); }
protected internal override void onDraw(android.graphics.Canvas canvas) { android.graphics.drawable.Drawable drawable = mHorizontalDivider; if (drawable != null) { // If we have a horizontal divider to draw, draw it at the remembered positions java.util.ArrayList <android.graphics.Rect> rects = mHorizontalDividerRects; { for (int i = rects.size() - 1; i >= 0; i--) { drawable.setBounds(rects.get(i)); drawable.draw(canvas); } } } drawable = mVerticalDivider; if (drawable != null) { // If we have a vertical divider to draw, draw it at the remembered positions java.util.ArrayList <android.graphics.Rect> rects = mVerticalDividerRects; { for (int i = rects.size() - 1; i >= 0; i--) { drawable.setBounds(rects.get(i)); drawable.draw(canvas); } } } }
static void Main() { java.util.ArrayList <int> primeNumbers = new java.util.ArrayList <int>(); primeNumbers.add(1); primeNumbers.add(2); primeNumbers.add(3); primeNumbers.add(5); primeNumbers.add(7); java.lang.SystemJ.outJ.println("Work with all collection elements"); java.lang.SystemJ.outJ.println("Using collection with for loop"); for (int i = 0; i < primeNumbers.size(); i++) { java.lang.SystemJ.outJ.println(primeNumbers.get(i)); } java.lang.SystemJ.outJ.println("Using collection with iterator while loop"); java.util.Iterator <int> it = primeNumbers.iterator(); while (it.hasNext()) { java.lang.SystemJ.outJ.println(it.next()); } java.lang.SystemJ.outJ.println("Using Java collection with .NET foreach loop"); foreach (int prime in primeNumbers) { java.lang.SystemJ.outJ.println(prime); } java.lang.SystemJ.outJ.print(""); }
public static string[] split(java.util.regex.Pattern pattern, string re, string input , int limit) { string[] fastResult = fastSplit(re, input, limit); if (fastResult != null) { return(fastResult); } // Unlike Perl, which considers the result of splitting the empty string to be the empty // array, Java returns an array containing the empty string. if (string.IsNullOrEmpty(input)) { return(new string[] { string.Empty }); } // Collect text preceding each occurrence of the separator, while there's enough space. java.util.ArrayList <string> list = new java.util.ArrayList <string>(); int maxSize = limit <= 0 ? int.MaxValue : limit; java.util.regex.Matcher matcher = new java.util.regex.Matcher(pattern, java.lang.CharSequenceProxy.Wrap (input)); int begin = 0; while (matcher.find() && list.size() + 1 < maxSize) { list.add(Sharpen.StringHelper.Substring(input, begin, matcher.start())); begin = matcher.end(); } return(finishSplit(list, input, begin, maxSize, limit)); }
/** * Returns the index of the least element in {@link #values}, * {@link #set(int) setting} any uninitialized values. * * @throws IllegalStateException */ private int least() { int leastIndex = -1; Object leastObject = null; for (int i = 0; i < values.size(); i++) { if (valueSet.get(i) == false) { set(i); } if (valueSet.get(i)) { if (leastIndex == -1) { leastIndex = i; leastObject = values.get(i); } else { Object curObject = values.get(i); if (comparator.compare(curObject, leastObject) < 0) { leastObject = curObject; leastIndex = i; } } } } return(leastIndex); }
public static string[] SplitStringByChar(string e, char p) { if (null == e) { throw new InvalidOperationException(); } var a = new java.util.ArrayList(); int i = -1; bool b = true; while (b) { int j = e.IndexOf(p, i + 1); if (j == -1) { a.add(e.Substring(i + 1)); b = false; } else { a.add(e.Substring(i + 1, j - i - 1)); i = j; } } return((string[])a.toArray(new string[a.size()])); }
/* * Returns a string containing a concise, human-readable description of this * {@code PermissionCollection}. * * @return a printable representation for this {@code PermissionCollection}. */ public override String ToString() { java.util.ArrayList <String> elist = new java.util.ArrayList <String>(100); java.util.Enumeration <Permission> elenum = elements(); String superStr = base.ToString(); int totalLength = superStr.length() + 5; if (elenum != null) { while (elenum.hasMoreElements()) { String el = elenum.nextElement().toString(); totalLength += el.length(); elist.add(el); } } int esize = elist.size(); totalLength += esize * 4; java.lang.StringBuilder result = new java.lang.StringBuilder(totalLength).append(superStr) .append(" ("); //$NON-NLS-1$ for (int i = 0; i < esize; i++) { result.append("\n ").append(elist.get(i).toString()); //$NON-NLS-1$ } return(result.append("\n)\n").toString()); //$NON-NLS-1$ }
/** * Constructs a new MultiRectArea and append rectangle from array */ public MultiRectArea(java.util.ArrayList <java.awt.Rectangle> buf) : this() { for (int i = 0; i < buf.size(); i++) { //Basties note: also foreach available... add(buf.get(i)); } }
internal static android.widget.ExpandableListPosition getRecycledOrCreate() { android.widget.ExpandableListPosition elp; lock (sPool) { if (sPool.size() > 0) { elp = sPool.remove(0); } else { return(new android.widget.ExpandableListPosition()); } } elp.resetState(); return(elp); }
internal override android.widget.Filter.FilterResults performFiltering(java.lang.CharSequence prefix) { android.widget.Filter.FilterResults results = new android.widget.Filter.FilterResults (); if (this._enclosing.mUnfilteredData == null) { this._enclosing.mUnfilteredData = new java.util.ArrayList <java.util.Map <string, object > >(this._enclosing.mData); } if (prefix == null || prefix.Length == 0) { java.util.ArrayList <java.util.Map <string, object> > list = this._enclosing.mUnfilteredData; results.values = list; results.count = list.size(); } else { string prefixString = prefix.ToString().ToLower(); java.util.ArrayList <java.util.Map <string, object> > unfilteredValues = this._enclosing .mUnfilteredData; int count = unfilteredValues.size(); java.util.ArrayList <java.util.Map <string, object> > newValues = new java.util.ArrayList <java.util.Map <string, object> >(count); { for (int i = 0; i < count; i++) { java.util.Map <string, object> h = unfilteredValues.get(i); if (h != null) { int len = this._enclosing.mTo.Length; { for (int j = 0; j < len; j++) { string str = (string)h.get(this._enclosing.mFrom[j]); string[] words = XobotOS.Runtime.Util.SplitStringRegex(str, " "); int wordCount = words.Length; { for (int k = 0; k < wordCount; k++) { string word = words[k]; if (word.ToLower().StartsWith(prefixString)) { newValues.add(h); break; } } } } } } } } results.values = newValues; results.count = newValues.size(); } return(results); }
private static android.widget.ExpandableListConnector.PositionMetadata getRecycledOrCreate () { android.widget.ExpandableListConnector.PositionMetadata pm; lock (sPool) { if (sPool.size() > 0) { pm = sPool.remove(0); } else { return(new android.widget.ExpandableListConnector.PositionMetadata()); } } pm.resetState(); return(pm); }
/// <summary> /// Creates a new instance of a XML Pull Parser /// using the currently configured factory features. /// </summary> /// <remarks> /// Creates a new instance of a XML Pull Parser /// using the currently configured factory features. /// </remarks> /// <returns>A new instance of a XML Pull Parser.</returns> /// <exception cref="XmlPullParserException"> /// if a parser cannot be created which satisfies the /// requested configuration. /// </exception> /// <exception cref="org.xmlpull.v1.XmlPullParserException"></exception> public virtual org.xmlpull.v1.XmlPullParser newPullParser() { if (parserClasses == null) { throw new org.xmlpull.v1.XmlPullParserException("Factory initialization was incomplete - has not tried " + classNamesLocation); } if (parserClasses.size() == 0) { throw new org.xmlpull.v1.XmlPullParserException("No valid parser classes found in " + classNamesLocation); } java.lang.StringBuilder issues = new java.lang.StringBuilder(); { for (int i = 0; i < parserClasses.size(); i++) { System.Type ppClass = (System.Type)parserClasses.get(i); try { org.xmlpull.v1.XmlPullParser pp = (org.xmlpull.v1.XmlPullParser)System.Activator.CreateInstance (ppClass); { for (java.util.Iterator <object> iter = features.keySet().iterator(); iter.hasNext ();) { string key = (string)iter.next(); bool value = (bool)features.get(key); if (value != null && value) { pp.setFeature(key, true); } } } return(pp); } catch (System.Exception ex) { issues.append(ppClass.FullName + ": " + ex.ToString() + "; "); } } } throw new org.xmlpull.v1.XmlPullParserException("could not create parser: " + issues ); }
public override bool shouldIncludeItem(int childIndex, [email protected] item) { java.util.ArrayList <*****@*****.**> itemsToShow = mMenu .getNonActionItems(); bool fits = (itemsToShow.size() == mMaxItems && childIndex < mMaxItems) || childIndex < mMaxItems - 1; return(fits && !item.isActionButton()); }
private void configureTab(android.app.ActionBar.Tab tab, int position) { [email protected] tabi = ([email protected] .TabImpl)tab; android.app.ActionBar.TabListener callback = tabi.getCallback(); if (callback == null) { throw new System.InvalidOperationException("Action Bar Tab must have a Callback"); } tabi.setPosition(position); mTabs.add(position, tabi); int count = mTabs.size(); { for (int i = position + 1; i < count; i++) { mTabs.get(i).setPosition(i); } } }
/// <summary> /// /// </summary> /// <param name="index"></param> /// <returns></returns> public bool GetSentence(uint index, ref InternalSentence sentence) { if ((index < 0) || (index > (this.SentencesCount - 1))) { throw new IndexOutOfRangeException(); } // extract the basic sentence fields CoreMap stanfordSentence = (CoreMap)_sentences.get((int)index); if (!ExtractSentence(stanfordSentence, ref sentence)) { return(false); } // extract words java.util.ArrayList stanfordWords = (java.util.ArrayList)stanfordSentence.get(_tokensAnnotationClass); if (stanfordWords.size() <= 0) { return(true); } // a "minor" optimisation (capacity) sentence.words = new System.Collections.Generic.List <InternalWord>( stanfordWords.size()); foreach (CoreMap stanfordWord in stanfordWords) { if (!ExtractWord(stanfordWord, ref sentence)) { // NOTE: currently, we fail the entire sentence even if a single // word fails return(false); } } ; return(true); }
public override void scaleCurrentDuration(float scale) { java.util.ArrayList <android.view.animation.Animation> animations = mAnimations; int count = animations.size(); { for (int i = 0; i < count; i++) { animations.get(i).scaleCurrentDuration(scale); } } }
public override int getCount() { java.util.ArrayList <*****@*****.**> items = this._enclosing .mMenu.getNonActionItems(); int count = items.size() - this._enclosing.mItemIndexOffset; if (this.mExpandedIndex < 0) { return(count); } return(count - 1); }
public override void restrictDuration(long durationMillis) { base.restrictDuration(durationMillis); java.util.ArrayList <android.view.animation.Animation> animations = mAnimations; int count = animations.size(); { for (int i = 0; i < count; i++) { animations.get(i).restrictDuration(durationMillis); } } }
private object[] collectComponentCallbacks() { object[] callbacks = null; lock (mComponentCallbacks) { if (mComponentCallbacks.size() > 0) { callbacks = mComponentCallbacks.toArray(); } } return(callbacks); }
private object[] collectActivityLifecycleCallbacks() { object[] callbacks = null; lock (mActivityLifecycleCallbacks) { if (mActivityLifecycleCallbacks.size() > 0) { callbacks = mActivityLifecycleCallbacks.toArray(); } } return(callbacks); }
/** * Returns <code>true</code> iff any {@link Iterator} * in the given list has a next value. */ private bool anyHasNext(java.util.ArrayList <Object> iters) { for (int i = 0; i < iters.size(); i++) { java.util.Iterator <Object> it = (java.util.Iterator <Object>)iters.get(i); if (it.hasNext()) { return(true); } } return(false); }
/// <summary> /// Converts arraylist of java.lang.Integer to a list of integers /// </summary> /// <param name="javaIntList">arraylist to convert</param> /// <returns>the list of integers</returns> public static List <int> ToIntList(java.util.ArrayList javaIntList) { List <int> intList = new List <int>(); for (int i = 0; i < javaIntList.size(); i++) { int convertBabySequencer = 0; Int32.TryParse(javaIntList.get(i).ToString(), out convertBabySequencer); intList.Add(convertBabySequencer); } return(intList); }
// The RI allows regular expressions beginning with ] or }, but that's probably a bug. /// <summary> /// Returns a result equivalent to /// <code>s.split(separator, limit)</code> /// if it's able /// to compute it more cheaply than ICU, or null if the caller should fall back to /// using ICU. /// </summary> public static string[] fastSplit(string re, string input, int limit) { // Can we do it cheaply? int len = re.Length; if (len == 0) { return(null); } char ch = re[0]; if (len == 1 && METACHARACTERS.IndexOf(ch) == -1) { } else { // We're looking for a single non-metacharacter. Easy. if (len == 2 && ch == '\\') { // We're looking for a quoted character. // Quoted metacharacters are effectively single non-metacharacters. ch = re[1]; if (METACHARACTERS.IndexOf(ch) == -1) { return(null); } } else { return(null); } } // We can do this cheaply... // Unlike Perl, which considers the result of splitting the empty string to be the empty // array, Java returns an array containing the empty string. if (string.IsNullOrEmpty(input)) { return(new string[] { string.Empty }); } // Collect text preceding each occurrence of the separator, while there's enough space. java.util.ArrayList <string> list = new java.util.ArrayList <string>(); int maxSize = limit <= 0 ? int.MaxValue : limit; int begin = 0; int end; while ((end = input.IndexOf(ch, begin)) != -1 && list.size() + 1 < maxSize) { list.add(Sharpen.StringHelper.Substring(input, begin, end)); begin = end + 1; } return(finishSplit(list, input, begin, maxSize, limit)); }
/// <summary>Removes a listener from the set listening to this animation.</summary> /// <remarks>Removes a listener from the set listening to this animation.</remarks> /// <param name="listener"> /// the listener to be removed from the current set of listeners for this /// animation. /// </param> public virtual void removeListener(android.animation.Animator.AnimatorListener listener ) { if (mListeners == null) { return; } mListeners.remove(listener); if (mListeners.size() == 0) { mListeners = null; } }
/// <summary>Starts all animations added since the last call to this function.</summary> /// <remarks> /// Starts all animations added since the last call to this function. Used to synchronize /// animations. /// </remarks> /// <param name="listener"> /// an optional listener to add to the animations. Typically used to know when /// to invalidate the surface these are being drawn to. /// </param> public virtual void startAnimations(android.animation.ValueAnimator.AnimatorUpdateListener listener) { { for (int i = 0; i < mNeedToStart.size(); i++) { android.animation.ObjectAnimator anim = mNeedToStart.get(i); anim.addUpdateListener(listener); anim.addListener(this); anim.start(); } } mNeedToStart.clear(); }
// The RI allows regular expressions beginning with ] or }, but that's probably a bug. /// <summary> /// Returns a result equivalent to /// <code>s.split(separator, limit)</code> /// if it's able /// to compute it more cheaply than ICU, or null if the caller should fall back to /// using ICU. /// </summary> public static string[] fastSplit(string re, string input, int limit) { // Can we do it cheaply? int len = re.Length; if (len == 0) { return null; } char ch = re[0]; if (len == 1 && METACHARACTERS.IndexOf(ch) == -1) { } else { // We're looking for a single non-metacharacter. Easy. if (len == 2 && ch == '\\') { // We're looking for a quoted character. // Quoted metacharacters are effectively single non-metacharacters. ch = re[1]; if (METACHARACTERS.IndexOf(ch) == -1) { return null; } } else { return null; } } // We can do this cheaply... // Unlike Perl, which considers the result of splitting the empty string to be the empty // array, Java returns an array containing the empty string. if (string.IsNullOrEmpty(input)) { return new string[] { string.Empty }; } // Collect text preceding each occurrence of the separator, while there's enough space. java.util.ArrayList<string> list = new java.util.ArrayList<string>(); int maxSize = limit <= 0 ? int.MaxValue : limit; int begin = 0; int end; while ((end = input.IndexOf(ch, begin)) != -1 && list.size() + 1 < maxSize) { list.add(Sharpen.StringHelper.Substring(input, begin, end)); begin = end + 1; } return finishSplit(list, input, begin, maxSize, limit); }
public virtual void setGroupVisible(int group, bool visible) { java.util.ArrayList <*****@*****.**> items = mItems; int itemCount = items.size(); { for (int i = 0; i < itemCount; i++) { [email protected] item = items.get(i); if (item.getGroupId() == group) { item.setVisible(visible); } } } }
public static string[] SplitStringByChar(string e, char p) { if (null == e) throw new InvalidOperationException(); var a = new java.util.ArrayList(); int i = -1; bool b = true; while (b) { int j = e.IndexOf(p, i + 1); if (j == -1) { a.add(e.Substring(i + 1)); b = false; } else { a.add(e.Substring(i + 1, j - i - 1)); i = j; } } return (string[])a.toArray(new string[a.size()]); }
//UPGRADE_TODO: The equivalent of method 'java.lang.Thread.run' is not an override method. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1143"' //UPGRADE_NOTE: Synchronized keyword was removed from method 'run'. Lock expression was added. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1027"' /// <summary> Simply runs the ChannelListener and lets it process Events. /// </summary> public override void Run() { lock (this) { List msgEvents = new ArrayList(); bool printPrompt = false; while (Enclosing_Instance.running) { Enclosing_Instance.channel.fillEventList(msgEvents); if (!msgEvents.isEmpty()) { Enclosing_Instance.stopTimer(); System.Text.StringBuilder buffer = new System.Text.StringBuilder(); for (int idx = 0; idx < msgEvents.size(); idx++) { MessageEvent event_Renamed = (MessageEvent) msgEvents.get(idx); if (event_Renamed.Type == MessageEvent.PARSE_ERROR || event_Renamed.Type == MessageEvent.ERROR || event_Renamed.Type == MessageEvent.RESULT) { printPrompt = true; Enclosing_Instance.lastIncompleteCommand = new System.Text.StringBuilder(); } if (event_Renamed.Type == MessageEvent.ERROR) { //UPGRADE_ISSUE: Method 'java.lang.System.getProperty' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javalangSystemgetProperty_javalangString"' buffer.Append(exceptionToString((System.Exception) event_Renamed.Message).Trim() + System.getProperty("line.separator")); } //UPGRADE_TODO: The equivalent in .NET for method 'java.Object.toString' may return a different value. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1043"' if (event_Renamed.Type != MessageEvent.COMMAND && !event_Renamed.Message.ToString().Equals("") && !event_Renamed.Message.Equals(Constants.NIL_SYMBOL)) { //UPGRADE_TODO: The equivalent in .NET for method 'java.Object.toString' may return a different value. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1043"' //UPGRADE_ISSUE: Method 'java.lang.System.getProperty' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javalangSystemgetProperty_javalangString"' buffer.Append(event_Renamed.Message.ToString().Trim() + System.getProperty("line.separator")); } } msgEvents.clear(); Enclosing_Instance.hideCursor(); Enclosing_Instance.printMessage(buffer.ToString().Trim(), true); if (printPrompt) { Enclosing_Instance.printPrompt(); Enclosing_Instance.moveCursorTo(Enclosing_Instance.lastPromptIndex); } Enclosing_Instance.showCursor(); printPrompt = false; Enclosing_Instance.startTimer(); } else { try { System.Threading.Thread.Sleep(new System.TimeSpan(10000 * 10)); } catch (System.Threading.ThreadInterruptedException e) { // Can be ignored } } } try { Enclosing_Instance.outWriter.Close(); } catch (System.IO.IOException e) { // we silently ignore it SupportClass.WriteStackTrace(e, Console.Error); } Enclosing_Instance.gui.Engine.MessageRouter.closeChannel(Enclosing_Instance.channel); } }
/** * Returns a string containing a concise, human-readable description of this * {@code PermissionCollection}. * * @return a printable representation for this {@code PermissionCollection}. */ public override String ToString() { java.util.ArrayList<String> elist = new java.util.ArrayList<String>(100); java.util.Enumeration<Permission> elenum = elements(); String superStr = base.ToString(); int totalLength = superStr.length() + 5; if (elenum != null) { while (elenum.hasMoreElements()) { String el = elenum.nextElement().toString(); totalLength += el.length(); elist.add(el); } } int esize = elist.size(); totalLength += esize * 4; java.lang.StringBuilder result = new java.lang.StringBuilder(totalLength).append(superStr) .append(" ("); //$NON-NLS-1$ for (int i = 0; i < esize; i++) { result.append("\n ").append(elist.get(i).toString()); //$NON-NLS-1$ } return result.append("\n)\n").toString(); //$NON-NLS-1$ }
internal override android.widget.Filter.FilterResults performFiltering(java.lang.CharSequence prefix) { android.widget.Filter.FilterResults results = new android.widget.Filter.FilterResults (); if (this._enclosing.mUnfilteredData == null) { this._enclosing.mUnfilteredData = new java.util.ArrayList<java.util.Map<string, object >>(this._enclosing.mData); } if (prefix == null || prefix.Length == 0) { java.util.ArrayList<java.util.Map<string, object>> list = this._enclosing.mUnfilteredData; results.values = list; results.count = list.size(); } else { string prefixString = prefix.ToString().ToLower(); java.util.ArrayList<java.util.Map<string, object>> unfilteredValues = this._enclosing .mUnfilteredData; int count = unfilteredValues.size(); java.util.ArrayList<java.util.Map<string, object>> newValues = new java.util.ArrayList <java.util.Map<string, object>>(count); { for (int i = 0; i < count; i++) { java.util.Map<string, object> h = unfilteredValues.get(i); if (h != null) { int len = this._enclosing.mTo.Length; { for (int j = 0; j < len; j++) { string str = (string)h.get(this._enclosing.mFrom[j]); string[] words = XobotOS.Runtime.Util.SplitStringRegex(str, " "); int wordCount = words.Length; { for (int k = 0; k < wordCount; k++) { string word = words[k]; if (word.ToLower().StartsWith(prefixString)) { newValues.add(h); break; } } } } } } } } results.values = newValues; results.count = newValues.size(); } return results; }
public static string[] split(java.util.regex.Pattern pattern, string re, string input , int limit) { string[] fastResult = fastSplit(re, input, limit); if (fastResult != null) { return fastResult; } // Unlike Perl, which considers the result of splitting the empty string to be the empty // array, Java returns an array containing the empty string. if (string.IsNullOrEmpty(input)) { return new string[] { string.Empty }; } // Collect text preceding each occurrence of the separator, while there's enough space. java.util.ArrayList<string> list = new java.util.ArrayList<string>(); int maxSize = limit <= 0 ? int.MaxValue : limit; java.util.regex.Matcher matcher = new java.util.regex.Matcher(pattern, java.lang.CharSequenceProxy.Wrap (input)); int begin = 0; while (matcher.find() && list.size() + 1 < maxSize) { list.add(Sharpen.StringHelper.Substring(input, begin, matcher.start())); begin = matcher.end(); } return finishSplit(list, input, begin, maxSize, limit); }
static void Main(string[] args) { bool mergedOutput = true; string projectDir = System.IO.Directory.GetParent( System.IO.Directory.GetParent( Environment.CurrentDirectory.ToString()).ToString()).ToString() + "\\"; string saveToPathPrefix = projectDir + @"OUT_MailMergeField"; // Programmatically configure Common Logging // (alternatively, you could do it declaratively in app.config) NameValueCollection commonLoggingproperties = new NameValueCollection(); commonLoggingproperties["showDateTime"] = "false"; commonLoggingproperties["level"] = "INFO"; LogManager.Adapter = new Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter(commonLoggingproperties); ILog log = LogManager.GetCurrentClassLogger(); log.Info("Hello from Common Logging"); // Necessary, if slf4j-api and slf4j-NetCommonLogging are separate DLLs ikvm.runtime.Startup.addBootClassPathAssembly( System.Reflection.Assembly.GetAssembly( typeof(org.slf4j.impl.StaticLoggerBinder))); // Configure to find docx4j.properties // .. add as URL the dir containing docx4j.properties (not the file itself!) Plutext.PropertiesConfigurator.setDocx4jPropertiesDir(projectDir + @"src\samples\resources\"); // Create a docx4j docx WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(); org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart(); documentPart.addObject(addParagraphWithMergeField("Hallo, MERGEFORMAT: ", " MERGEFIELD kundenname \\* MERGEFORMAT ", "«Kundenname»")); documentPart.addObject(addParagraphWithMergeField("Hallo, lower: ", " MERGEFIELD kundenname \\* Lower ", "«Kundenname»")); documentPart.addObject(addParagraphWithMergeField("Hallo, firstcap: ", " MERGEFIELD kundenname \\* FirstCap MERGEFORMAT ", "«Kundenname»")); documentPart.addObject(addParagraphWithMergeField("Hallo, random case: ", " MERGEFIELD KunDenName \\* MERGEFORMAT ", "«Kundenname»")); documentPart.addObject(addParagraphWithMergeField("Hallo, all caps: ", " MERGEFIELD KUNDENNAME \\* Upper MERGEFORMAT ", "«Kundenname»")); // " MERGEFIELD yourdate \@ "dddd, MMMM dd, yyyy" " //documentPart.addObject(addParagraphWithMergeField("Date example", " MERGEFIELD yourdate \\@ 'dddd, MMMM dd, yyyy' ", "«Kundenname»")); // FIXME .. doesn't work via .NET. Why? documentPart.addObject(addParagraphWithMergeField("Number example: ", " MERGEFIELD yournumber \\# $#,###,### ", "«Kundenname»")); // .. or alternatively, load existing //string template = @"C:\Users\jharrop\Documents\tmp-test-docx\HelloWorld.docx"; //WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage // .load(new java.io.File(template)); //Console.WriteLine(documentPart.getXML()); java.util.List data = new java.util.ArrayList(); // TODO: make more .NET friendly // Instance 1 java.util.Map map = new java.util.HashMap(); map.put( new DataFieldName("KundenNAme"), "Daffy duck"); map.put( new DataFieldName("Kundenname"), "Plutext"); map.put(new DataFieldName("Kundenstrasse"), "Bourke Street"); // To get dates right, make sure you have docx4j property docx4j.Fields.Dates.DateFormatInferencer.USA // set to true or false as appropriate. It defaults to non-US. map.put(new DataFieldName("yourdate"), "15/4/2013"); map.put(new DataFieldName("yournumber"), "2456800"); data.add(map); // Instance 2 map = new java.util.HashMap(); map.put( new DataFieldName("Kundenname"), "Jason"); map.put(new DataFieldName("Kundenstrasse"), "Collins Street"); map.put(new DataFieldName("yourdate"), "12/10/2013"); map.put(new DataFieldName("yournumber"), "1234800"); data.add(map); if (mergedOutput) { /* * This is a "poor man's" merge, which generates the mail merge * results as a single docx, and just hopes for the best. * Images and hyperlinks should be ok. But numbering * will continue, as will footnotes/endnotes. * * If your resulting documents aren't opening in Word, then * you probably need MergeDocx to perform the merge. */ // How to treat the MERGEFIELD, in the output? org.docx4j.model.fields.merge.MailMerger.setMERGEFIELDInOutput(org.docx4j.model.fields.merge.MailMerger.OutputField.KEEP_MERGEFIELD); // log.Debug(XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getJaxbElement(), true, true)); WordprocessingMLPackage output = org.docx4j.model.fields.merge.MailMerger.getConsolidatedResultCrude(wordMLPackage, data, true); // log.Info(XmlUtils.marshaltoString(output.getMainDocumentPart().getJaxbElement(), true, true)); SaveFromJavaUtils.save(output, saveToPathPrefix + ".docx"); } else { // Need to keep thane MERGEFIELDs. If you don't, you'd have to clone the docx, and perform the // merge on the clone. For how to clone, see the MailMerger code, method getConsolidatedResultCrude org.docx4j.model.fields.merge.MailMerger.setMERGEFIELDInOutput(org.docx4j.model.fields.merge.MailMerger.OutputField.KEEP_MERGEFIELD); for (int i = 0; i < data.size(); i++ ) { java.util.Map thismap = (java.util.Map)data.get(i); org.docx4j.model.fields.merge.MailMerger.performMerge(wordMLPackage, thismap, true); SaveFromJavaUtils.save(wordMLPackage, saveToPathPrefix + "_" + i + ".docx"); } } log.Info("Done! Saved to " + saveToPathPrefix); }