public override string ToString() { if (isEmpty()) { return("[]"); } java.lang.StringBuilder buffer = new java.lang.StringBuilder(size() * 16); buffer.append('['); java.util.Iterator <E> it = iterator(); while (it.hasNext()) { object next = it.next(); if (next != this) { buffer.append(next); } else { buffer.append("(this Collection)"); } if (it.hasNext()) { buffer.append(", "); } } buffer.append(']'); return(buffer.ToString()); }
/** * Tests two lists for value-equality as per the equality contract in * {@link java.util.List#equals(java.lang.Object)}. * <p> * This method is useful for implementing <code>List</code> when you cannot * extend AbstractList. The method takes Collection instances to enable other * collection types to use the List implementation algorithm. * <p> * The relevant text (slightly paraphrased as this is a static method) is: * <blockquote> * Compares the two list objects for equality. Returns * <tt>true</tt> if and only if both * lists have the same size, and all corresponding pairs of elements in * the two lists are <i>equal</i>. (Two elements <tt>e1</tt> and * <tt>e2</tt> are <i>equal</i> if <tt>(e1==null ? e2==null : * e1.equals(e2))</tt>.) In other words, two lists are defined to be * equal if they contain the same elements in the same order. This * definition ensures that the equals method works properly across * different implementations of the <tt>List</tt> interface. * </blockquote> * * <b>Note:</b> The behaviour of this method is undefined if the lists are * modified during the equals comparison. * * @see java.util.List * @param list1 the first list, may be null * @param list2 the second list, may be null * @return whether the lists are equal by value comparison */ public static bool isEqualList(java.util.Collection <Object> list1, java.util.Collection <Object> list2) { if (list1 == list2) { return(true); } if (list1 == null || list2 == null || list1.size() != list2.size()) { return(false); } java.util.Iterator <Object> it1 = list1.iterator(); java.util.Iterator <Object> it2 = list2.iterator(); Object obj1 = null; Object obj2 = null; while (it1.hasNext() && it2.hasNext()) { obj1 = it1.next(); obj2 = it2.next(); if (!(obj1 == null ? obj2 == null : obj1.equals(obj2))) { return(false); } } return(!(it1.hasNext() || it2.hasNext())); }
public virtual bool remove(object @object) { java.util.Iterator <E> it = iterator(); if (@object != null) { while (it.hasNext()) { if (@object.Equals(it.next())) { it.remove(); return(true); } } } else { while (it.hasNext()) { if (it.next() == null) { it.remove(); return(true); } } } return(false); }
public override String ToString() { if (size() == 0) { return("[]"); } java.lang.StringBuffer buf = new java.lang.StringBuffer(16 * size()); buf.append("["); java.util.Iterator <Object> it = iterator(); bool hasNext = it.hasNext(); while (hasNext) { Object value = it.next(); buf.append(value == this ? "(this Collection)" : value); hasNext = it.hasNext(); if (hasNext) { buf.append(", "); } } buf.append("]"); return(buf.toString()); }
/** * Returns an {@code Enumeration} that contains all of the loaded JDBC * drivers that the current caller can access. * * @return An {@code Enumeration} containing all the currently loaded JDBC * {@code Drivers}. */ public static java.util.Enumeration <Driver> getDrivers() { java.lang.ClassLoader callerClassLoader = java.lang.Runtime.getRuntime().getClass().getClassLoader();// Basties note: sometime do the same as VM.callerClassLoader(); /* * Synchronize to avoid clashes with additions and removals of drivers * in the DriverSet */ lock (theDrivers) { /* * Create the Enumeration by building a Vector from the elements of * the DriverSet */ java.util.Vector <Driver> theVector = new java.util.Vector <Driver>(); java.util.Iterator <Driver> theIterator = theDrivers.iterator(); while (theIterator.hasNext()) { Driver theDriver = theIterator.next(); if (DriverManager.isClassFromClassLoader(theDriver, callerClassLoader)) { theVector.add(theDriver); } } return(theVector.elements()); } }
/** * Tries to find a driver that can interpret the supplied URL. * * @param url * the URL of a database. * @return a {@code Driver} that matches the provided URL. {@code null} if * no {@code Driver} understands the URL * @throws SQLException * if there is any kind of problem accessing the database. */ public static Driver getDriver(String url) { //throws SQLException { java.lang.ClassLoader callerClassLoader = java.lang.Runtime.getRuntime().getClass().getClassLoader(); // Basties note: sometime do the same as VM.callerClassLoader(); lock (theDrivers) { /* * Loop over the drivers in the DriverSet checking to see if one * does understand the supplied URL - return the first driver which * does understand the URL */ java.util.Iterator <Driver> theIterator = theDrivers.iterator(); while (theIterator.hasNext()) { Driver theDriver = theIterator.next(); if (theDriver.acceptsURL(url) && DriverManager.isClassFromClassLoader(theDriver, callerClassLoader)) { return(theDriver); } } } // If no drivers understand the URL, throw an SQLException // sql.6=No suitable driver // SQLState: 08 - connection exception // 001 - SQL-client unable to establish SQL-connection throw new SQLException("No suitable driver", "08001"); //$NON-NLS-1$ //$NON-NLS-2$ }
void WriteGraph(RdfGraph graph, RdfSourceWrapper sourcewrapper, StatementSink sink) { java.util.Iterator iter = graph.iterator(); while (iter.hasNext()) { GraphStatement stmt = (GraphStatement)iter.next(); Statement s; if (stmt is GraphStatementWrapper) { s = ((GraphStatementWrapper)stmt).s; } else { s = new Statement( sourcewrapper.ToEntity(stmt.getSubject()), sourcewrapper.ToEntity(stmt.getPredicate()), sourcewrapper.ToResource(stmt.getObject()), stmt.getGraphName() == null ? Statement.DefaultMeta : sourcewrapper.ToEntity(stmt.getGraphName())); } if (s.AnyNull) { continue; // unbound variable, or literal in bad position } sink.Add(s); } }
/** * Return the hash code value for this list. This implementation uses * exactly the code that is used to define the list hash function in the * documentation for the <code>List.hashCode</code> method. */ public override int GetHashCode() { if (fast) { int hashCode = 1; java.util.Iterator <Object> i = list.iterator(); while (i.hasNext()) { Object o = i.next(); hashCode = 31 * hashCode + (o == null ? 0 : o.GetHashCode()); } return(hashCode); } else { lock (list) { int hashCode = 1; java.util.Iterator <Object> i = list.iterator(); while (i.hasNext()) { Object o = i.next(); hashCode = 31 * hashCode + (o == null ? 0 : o.GetHashCode()); } return(hashCode); } } }
public Object next() { if (firstNodes.empty()) { throw new java.util.NoSuchElementException(); } // get a node from firstNodes ProviderNode node = firstNodes.pop(); // find all the outgoing nodes java.util.Iterator <Object> it = node.getOutgoingNodes(); while (it.hasNext()) { ProviderNode outNode = (ProviderNode)it.next(); // remove the incoming edge from the node. int edges = incomingEdges.get(outNode); edges--; incomingEdges.put(outNode, new java.lang.Integer(edges)); // add to the firstNodes if this node's incoming edge is equal to 0 if (edges == 0) { firstNodes.push(outNode); } } incomingEdges.remove(node); return(node.getProvider()); }
/** * Destroys all instances in the stack and clears the stack. * * @param key key passed to factory when destroying instances * @param stack stack to destroy */ private void destroyStack(K key, java.util.Stack <V> stack) { lock (this) { if (null == stack) { return; } else { if (null != _factory) { java.util.Iterator <V> it = stack.iterator(); while (it.hasNext()) { try { _factory.destroyObject(key, it.next()); } catch (Exception e) { // ignore error, keep destroying the rest } } } _totIdle -= stack.size(); _activeCount.remove(key); stack.clear(); } } }
public override bool retainAll(java.util.Collection <Object> coll) { bool result = collection.retainAll(coll); if (result == false) { return(false); } else if (collection.size() == 0) { setOrder.clear(); } else { for (java.util.Iterator <Object> it = setOrder.iterator(); it.hasNext();) { Object obj = it.next(); if (collection.contains(obj) == false) { it.remove(); } } } return(result); }
public override bool Equals(Object o) { if (!(o is java.util.Map <Object, Object>)) { return(false); } java.util.Map <Object, Object> m = (java.util.Map <Object, Object>)o; java.util.Set <Object> keys = keySet(); if (!keys.equals(m.keySet())) { return(false); } java.util.Iterator <Object> it = keys.iterator(); while (it.hasNext()) { Key key = (Key)it.next(); Object v1 = get(key); Object v2 = m.get(key); if (!(v1 == null?v2 == null:v1.equals(v2))) { return(false); } } return(true); }
/// <summary> /// https://universaldependencies.org/u/dep/index.html /// Stratify a sentence according to the subject-predicate relationship /// </summary> /// <param name="sentence"></param> /// <returns>sentence, subject, predicate, objective</returns> public List <(edu.stanford.nlp.util.CoreMap, edu.stanford.nlp.ling.IndexedWord, edu.stanford.nlp.ling.IndexedWord, edu.stanford.nlp.ling.IndexedWord)> StepSamplingDependency(edu.stanford.nlp.util.CoreMap sentence) { List <(edu.stanford.nlp.util.CoreMap, edu.stanford.nlp.ling.IndexedWord, edu.stanford.nlp.ling.IndexedWord, edu.stanford.nlp.ling.IndexedWord)> samplings = new List <(edu.stanford.nlp.util.CoreMap, edu.stanford.nlp.ling.IndexedWord, edu.stanford.nlp.ling.IndexedWord, edu.stanford.nlp.ling.IndexedWord)>(); edu.stanford.nlp.semgraph.SemanticGraph dependencies = sentence.get(enhancedPlusPlusDependenciesAnnotationClass) as edu.stanford.nlp.semgraph.SemanticGraph; java.util.Collection typedDependencies = dependencies.typedDependencies(); java.util.Iterator itr = typedDependencies.iterator(); while (itr.hasNext()) { edu.stanford.nlp.trees.TypedDependency td = itr.next() as edu.stanford.nlp.trees.TypedDependency; string relationType = td.reln().getShortName(); //Nominals if (relationType == "nsubj" || relationType == "nsubjpass") { edu.stanford.nlp.ling.IndexedWord subject, predicate, objective; subject = td.dep(); predicate = td.gov(); //在谓语位置上,缺不满足谓语角色的词,此种谓语可缺省 edu.stanford.nlp.ling.IndexedWord expl = FindIndexedWordByDependencyType(dependencies, predicate, "expl"); predicate = expl == null ? predicate : null; //直接宾语, objective = FindIndexedWordByDependencyType(dependencies, predicate, "obj", "dobj"); //动词或形容词的补语做宾语, open clausal complement objective = objective ?? FindIndexedWordByDependencyType(dependencies, predicate, "ccomp", "xcomp"); //加入层次集合 samplings.Add((sentence, subject, predicate, objective)); } } return(samplings); }
/** * Clears any objects sitting idle in the pool. */ public override void clear() { lock (this) { if (null != _factory) { java.util.Iterator <java.lang.refj.SoftReference <T> > iter = _pool.iterator(); while (iter.hasNext()) { try { T obj = iter.next().get(); if (null != obj) { _factory.destroyObject(obj); } } catch (Exception e) { // ignore error, keep destroying the rest } } } _pool.clear(); pruneClearedReferences(); } }
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 override bool removeAll <_T0>(java.util.Collection <_T0> collection) { bool result = false; if (size() <= collection.size()) { java.util.Iterator <E> it = iterator(); while (it.hasNext()) { if (collection.contains(it.next())) { it.remove(); result = true; } } } else { java.util.Iterator <_T0> it = collection.iterator(); while (it.hasNext()) { result = remove(it.next()) || result; } } return(result); }
/** * Adds an delete change. * * @param pChange * the change which should result in a deletion */ private void addDeletion(Change pChange) { if ((Change.TYPE_DELETE != pChange.type() && Change.TYPE_DELETE_DIR != pChange.type()) || pChange.targetFile() == null) { return; } String source = pChange.targetFile(); if (!changes.isEmpty()) { for (java.util.Iterator <Change> it = changes.iterator(); it.hasNext();) { Change change = (Change)it.next(); if (change.type() == Change.TYPE_ADD && change.getEntry() != null) { String target = change.getEntry().getName(); if (Change.TYPE_DELETE == pChange.type() && source.equals(target)) { it.remove(); } else if (Change.TYPE_DELETE_DIR == pChange.type() && target.matches(source + "/.*")) { it.remove(); } } } } changes.add(pChange); }
public void registerServiceProviders(java.util.Iterator <Object> providers) { for (java.util.Iterator <Object> iterator = providers; iterator.hasNext();) { categories.addProvider(iterator.next(), null); } }
/** * Adds an addition change. * * @param pChange * the change which should result in an addition */ private void addAddition(Change pChange) { if (Change.TYPE_ADD != pChange.type() || pChange.getInput() == null) { return; } if (!changes.isEmpty()) { for (java.util.Iterator <Change> it = changes.iterator(); it.hasNext();) { Change change = it.next(); if (change.type() == Change.TYPE_ADD && change.getEntry() != null) { org.apache.commons.compress.archivers.ArchiveEntry entry = change.getEntry(); if (entry.equals(pChange.getEntry())) { if (pChange.isReplaceMode()) { it.remove(); changes.add(pChange); return; } else { // do not add this change return; } } } } } changes.add(pChange); }
/** * Returns a set of attributes present in the {@code AttributedString}. * An empty set returned indicates that no attributes where defined. * * @return a set of attribute keys that may be empty. */ public java.util.Set <AttributedCharacterIteratorNS.Attribute> getAllAttributeKeys() { if (begin == 0 && end == attrString.text.Length && attributesAllowed == null) { return(attrString.attributeMap.keySet()); } java.util.Set <AttributedCharacterIteratorNS.Attribute> result = new java.util.HashSet <AttributedCharacterIteratorNS.Attribute>();//(attrString.attributeMap.size() * 4 / 3) + 1); java.util.Iterator <java.util.MapNS.Entry <AttributedCharacterIteratorNS.Attribute, java.util.List <IAC_Range> > > it = attrString.attributeMap .entrySet().iterator(); while (it.hasNext()) { java.util.MapNS.Entry <AttributedCharacterIteratorNS.Attribute, java.util.List <IAC_Range> > entry = it.next(); if (attributesAllowed == null || attributesAllowed.contains(entry.getKey())) { java.util.List <IAC_Range> ranges = entry.getValue(); if (inRange(ranges)) { result.add(entry.getKey()); } } } return(result); }
//----------------------------------------------------------------------- /** * Returns the Map as a string. * * @return the Map as a String */ public override String ToString() { if (isEmpty()) { return("{}"); } java.lang.StringBuffer buf = new java.lang.StringBuffer(); buf.append('{'); bool first = true; java.util.Iterator <Object> it = entrySet().iterator(); while (it.hasNext()) { java.util.MapNS.Entry <Object, Object> entry = (java.util.MapNS.Entry <Object, Object>)it.next(); Object key = entry.getKey(); Object value = entry.getValue(); if (first) { first = false; } else { buf.append(", "); } buf.append(key == this ? "(this Map)" : key); buf.append('='); buf.append(value == this ? "(this Map)" : value); } buf.append('}'); return(buf.toString()); }
/** * Returns an array of all of this bag's elements. * * @param array the array to populate * @return an array of all of this bag's elements */ public virtual Object[] toArray <Object>(Object[] array) { int size = this.size(); if (array.Length < size) { array = new Object[sizeJ]; } int i = 0; java.util.Iterator <Object> it = (java.util.Iterator <Object>)map.keySet().iterator(); while (it.hasNext()) { Object current = it.next(); for (int index = getCount(current); index > 0; index--) { array[i++] = current; } } if (array.Length > size) { array[size] = default(Object); } return(array); }
//----------------------------------------------------------------------- /** * Compares this Bag to another. * This Bag equals another Bag if it contains the same number of occurrences of * the same elements. * * @param object the Bag to compare to * @return true if equal */ public override bool Equals(Object obj) { if (obj == this) { return(true); } if (obj is Bag == false) { return(false); } Bag other = (Bag)obj; if (other.size() != size()) { return(false); } for (java.util.Iterator <Object> it = map.keySet().iterator(); it.hasNext();) { Object element = it.next(); if (other.getCount(element) != getCount(element)) { return(false); } } return(true); }
/* * * Adds information about provider services into HashMap. * * @param p */ public static void initServiceInfo(java.security.Provider p) { java.security.Provider.Service serv; String key; String type; String alias; java.lang.StringBuilder sb = new java.lang.StringBuilder(128); for (java.util.Iterator <java.security.Provider.Service> it1 = p.getServices().iterator(); it1.hasNext();) { serv = it1.next(); type = serv.getType(); sb.delete(0, sb.length()); key = sb.append(type).append(".").append( //$NON-NLS-1$ Util.toUpperCase(serv.getAlgorithm())).toString(); if (!services.containsKey(key)) { services.put(key, serv); } for (java.util.Iterator <String> it2 = Engine.door.getAliases(serv); it2.hasNext();) { alias = it2.next(); sb.delete(0, sb.length()); key = sb.append(type).append(".").append(Util.toUpperCase(alias)) //$NON-NLS-1$ .toString(); if (!services.containsKey(key)) { services.put(key, serv); } } } }
/** * Remove any members of the bag that are not in the given * bag, respecting cardinality. * @see #retainAll(Collection) * * @param other the bag to retain * @return <code>true</code> if this call changed the collection */ bool retainAll(Bag other) { bool result = false; Bag excess = new HashBag(); java.util.Iterator <Object> i = uniqueSet().iterator(); while (i.hasNext()) { Object current = i.next(); int myCount = getCount(current); int otherCount = other.getCount(current); if (1 <= otherCount && otherCount <= myCount) { excess.add(current, myCount - otherCount); } else { excess.add(current, myCount); } } if (!excess.isEmpty()) { result = removeAll(excess); } return(result); }
/// <summary> /// Gets the response and modify the headers. /// </summary> /// <returns>The response.</returns> /// <param name="request">Request.</param> public override WebResponse getResponse(WebRequest request) { WebResponse response = base.getResponse(request); // // Only if Url matches // if (request.getUrl().toExternalForm().Contains("com")) { string content = response.getContentAsString("UTF-8"); java.util.ArrayList newheaders = new java.util.ArrayList(); java.util.List headers = response.getResponseHeaders(); java.util.Iterator it = headers.iterator(); // // Remove the 'Access-Control-Allow-Origin' header // while (it.hasNext()) { com.gargoylesoftware.htmlunit.util.NameValuePair o = (com.gargoylesoftware.htmlunit.util.NameValuePair)it.next(); if (o.getName().Equals("Access-Control-Allow-Origin")) { string value = response.getResponseHeaderValue("Access-Control-Allow-Origin"); Console.WriteLine("Found header 'Access-Control-Allow-Origin' = \"{0}\" and stripping it from new headers for response", value); continue; //headers.remove(o); } newheaders.add(o); } byte[] utf = System.Text.Encoding.UTF8.GetBytes(content); WebResponseData data = new WebResponseData(utf, response.getStatusCode(), response.getStatusMessage(), newheaders); response = new WebResponse(data, request, response.getLoadTime()); return(response); } return(response); }
/** * Return the hash code value for this map. This implementation uses * exactly the code that is used to define the list hash function in the * documentation for the <code>Map.hashCode</code> method. * * @return suitable integer hash code */ public override int GetHashCode() { if (fast) { int h = 0; java.util.Iterator <java.util.MapNS.Entry <Object, Object> > i = map.entrySet().iterator(); while (i.hasNext()) { h += i.next().GetHashCode(); } return(h); } else { lock (map) { int h = 0; java.util.Iterator <java.util.MapNS.Entry <Object, Object> > i = map.entrySet().iterator(); while (i.hasNext()) { h += i.next().GetHashCode(); } return(h); } } }
/// <summary> /// Get the IEnemurator instance for this wrapped java.util.Iterator. /// </summary> /// <returns></returns> public virtual IEnumerator <E> GetEnumerator() { java.util.Iterator <E> it = this.iterator(); while (it.hasNext()) { yield return(it.next()); } }
public bool hasNext() { if (expected != root.map) { throw new java.util.ConcurrentModificationException(); } return(iterator.hasNext()); }
public static void forEach(Iterable @this, java.util.function.Consumer consumer) { java.util.Iterator i = @this.iterator(); while (i.hasNext()) { consumer.accept(i.next()); } }