Beispiel #1
0
 /// <summary>
 /// True, if list is equal to this
 /// </summary>
 /// <param name="list">list</param>
 /// <returns>True, if instance euqals list</returns>
 public Boolean Equals(EquatableList<T> list)
 {
     if (list == null) return false;
     foreach (T t in this) if (!list.Contains(t)) return false;
     foreach (T t in list) if (!this.Contains(t)) return false;
     return true;
 }
Beispiel #2
0
 /// <summary>Returns a hash code value for this object. </summary>
 public override int GetHashCode()
 {
     // TODO in Java 1.5: switch to Arrays.hashCode().  The
     // Java 1.4 workaround below calculates the same hashCode
     // as Java 1.5's new Arrays.hashCode()
     return(0x45aaf665 + EquatableList <SortField> .GetHashCode(fields));
 }
Beispiel #3
0
        //public SpeciesType Type { get; set; }

        public NodeModel()
        {
            ScientificName = "";
            TaxonRank      = TaxonRank.Species;
            Interactions   = new EquatableList <InteractionModel>();
            LifeCycles     = new List <List <TimePeriodModel> >();
        }
Beispiel #4
0
/// <summary>
/// True, if list is equal to this
/// </summary>
/// <param name="list">list</param>
/// <returns>True, if instance equals list</returns>
public Boolean Equals(EquatableList <T> list)
{
    if (list == null)
    {
        return(false);
    }
    return(this.All(list.Contains) && list.All(this.Contains));
}
Beispiel #5
0
 /// <summary>
 /// Construct a <see cref="SpanOrQuery"/> merging the provided <paramref name="clauses"/>. </summary>
 public SpanOrQuery(params SpanQuery[] clauses)
 {
     // copy clauses array into an ArrayList
     this.clauses = new EquatableList <SpanQuery>(clauses.Length);
     for (int i = 0; i < clauses.Length; i++)
     {
         AddClause(clauses[i]);
     }
 }
Beispiel #6
0
 // LUCENENET specific overload.
 // LUCENENET TODO: API - This constructor was added to eliminate casting with PayloadSpanUtil. Make public?
 // It would be more useful if the type was an IEnumerable<SpanQuery>, but
 // need to rework the allocation below. It would also be better to change AddClause() to Add() to make
 // the C# collection initializer function.
 internal SpanOrQuery(IList <SpanQuery> clauses)
 {
     // copy clauses array into an ArrayList
     this.clauses = new EquatableList <SpanQuery>(clauses.Count);
     for (int i = 0; i < clauses.Count; i++)
     {
         AddClause(clauses[i]);
     }
 }
Beispiel #7
0
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="name">关键字</param>
        /// <returns>Id集合</returns>
        public List <string> SearchHotel(string name)
        {
            List <QueryParameter> paras = new EquatableList <QueryParameter>
            {
                new QueryParameter
                {
                    ParameterName  = "keyword",
                    ParameterValue = name
                }
            };

            return(SearchHotel(paras));
        }
        public void Suitable_For_Determining_Uniqueness_In_Hashtable()
        {
            var foo = new Object();
            var bar = new Object();

            var list1 = new EquatableList<Object> { foo, bar };
            var list2 = new EquatableList<Object> { foo, bar };

            var hashTable = new Hashtable();

            Assert.IsFalse(hashTable.ContainsKey(list1));
            hashTable.Add(list1, list1);

            Assert.IsTrue(hashTable.ContainsKey(list2));
        }
        public void Suitable_For_Determining_Uniqueness_In_HashSet()
        {
            var foo = new Object();
            var bar = new Object();

            var list1 = new EquatableList<Object> {foo, bar};
            var list2 = new EquatableList<Object> {foo, bar};

            Assert.AreEqual(list1, list2);

            var hashSet = new HashSet<List<Object>>();

            Assert.IsTrue(hashSet.Add(list1));
            Assert.IsFalse(hashSet.Add(list2));
        }
