Ejemplo n.º 1
0
 public bool addAll(int i, java.util.Collection <Object> o)
 {
     if (root.fast)
     {
         lock (root)
         {
             java.util.ArrayList <Object> temp = (java.util.ArrayList <Object>)root.list.clone();
             bool r = get(temp).addAll(i, o);
             root.list = temp;
             if (r)
             {
                 last += o.size();
             }
             expected = temp;
             return(r);
         }
     }
     else
     {
         lock (root.list)
         {
             return(get(expected).addAll(i, o));
         }
     }
 }
Ejemplo n.º 2
0
 public bool removeAll(java.util.Collection <Object> o)
 {
     if (root.fast)
     {
         lock (root)
         {
             java.util.ArrayList <Object> temp = (java.util.ArrayList <Object>)root.list.clone();
             java.util.List <Object>      sub  = get(temp);
             bool r = sub.removeAll(o);
             if (r)
             {
                 last = first + sub.size();
             }
             root.list = temp;
             expected  = temp;
             return(r);
         }
     }
     else
     {
         lock (root.list)
         {
             return(get(expected).removeAll(o));
         }
     }
 }
 /**
  * Add an additional Map to the composite.
  *
  * @param map  the Map to be added to the composite
  * @throws IllegalArgumentException if there is a key collision and there is no
  *         MapMutator set to handle it.
  */
 public void addComposited(java.util.Map <Object, Object> map)
 {//throws IllegalArgumentException {
     lock (this)
     {
         for (int i = composite.Length - 1; i >= 0; --i)
         {
             java.util.Collection <Object> intersect = CollectionUtils.intersection(this.composite[i].keySet(), map.keySet());
             if (intersect.size() != 0)
             {
                 if (this.mutator == null)
                 {
                     throw new java.lang.IllegalArgumentException("Key collision adding Map to CompositeMap");
                 }
                 else
                 {
                     this.mutator.resolveCollision(this, this.composite[i], map, intersect);
                 }
             }
         }
         java.util.Map <Object, Object>[] temp = new java.util.Map <Object, Object> [this.composite.Length + 1];
         java.lang.SystemJ.arraycopy(this.composite, 0, temp, 0, this.composite.Length);
         temp[temp.Length - 1] = map;
         this.composite        = temp;
     }
 }
Ejemplo n.º 4
0
        public override bool retainAll(java.util.Collection <Object> coll)
        {
            bool result = base.retainAll(coll);

            setJ.retainAll(coll);
            return(result);
        }
 /**
  * Constructs a new <code>EnumerationIterator</code> that will remove
  * elements from the specified collection.
  *
  * @param enumeration  the enumeration to use
  * @param collection  the collection to remove elements form
  */
 public EnumerationIterator(java.util.Enumeration <Object> enumeration, java.util.Collection <Object> collection)
     : base()
 {
     this.enumeration = enumeration;
     this.collection  = collection;
     this.last        = null;
 }
Ejemplo n.º 6
0
        private void removeNodeImpl()// throws BackingStoreException {
        {
            lock (lockJ) {
                checkState();
                String[] childrenNames = childrenNamesSpi();
                for (int i = 0; i < childrenNames.Length; i++)
                {
                    if (null == cachedNode.get(childrenNames[i]))
                    {
                        AbstractPreferences child = childSpi(childrenNames[i]);
                        cachedNode.put(childrenNames[i], child);
                    }
                }

                java.util.Collection <AbstractPreferences> values = cachedNode.values();
                AbstractPreferences[] children = values
                                                 .toArray(new AbstractPreferences[values.size()]);
                foreach (AbstractPreferences child in children)
                {
                    child.removeNodeImpl();
                }
                removeNodeSpi();
                isRemovedJ = true;
                parentPref.cachedNode.remove(nodeName);
            }
            if (parentPref.nodeChangeListeners.size() > 0)
            {
                parentPref.notifyChildRemoved(this);
            }
        }
Ejemplo n.º 7
0
        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);
        }
 /**
  * Removes a collection from the those being decorated in this composite.
  *
  * @param coll  collection to be removed
  */
 public virtual void removeComposited(java.util.Collection <Object> coll)
 {
     java.util.ArrayList <Object> list = new java.util.ArrayList <Object>(this.all.Length);
     list.addAll(java.util.Arrays <Object> .asList <Object>(this.all));
     list.remove(coll);
     this.all = (java.util.Collection <Object>[])list.toArray(new java.util.Collection <Object> [list.size()]);
 }
