/// <summary> /// Internal utility to dump relationship lists in a structured format that can /// easily be compared with the tabular data in MS Project. /// </summary> /// <param name="relations">project file</param> private static void dumpRelationList(java.util.List relations) { if (relations != null && relations.isEmpty() == false) { if (relations.size() > 1) { System.Console.Write('"'); } bool first = true; foreach (Relation relation in relations.ToIEnumerable()) { if (!first) { System.Console.Write(','); } first = false; System.Console.Write(relation.TargetTask.ID); Duration lag = relation.Lag; if (relation.Type != RelationType.FINISH_START || lag.Duration != 0) { System.Console.Write(relation.Type); } if (lag.Duration != 0) { if (lag.Duration > 0) { System.Console.Write("+"); } System.Console.Write(lag); } } if (relations.size() > 1) { System.Console.Write('"'); } } }
/** * Factory method to create a SetList using the supplied list to retain order. * <p> * If the list contains duplicates, these are removed (first indexed one kept). * A <code>HashSet</code> is used for the set behaviour. * * @param list the list to decorate, must not be null * @throws IllegalArgumentException if list is null */ public static SetUniqueList decorate(java.util.List<Object> list) { if (list == null) { throw new java.lang.IllegalArgumentException("List must not be null"); } if (list.isEmpty()) { return new SetUniqueList(list, new java.util.HashSet<Object>()); } else { java.util.List<Object> temp = new java.util.ArrayList<Object>(list); list.clear(); SetUniqueList sl = new SetUniqueList(list, new java.util.HashSet<Object>()); sl.addAll(temp); return sl; } }
/** * Returns the array of providers which meet the user supplied set of * filters. The filter must be supplied in one of two formats: * <nl> * <li> CRYPTO_SERVICE_NAME.ALGORITHM_OR_TYPE</li> * <p/> * for example: "MessageDigest.SHA" The value associated with the key must * be an empty string. <li> CRYPTO_SERVICE_NAME.ALGORITHM_OR_TYPE</li> * ATTR_NAME:ATTR_VALUE * <p/> * for example: "Signature.MD2withRSA KeySize:512" where "KeySize:512" is * the value of the filter map entry. * </nl> * * @param filter * case-insensitive filter. * @return the providers which meet the user supplied string filter {@code * filter}. A {@code null} value signifies that none of the * installed providers meets the filter specification. * @throws InvalidParameterException * if an unusable filter is supplied. * @throws NullPointerException * if {@code filter} is {@code null}. */ public static Provider[] getProviders(java.util.Map<String, String> filter) { lock (lockJ) { if (filter == null) { throw new java.lang.NullPointerException("The filter is null"); //$NON-NLS-1$ } if (filter.isEmpty()) { return null; } java.util.List<Provider> result = Services.getProvidersList(); java.util.Set<java.util.MapNS.Entry<String, String>> keys = filter.entrySet(); java.util.MapNS.Entry<String, String> entry; for (java.util.Iterator<java.util.MapNS.Entry<String, String>> it = keys.iterator(); it.hasNext(); ) { entry = it.next(); String key = entry.getKey(); String val = entry.getValue(); String attribute = null; int i = key.indexOf(' '); int j = key.indexOf('.'); if (j == -1) { throw new InvalidParameterException("The filter is not in the required format"); //$NON-NLS-1$ } if (i == -1) { // <crypto_service>.<algorithm_or_type> if (val.length() != 0) { throw new InvalidParameterException("The filter is not in the required format"); //$NON-NLS-1$ } } else { // <crypto_service>.<algorithm_or_type> <attribute_name> if (val.length() == 0) { throw new InvalidParameterException("The filter is not in the required format"); //$NON-NLS-1$ } attribute = key.substring(i + 1); if (attribute.trim().length() == 0) { throw new InvalidParameterException("The filter is not in the required format"); //$NON-NLS-1$ } key = key.substring(0, i); } String serv = key.substring(0, j); String alg = key.substring(j + 1); if (serv.length() == 0 || alg.length() == 0) { throw new InvalidParameterException("The filter is not in the required format"); //$NON-NLS-1$ } Provider p; for (int k = 0; k < result.size(); k++) { try { p = result.get(k); } catch (java.lang.IndexOutOfBoundsException e) { break; } if (!p.implementsAlg(serv, alg, attribute, val)) { result.remove(p); k--; } } } if (result.size() > 0) { return result.toArray(new Provider[result.size()]); } return null; } }
/** * Transforms a map. * <p> * The transformer itself may throw an exception if necessary. * * @param map the map to transform * @throws the transformed object */ protected virtual java.util.Map<Object, Object> transformMap(java.util.Map<Object, Object> map) { if (map.isEmpty()) { return map; } java.util.Map<Object, Object> result = new LinkedMap(map.size()); for (java.util.Iterator<java.util.MapNS.Entry<Object, Object>> it = map.entrySet().iterator(); it.hasNext(); ) { java.util.MapNS.Entry<Object, Object> entry = it.next(); result.put(transformKey(entry.getKey()), transformValue(entry.getValue())); } return result; }
//----------------------------------------------------------------------- /** * Null-safe check if the specified collection is empty. * <p> * Null returns true. * * @param coll the collection to check, may be null * @return true if empty or null * @since Commons Collections 3.2 */ public static bool isEmpty(java.util.Collection<Object> coll) { return (coll == null || coll.isEmpty()); }
/** * Creates an {@code AttributedString} from the given text and the * attributes. The whole text has the given attributes applied. * * @param value * the text to take as base for this attributed string. * @param attributes * the attributes that the text is associated with. * @throws IllegalArgumentException * if the length of {@code value} is 0 but the size of {@code * attributes} is greater than 0. * @throws NullPointerException * if {@code value} is {@code null}. */ public AttributedString(System.String value, java.util.Map<AttributedCharacterIteratorNS.Attribute, System.Object> attributes) { if (value == null) { throw new java.lang.NullPointerException(); } if (value.Length == 0 && !attributes.isEmpty()) { // text.0B=Cannot add attributes to empty string throw new java.lang.IllegalArgumentException("Cannot add attributes to empty string"); //$NON-NLS-1$ } text = value; attributeMap = new java.util.HashMap<AttributedCharacterIteratorNS.Attribute, java.util.List<IAC_Range>>();//(attributes.size() * 4 / 3) + 1); java.util.Iterator<java.util.MapNS.Entry<AttributedCharacterIteratorNS.Attribute,System.Object>> it = attributes.entrySet().iterator(); while (it.hasNext()) { java.util.MapNS.Entry<AttributedCharacterIteratorNS.Attribute, System.Object> entry = it.next(); java.util.ArrayList<IAC_Range> ranges = new java.util.ArrayList<IAC_Range>(1); ranges.add(new IAC_Range(0, text.Length, entry.getValue())); attributeMap.put((AttributedCharacterIteratorNS.Attribute) entry .getKey(), ranges); } }
//----------------------------------------------------------------------- /** * Null-safe check if the specified map is empty. * <p> * Null returns true. * * @param map the map to check, may be null * @return true if empty or null * @since Commons Collections 3.2 */ public static bool isEmpty(java.util.Map<Object, Object> map) { return (map == null || map.isEmpty()); }