Beispiel #10
0
 /// <summary>Construct a SpanOrQuery merging the provided clauses. </summary>
 public SpanOrQuery(params SpanQuery[] clauses)
 {
     // copy clauses array into an ArrayList
     this.clauses = new EquatableList <SpanQuery>(clauses.Length);
     for (int i = 0; i < clauses.Length; i++)
     {
         SpanQuery clause = clauses[i];
         if (i == 0)
         {
             // check field
             field = clause.Field;
         }
         else if (!clause.Field.Equals(field))
         {
             throw new System.ArgumentException("Clauses must have same field.");
         }
         this.clauses.Add(clause);
     }
 }
        /// <summary>
        /// This method exists in order to avoid recursive calls to the method
        /// as the complexity of a fairly small matrix then easily would require
        /// a gigabyte sized stack per thread.
        /// </summary>
        /// <param name="reusableToken"></param>
        /// <returns>null if exhausted, instance request_next_token if one more call is required for an answer, 
        /// or instance parameter resuableToken.</returns>
        private Token ProduceNextToken(Token reusableToken)
        {
            if (_currentPermuationTokens != null)
            {
                _currentShingleLength++;

                if (_currentShingleLength + _currentPermutationTokensStartOffset <= _currentPermuationTokens.Count
                    && _currentShingleLength <= MaximumShingleSize)
                {
                    // it is possible to create at least one more shingle of the current matrix permutation

                    if (IsIgnoringSinglePrefixOrSuffixShingle && 
                        _currentShingleLength == 1 && 
                        (_currentPermutationRows[_currentPermutationTokensStartOffset].Column.IsFirst || _currentPermutationRows[_currentPermutationTokensStartOffset].Column.IsLast))
                    {
                        return Next();
                    }

                    var termLength = 0;

                    var shingle = new EquatableList<Token>();

                    for (int i = 0; i < _currentShingleLength; i++)
                    {
                        var shingleToken = _currentPermuationTokens[i + _currentPermutationTokensStartOffset];
                        termLength += shingleToken.TermLength();
                        shingle.Add(shingleToken);
                    }
                    if (SpacerCharacter != null)
                        termLength += _currentShingleLength - 1;

                    // only produce shingles that not already has been created
                    if (!_shinglesSeen.Add(shingle))
                        return _requestNextToken;

                    // shingle token factory
                    var sb = new StringBuilder(termLength + 10); // paranormal ability to foresee the future. ;)
                    foreach (var shingleToken in shingle)
                    {
                        if (SpacerCharacter != null &&  sb.Length > 0)
                            sb.Append(SpacerCharacter);

                        sb.Append(shingleToken.TermBuffer(), 0, shingleToken.TermLength());
                    }

                    reusableToken.SetTermBuffer(sb.ToString());
                    UpdateToken(reusableToken, shingle, _currentPermutationTokensStartOffset, _currentPermutationRows,
                                _currentPermuationTokens);

                    return reusableToken;
                }

                // it is NOT possible to create one more shingles of the current matrix permutation
                if (_currentPermutationTokensStartOffset < _currentPermuationTokens.Count - 1)
                {
                    // reset shingle size and move one step to the right in the current tokens permutation
                    _currentPermutationTokensStartOffset++;
                    _currentShingleLength = MinimumShingleSize - 1;
                    return _requestNextToken;
                }


                // todo does this ever occur?
                if (_permutations == null)
                    return null;

                if (!_permutations.HasNext())
                {
                    // load more data (if available) to the matrix

                    // don't really care, we just read it.
                    if (_input != null)
                        ReadColumn();

                    // get rid of resources

                    // delete the first column in the matrix
                    var deletedColumn = Matrix.Columns[0];
                    Matrix.Columns.RemoveAt(0);

                    // remove all shingles seen that include any of the tokens from the deleted column.
                    var deletedColumnTokens = deletedColumn.Rows.SelectMany(row => row.Tokens).ToList();
                    
                    // I'm a little concerned about this part of the code, because the unit tests currently 
                    // don't cover this scenario. (I put a break point here, and ran the unit tests in debug mode 
                    // and this code block was never hit... I also changed it significatly from the Java version
                    // to use RemoveWhere and LINQ. 
                    //
                    // TODO: Write a unit test to cover this and make sure this is a good port! -thoward

                    // linq version
                    _shinglesSeen.RemoveWhere(
                        shingle => (shingle.Find(deletedColumnTokens.Contains) != default(Token)));

                    //// initial conversion
                    //var shinglesSeenIterator = _shinglesSeen.ToList();
                    //foreach (var shingle in shinglesSeenIterator)
                    //{
                    //    foreach (var deletedColumnToken in deletedColumnTokens)
                    //    {
                    //        if (shingle.Contains(deletedColumnToken))
                    //        {
                    //            _shinglesSeen.Remove(shingle);
                    //            break;
                    //        }
                    //    }
                    //}

                    // exhausted
                    if (Matrix.Columns.Count < MinimumShingleSize)
                        return null;

                    // create permutations of the matrix it now looks
                    _permutations = Matrix.PermutationIterator();
                }

                NextTokensPermutation();
                return _requestNextToken;
            }

            if (_permutations == null)
                _permutations = Matrix.PermutationIterator();

            if (!_permutations.HasNext())
                return null;

            NextTokensPermutation();

            return _requestNextToken;
        }
