Example #1
0
		private static string[] finishSplit(java.util.List<string> list, string input, int
			 begin, int maxSize, int limit)
		{
			// Add trailing text.
			if (begin < input.Length)
			{
				list.add(Sharpen.StringHelper.Substring(input, begin));
			}
			else
			{
				if (limit != 0)
				{
					// No point adding the empty string if limit == 0, just to remove it below.
					list.add(string.Empty);
				}
			}
			// Remove all trailing empty matches in the limit == 0 case.
			if (limit == 0)
			{
				int i = list.size() - 1;
				while (i >= 0 && string.IsNullOrEmpty(list.get(i)))
				{
					list.remove(i);
					i--;
				}
			}
			// Convert to an array.
			return list.toArray(new string[list.size()]);
		}
 /**
  * Adds all elements in the enumeration to the given collection.
  *
  * @param collection  the collection to add to, must not be null
  * @param enumeration  the enumeration of elements to add, must not be null
  * @throws NullPointerException if the collection or enumeration is null
  */
 public static void addAll(java.util.Collection<Object> collection, java.util.Enumeration<Object> enumeration)
 {
     while (enumeration.hasMoreElements())
     {
         collection.add(enumeration.nextElement());
     }
 }
Example #3
0
		internal virtual void findItemsWithShortcutForKey(java.util.List<*****@*****.**
			> items, int keyCode, android.view.KeyEvent @event)
		{
			bool qwerty = isQwertyMode();
			int metaState = @event.getMetaState();
			android.view.KeyCharacterMap.KeyData possibleChars = new android.view.KeyCharacterMap
				.KeyData();
			// Get the chars associated with the keyCode (i.e using any chording combo)
			bool isKeyCodeMapped = @event.getKeyData(possibleChars);
			// The delete key is not mapped to '\b' so we treat it specially
			if (!isKeyCodeMapped && (keyCode != android.view.KeyEvent.KEYCODE_DEL))
			{
				return;
			}
			// Look for an item whose shortcut is this key.
			int N = mItems.size();
			{
				for (int i = 0; i < N; i++)
				{
					[email protected] item = mItems.get(i);
					if (item.hasSubMenu())
					{
						(([email protected])item.getSubMenu()).findItemsWithShortcutForKey
							(items, keyCode, @event);
					}
					char shortcutChar = qwerty ? item.getAlphabeticShortcut() : item.getNumericShortcut
						();
					if (((metaState & (android.view.KeyEvent.META_SHIFT_ON | android.view.KeyEvent.META_SYM_ON
						)) == 0) && (shortcutChar != 0) && (shortcutChar == possibleChars.meta[0] || shortcutChar
						 == possibleChars.meta[2] || (qwerty && shortcutChar == '\b' && keyCode == android.view.KeyEvent
						.KEYCODE_DEL)) && item.isEnabled())
					{
						items.add(item);
					}
				}
			}
		}
 /**
  * Adds all elements in the iteration to the given collection.
  *
  * @param collection  the collection to add to, must not be null
  * @param iterator  the iterator of elements to add, must not be null
  * @throws NullPointerException if the collection or iterator is null
  */
 public static void addAll(java.util.Collection<Object> collection, java.util.Iterator<Object> iterator)
 {
     while (iterator.hasNext())
     {
         collection.add(iterator.next());
     }
 }
 /**
  * Transforms all elements from the inputIterator with the given transformer
  * and adds them to the outputCollection.
  * <p>
  * If the input iterator or transformer is null, there is no change to the
  * output collection.
  *
  * @param inputIterator  the iterator to get the input from, may be null
  * @param transformer  the transformer to use, may be null
  * @param outputCollection  the collection to output into, may not be null
  * @return the outputCollection with the transformed input added
  * @throws NullPointerException if the output collection is null
  */
 public static java.util.Collection<Object> collect(java.util.Iterator<Object> inputIterator, Transformer transformer, java.util.Collection<Object> outputCollection)
 {
     if (inputIterator != null && transformer != null)
     {
         while (inputIterator.hasNext())
         {
             Object item = inputIterator.next();
             Object value = transformer.transform(item);
             outputCollection.add(value);
         }
     }
     return outputCollection;
 }
 //-----------------------------------------------------------------------
 /**
  * Adds an element to the collection unless the element is null.
  *
  * @param collection  the collection to add to, must not be null
  * @param object  the object to add, if null it will not be added
  * @return true if the collection changed
  * @throws NullPointerException if the collection is null
  * @since Commons Collections 3.2
  */
 public static bool addIgnoreNull(java.util.Collection<Object> collection, Object obj)
 {
     return (obj == null ? false : collection.add(obj));
 }
 /**
  * Adds all elements in the array to the given collection.
  *
  * @param collection  the collection to add to, must not be null
  * @param elements  the array of elements to add, must not be null
  * @throws NullPointerException if the collection or array is null
  */
 public static void addAll(java.util.Collection<Object> collection, Object[] elements)
 {
     for (int i = 0, size = elements.Length; i < size; i++)
     {
         collection.add(elements[i]);
     }
 }
 /**
  * Selects all elements from inputCollection which don't match the given predicate
  * and adds them to outputCollection.
  * <p>
  * If the input predicate is <code>null</code>, no elements are added to <code>outputCollection</code>.
  *
  * @param inputCollection  the collection to get the input from, may be null
  * @param predicate  the predicate to use, may be null
  * @param outputCollection  the collection to output into, may not be null
  */
 public static void selectRejected(java.util.Collection<Object> inputCollection, Predicate predicate, java.util.Collection<Object> outputCollection)
 {
     if (inputCollection != null && predicate != null)
     {
         for (java.util.Iterator<Object> iter = inputCollection.iterator(); iter.hasNext(); )
         {
             Object item = iter.next();
             if (predicate.evaluate(item) == false)
             {
                 outputCollection.add(item);
             }
         }
     }
 }