Ejemplo n.º 9
0
        /**
         * Factory method to create an unmodifiable bounded collection.
         * <p>
         * This method is capable of drilling down through up to 1000 other decorators
         * to find a suitable BoundedCollection.
         *
         * @param coll  the <code>BoundedCollection</code> to decorate, must not be null
         * @return a new unmodifiable bounded collection
         * @throws IllegalArgumentException if bag is null
         */
        public static BoundedCollection decorateUsing(java.util.Collection <Object> coll)
        {
            if (coll == null)
            {
                throw new java.lang.IllegalArgumentException("The collection must not be null");
            }

            // handle decorators
            for (int i = 0; i < 1000; i++)
            {  // counter to prevent infinite looping
                if (coll is BoundedCollection)
                {
                    break;  // normal loop exit
                }
                else if (coll is AbstractCollectionDecorator)
                {
                    coll = ((AbstractCollectionDecorator)coll).collection;
                }
                else if (coll is SynchronizedCollection)
                {
                    coll = ((SynchronizedCollection)coll).collection;
                }
                else
                {
                    break;  // normal loop exit
                }
            }

            if (coll is BoundedCollection == false)
            {
                throw new java.lang.IllegalArgumentException("The collection is not a bounded collection");
            }
            return(new UnmodifiableBoundedCollection((BoundedCollection)coll));
        }
        /**
         * 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()));
        }
Ejemplo n.º 11
0
 public ValuesIterator(Object key, MultiValueMap root)
 {
     this.root     = root;
     this.key      = key;
     this.values   = root.getCollection(key);
     this.iterator = values.iterator();
 }
Ejemplo n.º 12
0
        /// <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);
        }
 public virtual bool retainAll(java.util.Collection <Object> coll)
 {
     lock (lockJ)
     {
         return(collection.retainAll(coll));
     }
 }
 public bool addAll(int index, java.util.Collection <Object> coll)
 {
     lock (lockJ)
     {
         return(getList().addAll(index, coll));
     }
 }
Ejemplo n.º 15
0
        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);
        }
Ejemplo n.º 16
0
 public override bool addAll <_T0>(java.util.Collection <_T0> collection)
 {
     lock (this._enclosing)
     {
         return(this.addAll(this.size(), collection));
     }
 }
Ejemplo n.º 17
0
        public void runRules(String[] rules, java.lang.Object[] facts)
        {
            KnowledgeBase    kbase    = KnowledgeBaseFactory.newKnowledgeBase();
            KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

            for (int i = 0; i < rules.Length; i++)
            {
                String ruleFile = rules[i];
                Console.WriteLine("Loading file: " + ruleFile);
                ruleFile = Path.GetFullPath(Path.Combine("rules", ruleFile));
                kbuilder.add(ResourceFactory.newFileResource(ruleFile), ResourceType.DRL);
            }

            java.util.Collection pkgs = kbuilder.getKnowledgePackages();
            kbase.addKnowledgePackages(pkgs);
            StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

            for (int i = 0; i < facts.Length; i++)
            {
                java.lang.Object fact = facts[i];
                //Console.WriteLine("Inserting fact: " + fact);
                ksession.insert(fact);
            }



            ksession.fireAllRules();
        }
 /**
  * Constructor that wraps (not copies).
  *
  * @param coll  the collection to decorate, must not be null
  * @throws IllegalArgumentException if the collection is null
  */
 protected AbstractCollectionDecorator(java.util.Collection <Object> coll)
 {
     if (coll == null)
     {
         throw new java.lang.IllegalArgumentException("Collection must not be null");
     }
     this.collection = coll;
 }
Ejemplo n.º 19
0
 public override bool containsAll <_T0>(java.util.Collection <_T0> collection)
 {
     java.util.concurrent.CopyOnWriteArrayList.Slice slice = this.slice;
     object[] snapshot = this._enclosing.elements;
     slice.checkConcurrentModification(snapshot);
     return(java.util.concurrent.CopyOnWriteArrayList <E> .containsAll(collection, snapshot
                                                                       , slice.from, slice.to));
 }
 /**
  * Gets a values view of the map.
  * Changes made on the view are reflected in the map.
  * The set supports remove and clear but not add.
  *
  * @return the values view
  */
 public virtual java.util.Collection <Object> values()
 {
     if (valuesJ == null)
     {
         valuesJ = new Values(this);
     }
     return(valuesJ);
 }
 /**
  * Factory method to create an unmodifiable collection.
  * <p>
  * If the collection passed in is already unmodifiable, it is returned.
  *
  * @param coll  the collection to decorate, must not be null
  * @return an unmodifiable collection
  * @throws IllegalArgumentException if collection is null
  */
 public static java.util.Collection <Object> decorate(java.util.Collection <Object> coll)
 {
     if (coll is Unmodifiable)
     {
         return(coll);
     }
     return(new UnmodifiableCollection(coll));
 }
 public bool addAll(int index, java.util.Collection <Object> coll)
 {
     for (java.util.Iterator <Object> it = coll.iterator(); it.hasNext();)
     {
         validate(it.next());
     }
     return(getList().addAll(index, coll));
 }