Beispiel #12
0
        /// <summary>
        /// This method exists in order to avoid recursive calls to the method
        /// as the complexity of a fairly small matrix then easily would require
        /// a gigabyte sized stack per thread.
        /// </summary>
        /// <param name="reusableToken"></param>
        /// <returns>null if exhausted, instance request_next_token if one more call is required for an answer,
        /// or instance parameter resuableToken.</returns>
        private Token ProduceNextToken(Token reusableToken)
        {
            if (_currentPermuationTokens != null)
            {
                _currentShingleLength++;

                if (_currentShingleLength + _currentPermutationTokensStartOffset <= _currentPermuationTokens.Count &&
                    _currentShingleLength <= MaximumShingleSize)
                {
                    // it is possible to create at least one more shingle of the current matrix permutation

                    if (IsIgnoringSinglePrefixOrSuffixShingle &&
                        _currentShingleLength == 1 &&
                        (_currentPermutationRows[_currentPermutationTokensStartOffset].Column.IsFirst || _currentPermutationRows[_currentPermutationTokensStartOffset].Column.IsLast))
                    {
                        return(GetNextToken(reusableToken));
                    }

                    var termLength = 0;

                    var shingle = new EquatableList <Token>();

                    for (int i = 0; i < _currentShingleLength; i++)
                    {
                        var shingleToken = _currentPermuationTokens[i + _currentPermutationTokensStartOffset];
                        termLength += shingleToken.TermLength();
                        shingle.Add(shingleToken);
                    }
                    if (SpacerCharacter != null)
                    {
                        termLength += _currentShingleLength - 1;
                    }

                    // only produce shingles that not already has been created
                    if (!_shinglesSeen.Add(shingle))
                    {
                        return(_requestNextToken);
                    }

                    // shingle token factory
                    var sb = new StringBuilder(termLength + 10); // paranormal ability to foresee the future. ;)
                    foreach (var shingleToken in shingle)
                    {
                        if (SpacerCharacter != null && sb.Length > 0)
                        {
                            sb.Append(SpacerCharacter);
                        }

                        sb.Append(shingleToken.TermBuffer(), 0, shingleToken.TermLength());
                    }

                    reusableToken.SetTermBuffer(sb.ToString());
                    UpdateToken(reusableToken, shingle, _currentPermutationTokensStartOffset, _currentPermutationRows,
                                _currentPermuationTokens);

                    return(reusableToken);
                }

                // it is NOT possible to create one more shingles of the current matrix permutation
                if (_currentPermutationTokensStartOffset < _currentPermuationTokens.Count - 1)
                {
                    // reset shingle size and move one step to the right in the current tokens permutation
                    _currentPermutationTokensStartOffset++;
                    _currentShingleLength = MinimumShingleSize - 1;
                    return(_requestNextToken);
                }


                // todo does this ever occur?
                if (_permutations == null)
                {
                    return(null);
                }

                if (!_permutations.HasNext())
                {
                    // load more data (if available) to the matrix

                    // don't really care, we just read it.
                    if (_input != null)
                    {
                        ReadColumn();
                    }

                    // get rid of resources

                    // delete the first column in the matrix
                    var deletedColumn = Matrix.Columns[0];
                    Matrix.Columns.RemoveAt(0);

                    // remove all shingles seen that include any of the tokens from the deleted column.
                    var deletedColumnTokens = deletedColumn.Rows.SelectMany(row => row.Tokens).ToList();

                    // I'm a little concerned about this part of the code, because the unit tests currently
                    // don't cover this scenario. (I put a break point here, and ran the unit tests in debug mode
                    // and this code block was never hit... I also changed it significatly from the Java version
                    // to use RemoveWhere and LINQ.
                    //
                    // TODO: Write a unit test to cover this and make sure this is a good port! -thoward

                    // linq version
                    _shinglesSeen.RemoveWhere(
                        shingle => (shingle.Find(deletedColumnTokens.Contains) != default(Token)));

                    //// initial conversion
                    //var shinglesSeenIterator = _shinglesSeen.ToList();
                    //foreach (var shingle in shinglesSeenIterator)
                    //{
                    //    foreach (var deletedColumnToken in deletedColumnTokens)
                    //    {
                    //        if (shingle.Contains(deletedColumnToken))
                    //        {
                    //            _shinglesSeen.Remove(shingle);
                    //            break;
                    //        }
                    //    }
                    //}

                    // exhausted
                    if (Matrix.Columns.Count < MinimumShingleSize)
                    {
                        return(null);
                    }

                    // create permutations of the matrix it now looks
                    _permutations = Matrix.PermutationIterator();
                }

                NextTokensPermutation();
                return(_requestNextToken);
            }

            if (_permutations == null)
            {
                _permutations = Matrix.PermutationIterator();
            }

            if (!_permutations.HasNext())
            {
                return(null);
            }

            NextTokensPermutation();

            return(_requestNextToken);
        }