Ejemplo n.º 23
0
 /**
  * Returns a collection view of the values
  */
 public override java.util.Collection <V> values()
 {
     if (valuesJ == null)
     {
         valuesJ = new ValuesCollectionImpl(this);
     }
     return(valuesJ);
 }
Ejemplo n.º 24
0
 public override bool addAll(java.util.Collection <Object> c)
 {
     lock (lockJ)
     {
         timeoutWait(c.size());
         return(getBuffer().addAll(c));
     }
 }
 /**
  * Remove any members of the bag that are not in the given
  * bag, respecting cardinality.
  *
  * @param coll  the collection to retain
  * @return true if this call changed the collection
  */
 public virtual bool retainAll(java.util.Collection <Object> coll)
 {
     if (coll is Bag)
     {
         return(retainAll((Bag)coll));
     }
     return(retainAll(new HashBag(coll)));
 }
Ejemplo n.º 26
0
 /**
  * Override to validate the objects being added to ensure they match
  * the predicate. If any one fails, no update is made to the underlying
  * collection.
  *
  * @param coll  the collection being added
  * @return the result of adding to the underlying collection
  * @throws IllegalArgumentException if the add is invalid
  */
 public override bool addAll(java.util.Collection <Object> coll)
 {
     for (java.util.Iterator <Object> it = coll.iterator(); it.hasNext();)
     {
         validate(it.next());
     }
     return(getCollection().addAll(coll));
 }
        // Looping
        //-----------------------------------------------------------------------

        /**
         * Gets an iterator that loops continuously over the supplied collection.
         * <p>
         * The iterator will only stop looping if the remove method is called
         * enough times to empty the collection, or if the collection is empty
         * to start with.
         *
         * @param coll  the collection to iterate over, not null
         * @return a new looping iterator
         * @throws NullPointerException if the collection is null
         */
        public static ResettableIterator loopingIterator(java.util.Collection <Object> coll)
        {
            if (coll == null)
            {
                throw new java.lang.NullPointerException("Collection must not be null");
            }
            return(new LoopingIterator(coll));
        }
Ejemplo n.º 28
0
 /**
  * Constructor that wraps a collection.
  * <p>
  * There is no way to reset an Iterator instance without recreating it from
  * the original source, so the Collection must be passed in.
  *
  * @param coll  the collection to wrap
  * @throws NullPointerException if the collection is null
  */
 public LoopingIterator(java.util.Collection <Object> coll)
 {
     if (coll == null)
     {
         throw new java.lang.NullPointerException("The collection must not be null");
     }
     collection = coll;
     reset();
 }
 /**
  * Checks whether the collection at the specified key contains the value.
  *
  * @param value  the value to search for
  * @return true if the map contains the value
  * @since Commons Collections 3.1
  */
 public virtual bool containsValue(Object key, Object value)
 {
     java.util.Collection <Object> coll = getCollection(key);
     if (coll == null)
     {
         return(false);
     }
     return(coll.contains(value));
 }
 /**
  * Gets an iterator for the collection mapped to the specified key.
  *
  * @param key  the key to get an iterator for
  * @return the iterator of the collection at the key, empty iterator if key not in map
  * @since Commons Collections 3.1
  */
 public virtual java.util.Iterator <Object> iterator(Object key)
 {
     java.util.Collection <Object> coll = getCollection(key);
     if (coll == null)
     {
         return(EmptyIterator.INSTANCE);
     }
     return(coll.iterator());
 }
 /**
  * Constructor that wraps a collection.
  * <p>
  * There is no way to reset an Iterator instance without recreating it from
  * the original source, so the Collection must be passed in.
  *
  * @param coll  the collection to wrap
  * @throws NullPointerException if the collection is null
  */
 public LoopingIterator(java.util.Collection<Object> coll)
 {
     if (coll == null)
     {
         throw new java.lang.NullPointerException("The collection must not be null");
     }
     collection = coll;
     reset();
 }