/// <summary>
        /// <para>
        /// Creates a new <see cref="MonotonicVersioner"/> instance with
        /// the specified initial compatibility line and metadata.
        /// </para>
        /// </summary>
        /// <param name="startAtOne">
        /// If true, the produced <see cref="Compatibility"/> number
        /// sequence starts at one. If false, zero.
        /// </param>
        /// <param name="metadata">
        /// Any metadata items to be included as part of the
        /// initial version number.
        /// </param>
        /// <remarks>
        /// <para>
        /// The Monotonic Versioning Manifesto 1.2 does not specify
        /// whether the <see cref="Compatibility"/> component of versions
        /// are to start at one or zero. It is assumed that either is valid
        /// as neither is specifically recommended nor prohibited.
        /// </para>
        /// </remarks>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="metadata"/> or an item thereof is null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// One or more of the items in <paramref name="metadata"/> is not
        /// a valid metadata item.
        /// </exception>
        public MonotonicVersioner(bool startAtOne, IEnumerable <string> metadata)
        {
            _verifyMetadataColl(metadata);

            _latest = new SemanticVersion(
                major:          startAtOne ? 1 : 0,
                minor:          0,
                patch:          0,
                identifiers:    Enumerable.Empty <string>(),
                metadata:       metadata
                );

            _latestVers = new Dictionary <int, SemanticVersion>
            {
                { _latest.Major, _latest }
            };

            _chronology = new List <SemanticVersion>()
            {
                _latest
            };

            this.LatestVersions = _latestVers.AsReadOnly();
            this.Chronology     = _chronology.AsReadOnly();
        }
        private ParameterService GetService(string[] commandLineArguments = null, IDictionary <string, string> environmentVariables = null)
        {
            commandLineArguments = commandLineArguments ?? new string[0];
            environmentVariables = environmentVariables ?? new Dictionary <string, string>();

            return(new ParameterService(commandLineArguments, environmentVariables.AsReadOnly()));
        }
        public void AsReadOnly()
        {
            // Act
            var result = _TestDictionary.AsReadOnly();

            // Assert
            result.Should().NotBeNull();
            result.GetType().DeclaringType.Should().Be(typeof(DictionaryExtensions));
            result.GetType().Name.Should().Be("ReadOnlyDictionary`2");
        }
        public static IDictionary <ShapeInfo, IDictionary <object, object> > ToReadOnlyMap(IEnumerable <TupleStruct <ShapeInfo, object, object> > shapePropertyValues)
        {
            IDictionary <ShapeInfo, IDictionary <object, object> > dictionary = ToMap(shapePropertyValues);

            foreach (ShapeInfo info in dictionary.Keys.ToArrayEx <ShapeInfo>())
            {
                IDictionary <object, object> dictionary3 = dictionary[info].AsReadOnly <object, object>();
                dictionary[info] = dictionary3;
            }
            return(dictionary.AsReadOnly <ShapeInfo, IDictionary <object, object> >());
        }
 public DerivedComposablePartDefinition(
     IDictionary<string, object> metadata,
     Func<ComposablePart> partCreator,
     Func<IEnumerable<ImportDefinition>> importsCreator,
     Func<IEnumerable<ExportDefinition>> exportsCreator)
 {
     this._metadata = metadata.AsReadOnly();
     this._partCreator = partCreator;
     this._importsCreator = importsCreator;
     this._exportsCreator = exportsCreator;
 }
        /// <summary>
        ///     Initializes a new instance of the <see cref="ExportDefinition"/> class with 
        ///     the specified contract name and metadata.
        /// </summary>
        /// <param name="contractName">
        ///     A <see cref="String"/> containing the contract name of the 
        ///     <see cref="ExportDefinition"/>.
        /// </param>
        /// <param name="metadata">
        ///     An <see cref="IDictionary{TKey, TValue}"/> containing the metadata of the 
        ///     <see cref="ExportDefinition"/>; or <see langword="null"/> to set the 
        ///     <see cref="Metadata"/> property to an empty, read-only 
        ///     <see cref="IDictionary{TKey, TValue}"/>.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="contractName"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentException">
        ///     <paramref name="contractName"/> is an empty string ("").
        /// </exception>
        public ExportDefinition(string contractName, IDictionary<string, object> metadata)
        {
            Requires.NotNullOrEmpty(contractName, "contractName");

            _contractName = contractName;

            if (metadata != null)
            {
                _metadata = metadata.AsReadOnly();
            }
        }
Beispiel #7
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="ExportDefinition"/> class with
        ///     the specified contract name and metadata.
        /// </summary>
        /// <param name="contractName">
        ///     A <see cref="String"/> containing the contract name of the
        ///     <see cref="ExportDefinition"/>.
        /// </param>
        /// <param name="metadata">
        ///     An <see cref="IDictionary{TKey, TValue}"/> containing the metadata of the
        ///     <see cref="ExportDefinition"/>; or <see langword="null"/> to set the
        ///     <see cref="Metadata"/> property to an empty, read-only
        ///     <see cref="IDictionary{TKey, TValue}"/>.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="contractName"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentException">
        ///     <paramref name="contractName"/> is an empty string ("").
        /// </exception>
        public ExportDefinition(string contractName, IDictionary <string, object> metadata)
        {
            Requires.NotNullOrEmpty(contractName, nameof(contractName));

            _contractName = contractName;

            if (metadata != null)
            {
                _metadata = metadata.AsReadOnly();
            }
        }
        public ImapNamespaceDesc(string prefix, string hierarchyDelimiter, IDictionary<string, string[]> extensions)
        {
            if (prefix == null)
            throw new ArgumentNullException("prefix");
              if (extensions == null)
            throw new ArgumentNullException("extensions");

              this.Prefix = prefix;
              this.HierarchyDelimiter = hierarchyDelimiter;
              this.Extensions = extensions.AsReadOnly();
        }
Beispiel #9
0
 public DerivedComposablePartDefinition(
     IDictionary <string, object> metadata,
     Func <ComposablePart> partCreator,
     Func <IEnumerable <ImportDefinition> > importsCreator,
     Func <IEnumerable <ExportDefinition> > exportsCreator)
 {
     this._metadata       = metadata.AsReadOnly();
     this._partCreator    = partCreator;
     this._importsCreator = importsCreator;
     this._exportsCreator = exportsCreator;
 }
Beispiel #10
0
 public ExtraPropertyInfo(ExtraPropertyId id, IDictionary <string, string> descriptions)
 {
     if (id == null)
     {
         throw new ArgumentNullException();
     }
     if (descriptions == null)
     {
         throw new ArgumentNullException();
     }
     PropertyId   = id;
     Descriptions = descriptions.AsReadOnly();
 }
        /// <summary>
        /// Initialize this factory via a set of key-value pairs.
        /// </summary>
        protected AbstractAnalysisFactory(IDictionary <string, string> args)
        {
            IsExplicitLuceneMatchVersion = false;
            originalArgs = args.AsReadOnly();
            string version = Get(args, LUCENE_MATCH_VERSION_PARAM);

            // LUCENENET TODO: What should we do if the version is null?
            //luceneMatchVersion = version is null ? (LuceneVersion?)null : LuceneVersionHelpers.ParseLeniently(version);
            m_luceneMatchVersion = version is null ?
#pragma warning disable 612, 618
                                   LuceneVersion.LUCENE_CURRENT :
#pragma warning restore 612, 618
                                   LuceneVersionExtensions.ParseLeniently(version);
            args.Remove(CLASS_NAME); // consume the class arg
        }
        public FakeViewRow(IDictionary<string, object> info)
        {
            if (!info.TryGetValue("id", out _id))
            {
                _id = null;
            }

            object tempKey;
            if (!info.TryGetValue("key", out tempKey))
            {
                throw new InvalidOperationException("The value 'key' was not found in the info definition.");
            }

            _key = (tempKey as object[]) ?? (new[] { tempKey });
            _info = info.AsReadOnly();
        }
Beispiel #13
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="PerftResult"/> class.
        /// </summary>
        internal PerftResult(
            PerftFlags flags,
            int depth,
            TimeSpan elapsed,
            ulong nodeCount,
            ulong captureCount,
            ulong enPassantCaptureCount,
            IDictionary <GameMove, ulong> dividedMoves,
            ulong?checkCount,
            ulong?checkmateCount)
        {
            if (depth < 0)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(depth),
                          depth,
                          @"The value cannot be negative.");
            }

            if (elapsed < TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(elapsed),
                          elapsed,
                          @"The value cannot be negative.");
            }

            if (dividedMoves is null)
            {
                throw new ArgumentNullException(nameof(dividedMoves));
            }

            Flags                 = flags;
            Depth                 = depth;
            Elapsed               = elapsed;
            NodeCount             = nodeCount;
            CaptureCount          = captureCount;
            EnPassantCaptureCount = enPassantCaptureCount;
            DividedMoves          = dividedMoves.AsReadOnly();
            CheckCount            = checkCount;
            CheckmateCount        = checkmateCount;

            var totalSeconds = elapsed.TotalSeconds;

            NodesPerSecond = checked ((ulong)(totalSeconds.IsZero() ? 0 : nodeCount / totalSeconds));
        }
        public FakeViewRow(IDictionary <string, object> info)
        {
            if (!info.TryGetValue("id", out _id))
            {
                _id = null;
            }

            object tempKey;

            if (!info.TryGetValue("key", out tempKey))
            {
                throw new InvalidOperationException("The value 'key' was not found in the info definition.");
            }

            _key  = (tempKey as object[]) ?? (new[] { tempKey });
            _info = info.AsReadOnly();
        }
Beispiel #15
0
        private static void GetDisallowedEntries(XmlNode node, int numSections, out IList <IList <int> > disallowed, out IList <IDictionary <int, string> > staticEntries)
        {
            IList <IList <int> > result = new IList <int> [numSections];
            IList <IDictionary <int, string> > ourStatic = new IDictionary <int, string> [numSections];
            XmlNode disallowedNode = node.SelectSingleNode("DisallowedEntries");

            if (disallowedNode != null)
            {
                foreach (XmlNode node2 in disallowedNode.SelectNodes("Section"))
                {
                    int        sec                   = Int32.Parse(node2.Attributes["value"].InnerText);
                    List <int> ourResult             = new List <int>();
                    Dictionary <int, string> ourDict = new Dictionary <int, string>();
                    foreach (XmlNode ent in node2.SelectNodes("entry"))
                    {
                        int idx = Int32.Parse(ent.InnerText);
                        ourResult.Add(idx);
                        XmlAttribute stat = ent.Attributes["staticValue"];
                        if (stat != null)
                        {
                            ourDict[idx] = stat.InnerText;
                        }
                        else
                        {
                            ourDict[idx] = string.Empty;
                        }
                    }
                    result[sec]    = ourResult.AsReadOnly();
                    ourStatic[sec] = new ReadOnlyDictionary <int, string>(ourDict);
                }
            }
            for (int i = 0; i < result.Count; i++)
            {
                if (result[i] == null)
                {
                    result[i] = new int[0].AsReadOnly();
                }
                if (ourStatic[i] == null)
                {
                    ourStatic[i] = new ReadOnlyDictionary <int, string>(new Dictionary <int, string>(0));
                }
            }

            disallowed    = result.AsReadOnly();
            staticEntries = ourStatic.AsReadOnly();
        }
            public __Row(CouchbaseView owner, IDictionary<string, object> row)
            {
                this.owner = owner;

                if (row == null) throw new ArgumentNullException("row", "Missing row info");

                if (!row.TryGetValue("id", out this.id))
                    this.id = null; //this is the case when the row is from a reduced view

                object tempKey;

                if (!row.TryGetValue("key", out tempKey))
                    throw new InvalidOperationException("The value 'key' was not found in the row definition.");

                this.key = (tempKey as object[]) ?? (new object[] { tempKey });
                this.info = row.AsReadOnly();
            }
Beispiel #17
0
        public static Bug FromJsonObject(IDictionary <string, object> jsonObject)
        {
            jsonObject = jsonObject.WrapInMissingKeySafeDictionary();
            var bug = new Bug();

            try {
                bug.AssignedTo     = (string)jsonObject["assigned_to"];
                bug.BlocksOn       = ((JsonArray)jsonObject["blocks"]).Cast <long> ().ToArray();
                bug.Classification = (string)jsonObject["classification"];
                bug.Component      = (string)jsonObject["component"];
                bug.Creator        = (string)jsonObject["creator"];
                bug.DependsOn      = ((JsonArray)jsonObject["depends_on"]).Cast <long> ().ToArray();
                bug.DuplicateOf    = (long?)jsonObject["duplicate_of"];
                bug.Groups         = ((JsonArray)jsonObject["groups"]).Cast <string> ().ToArray();
                bug.Id             = (long)jsonObject["id"];
                bug.Keywords       = ((JsonArray)jsonObject["keywords"]).Cast <string> ().ToArray();
                bug.LastChanged    = DateTime.SpecifyKind(DateTime.Parse((string)jsonObject["last_change_time"]), DateTimeKind.Utc);
                bug.Milestone      = (string)jsonObject["target_milestone"];
                bug.Priority       = (string)jsonObject["priority"];
                bug.Product        = (string)jsonObject["product"];
                bug.Resolution     = (string)jsonObject["resolution"];
                bug.SeeAlso        = ((JsonArray)jsonObject["see_also"]).Cast <string> ().ToArray();
                bug.Severity       = (string)jsonObject["severity"];
                bug.Status         = (string)jsonObject["status"];
                bug.Subscribers    = ((JsonArray)jsonObject["cc"]).Cast <string> ().ToArray();
                bug.Summary        = (string)jsonObject["summary"];
                bug.Version        = (string)jsonObject["version"];
                bug.Attributes     = jsonObject.AsReadOnly();
            } catch (Exception e) {
                                #if DEBUG
                Console.Error.WriteLine(jsonObject.ToString());
                                #endif
                Console.WriteLine("Failed to parse bug from JSON: {0}", e.Message);
            }
            return(bug);
        }
Beispiel #18
0
        public override FieldInfos Read(Directory directory, string segmentName, string segmentSuffix, IOContext iocontext)
        {
            string     fileName = IndexFileNames.SegmentFileName(segmentName, "", Lucene42FieldInfosFormat.EXTENSION);
            IndexInput input    = directory.OpenInput(fileName, iocontext);

            bool success = false;

            try
            {
                CodecUtil.CheckHeader(input, Lucene42FieldInfosFormat.CODEC_NAME,
                                      Lucene42FieldInfosFormat.FORMAT_START,
                                      Lucene42FieldInfosFormat.FORMAT_CURRENT);

                int         size  = input.ReadVInt32(); //read in the size
                FieldInfo[] infos = new FieldInfo[size];

                for (int i = 0; i < size; i++)
                {
                    string       name            = input.ReadString();
                    int          fieldNumber     = input.ReadVInt32();
                    sbyte        bits            = (sbyte)input.ReadByte();
                    bool         isIndexed       = (bits & Lucene42FieldInfosFormat.IS_INDEXED) != 0;
                    bool         storeTermVector = (bits & Lucene42FieldInfosFormat.STORE_TERMVECTOR) != 0;
                    bool         omitNorms       = (bits & Lucene42FieldInfosFormat.OMIT_NORMS) != 0;
                    bool         storePayloads   = (bits & Lucene42FieldInfosFormat.STORE_PAYLOADS) != 0;
                    IndexOptions indexOptions;
                    if (!isIndexed)
                    {
                        indexOptions = IndexOptions.NONE;
                    }
                    else if ((bits & Lucene42FieldInfosFormat.OMIT_TERM_FREQ_AND_POSITIONS) != 0)
                    {
                        indexOptions = IndexOptions.DOCS_ONLY;
                    }
                    else if ((bits & Lucene42FieldInfosFormat.OMIT_POSITIONS) != 0)
                    {
                        indexOptions = IndexOptions.DOCS_AND_FREQS;
                    }
                    else if ((bits & Lucene42FieldInfosFormat.STORE_OFFSETS_IN_POSTINGS) != 0)
                    {
                        indexOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS;
                    }
                    else
                    {
                        indexOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;
                    }

                    // DV Types are packed in one byte
                    sbyte         val                       = (sbyte)input.ReadByte();
                    DocValuesType docValuesType             = GetDocValuesType(input, (byte)(val & 0x0F));
                    DocValuesType normsType                 = GetDocValuesType(input, (byte)((val.TripleShift(4)) & 0x0F));
                    IDictionary <string, string> attributes = input.ReadStringStringMap();
                    infos[i] = new FieldInfo(name, isIndexed, fieldNumber, storeTermVector,
                                             omitNorms, storePayloads, indexOptions, docValuesType, normsType, attributes.AsReadOnly());
                }

                CodecUtil.CheckEOF(input);
                FieldInfos fieldInfos = new FieldInfos(infos);
                success = true;
                return(fieldInfos);
            }
            finally
            {
                if (success)
                {
                    input.Dispose();
                }
                else
                {
                    IOUtils.DisposeWhileHandlingException(input);
                }
            }
        }
        public void AsReadOnly()
        {
            ReadOnlyDictionary <string, string> readOnlyDictionary = _dictionary.AsReadOnly();

            Assert.That(readOnlyDictionary, Is.EqualTo(_dictionary));
        }
Beispiel #20
0
        private static void GetDisallowedEntries( XmlNode node, int numSections, out IList<IList<int>> disallowed, out IList<IDictionary<int,string>> staticEntries )
        {
            IList<IList<int>> result = new IList<int>[numSections];
            IList<IDictionary<int, string>> ourStatic = new IDictionary<int, string>[numSections];
            XmlNode disallowedNode = node.SelectSingleNode( "DisallowedEntries" );
            if ( disallowedNode != null )
            {
                foreach ( XmlNode node2 in disallowedNode.SelectNodes( "Section" ) )
                {
                    int sec = Int32.Parse( node2.Attributes["value"].InnerText );
                    List<int> ourResult = new List<int>();
                    Dictionary<int, string> ourDict = new Dictionary<int, string>();
                    foreach ( XmlNode ent in node2.SelectNodes( "entry" ) )
                    {
                        int idx = Int32.Parse(ent.InnerText);
                        ourResult.Add( idx);
                        XmlAttribute stat = ent.Attributes["staticValue"];
                        if ( stat != null )
                        {
                            ourDict[idx] = stat.InnerText;
                        }
                        else
                        {
                            ourDict[idx] = string.Empty;
                        }
                    }
                    result[sec] = ourResult.AsReadOnly();
                    ourStatic[sec] = new ReadOnlyDictionary<int, string>( ourDict );
                }
            }
            for ( int i = 0; i < result.Count; i++ )
            {
                if ( result[i] == null )
                {
                    result[i] = new int[0].AsReadOnly();
                }
                if ( ourStatic[i] == null )
                {
                    ourStatic[i] = new ReadOnlyDictionary<int, string>( new Dictionary<int, string>( 0 ) );
                }
            }

            disallowed = result.AsReadOnly();
            staticEntries = ourStatic.AsReadOnly();
        }
        /// <summary>
        /// <para>
        /// Creates a new <see cref="MonotonicVersioner"/> with the
        /// specified version number history.
        /// </para>
        /// </summary>
        /// <param name="chronology">
        /// A collection of version numbers providing the version
        /// history to use for this instance.
        /// </param>
        /// <remarks>
        /// <paramref name="chronology"/> is not required to be
        /// in order.
        /// </remarks>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="chronology"/> or an item thereof is null.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <paramref name="chronology"/> contains a version which is
        /// not a valid monotonic version.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// <para>
        /// <paramref name="chronology"/> provides an incomplete
        /// version history. The chronology may:
        /// </para>
        /// <list type="bullet">
        ///     <item>
        ///     <description>
        ///     Not provide a contiguous sequence of <see cref="Compatibility"/>
        ///     numbers;
        ///     </description>
        ///     </item>
        ///     <item>
        ///     <description>
        ///     Not provide a contiguous sequence of <see cref="Release"/>
        ///     numbers;
        ///     </description>
        ///     </item>
        ///     <item>
        ///     <description>
        ///     Not contain a <see cref="Compatibility"/> starting at either
        ///     zero or one; or
        ///     </description>
        ///     </item>
        ///     <item>
        ///     <description>
        ///     Be empty.
        ///     </description>
        ///     </item>
        /// </list>
        /// </exception>
        public MonotonicVersioner(IEnumerable <SemanticVersion> chronology)
        {
            if (chronology == null)
            {
                throw new ArgumentNullException(
                          message:    "The specified chronology cannot be null.",
                          paramName:  nameof(chronology)
                          );
            }

            if (chronology.Contains(null))
            {
                throw new ArgumentNullException(
                          message:    "The specified chronology cannot contain a " +
                          "null version.",
                          paramName:  nameof(chronology)
                          );
            }

            if (!chronology.All(MonotonicExtensions.IsMonotonic))
            {
                throw new ArgumentOutOfRangeException(
                          message:    "The specified chronology contains a version " +
                          "that is not a valid monotonic version.",
                          paramName:  nameof(chronology)
                          );
            }

            if (!chronology.Any())
            {
                throw new ArgumentException(
                          message:    "The specified chronology is empty.",
                          paramName:  nameof(chronology)
                          );
            }

            // Order the versions we've provided by release number.
            var orderedChron = chronology.OrderBy(v => v.Minor);

            // Is the set of lines of compatibility without gaps?
            var linesOfCompat = orderedChron.Select(v => v.Major).Distinct();

            if (!_isOrderedCtgsIntSeq(linesOfCompat))
            {
                throw new ArgumentException(
                          message:    "The specified chronology does not provide " +
                          "a contiguous set of lines of compatibility.",
                          paramName:  nameof(chronology)
                          );
            }

            // Is the set of release numbers ordered without any gaps.
            if (!_isOrderedCtgsIntSeq(orderedChron.Select(v => v.Minor)))
            {
                throw new ArgumentException(
                          message:    "The specified chronology does not provide " +
                          "a contiguous sequence of release numbers.",
                          paramName:  nameof(chronology)
                          );
            }

            // Is the first line of compatibility a value other than 0 or 1?
            if (orderedChron.First().Major >= 2)
            {
                throw new ArgumentException(
                          message:    "The set of lines of compatibility in the " +
                          "specified chronology does not start at " +
                          $"one or zero ({chronology.First().Major}).",
                          paramName:  nameof(chronology)
                          );
            }

            _latest = orderedChron.Last();

            _latestVers = new Dictionary <int, SemanticVersion>();
            foreach (var line in linesOfCompat)
            {
                _latestVers[line] = orderedChron.Where(v => v.Major == line)
                                    .Last();
            }

            _chronology = new List <SemanticVersion>(orderedChron);

            this.LatestVersions = _latestVers.AsReadOnly();
            this.Chronology     = _chronology.AsReadOnly();
        }
Beispiel #22
0
 private TermExpression(TermExpression original, IEnumerable<TermExpression> terms,
                        IDictionary<TermExpression, TermExpression> dictTerms)
 {
     _function = original.Function;
     _termType = original._termType;
     _type = original.Type;
     _value = original.Value;
     _terms = terms.AsReadOnly();
     _dictionaryTerms = dictTerms.AsReadOnly();
 }
Beispiel #23
0
        public static ReadOnlyDictionary <TKey, TSource> ToReadOnlyDictionary <TSource, TKey>(this IEnumerable <TSource> source, Func <TSource, TKey> keySelector)
        {
            IDictionary <TKey, TSource> dict = source.ToDictionary(keySelector);

            return(dict.AsReadOnly());
        }
Beispiel #24
0
        public static Bug FromJsonObject(IDictionary<string, object> jsonObject)
        {
            jsonObject = jsonObject.WrapInMissingKeySafeDictionary ();
            var bug = new Bug ();

            try {
                bug.AssignedTo = (string) jsonObject["assigned_to"];
                bug.BlocksOn = ((JsonArray) jsonObject["blocks"]).Cast<long> ().ToArray ();
                bug.Classification = (string) jsonObject["classification"];
                bug.Component = (string) jsonObject["component"];
                bug.Creator = (string) jsonObject["creator"];
                bug.DependsOn = ((JsonArray) jsonObject["depends_on"]).Cast<long> ().ToArray ();
                bug.DuplicateOf = (long?) jsonObject["duplicate_of"];
                bug.Groups = ((JsonArray) jsonObject["groups"]).Cast<string> ().ToArray ();
                bug.Id = (long) jsonObject["id"];
                bug.Keywords = ((JsonArray) jsonObject["keywords"]).Cast<string> ().ToArray ();
                bug.LastChanged = DateTime.SpecifyKind (DateTime.Parse ((string) jsonObject["last_change_time"]), DateTimeKind.Utc);
                bug.Milestone = (string) jsonObject["target_milestone"];
                bug.Priority = (string) jsonObject["priority"];
                bug.Product = (string) jsonObject["product"];
                bug.Resolution = (string) jsonObject["resolution"];
                bug.SeeAlso = ((JsonArray) jsonObject["see_also"]).Cast<string> ().ToArray ();
                bug.Severity = (string) jsonObject["severity"];
                bug.Status = (string) jsonObject["status"];
                bug.Subscribers = ((JsonArray) jsonObject["cc"]).Cast<string> ().ToArray ();
                bug.Summary = (string) jsonObject["summary"];
                bug.Version = (string) jsonObject["version"];
                bug.Attributes = jsonObject.AsReadOnly ();
                bug.Url = (string) jsonObject["url"];
            } catch (Exception e) {
                #if DEBUG
                Console.Error.WriteLine(jsonObject.ToString());
                #endif
                Console.WriteLine("Failed to parse bug from JSON: {0}", e.Message);
            }
            return bug;
        }
Beispiel #25
0
 public void InitializeNearestStations(IDictionary <Station, TimeSpan> nearestStationsDistances)
 {
     this.NearestStationsDistances = nearestStationsDistances.AsReadOnly();
 }
        public void Test_unmodifiableMapLjava_util_Map()
        {
            // Test for method java.util.Map
            // java.util.Collections.unmodifiableMap(java.util.Map)
            bool exception = false;
            var  c         = (IDictionary <object, object>)hm.AsReadOnly();

            assertTrue("Returned map is of incorrect size", c.Count == hm.Count);
            var i = hm.Keys.GetEnumerator();

            while (i.MoveNext())
            {
                Object x = i.Current;
                assertTrue("Returned map missing elements", c[x].Equals(
                               hm[x]));
            }
            try
            {
                c[new Object()] = "";
            }
            catch (NotSupportedException e)
            {
                exception = true;
                // Correct
            }
            assertTrue("Allowed modification of map", exception);

            exception = false;
            try
            {
                c.Remove(new Object());
            }
            catch (NotSupportedException e)
            {
                // Correct
                exception = true;
            }
            assertTrue("Allowed modification of map", exception);

            exception = false;
            var it    = c.GetEnumerator();
            var entry = it.Current;

            //try
            //{
            //    entry.Value = ("modified"); // J2N: In .NET, Value property doesn't have a setter
            //}
            //catch (NotSupportedException e)
            //{
            //    // Correct
            //    exception = true;
            //}
            //assertTrue("Allowed modification of entry", exception);

            exception = false;
            object[] array = c.Cast <object>().ToArray();
            //try
            //{
            //    ((Map.Entry)array[0]).setValue("modified"); // J2N: In .NET, Value property doesn't have a setter
            //}
            //catch (NotSupportedException e)
            //{
            //    // Correct
            //    exception = true;
            //}
            //assertTrue("Allowed modification of array entry", exception);

            exception = false;
            var array2 = c.ToArray();
            //try
            //{
            //    array2[0].setValue("modified"); // J2N: In .NET, Value property doesn't have a setter
            //}
            //catch (NotSupportedException e)
            //{
            //    // Correct
            //    exception = true;
            //}
            //assertTrue("Allowed modification of array entry2", exception);

            var smallMap = new Dictionary <object, object>(); // J2N TODO: Need HashDictionary so we can support null keys here

            //smallMap[null] = new long?(30); // J2N TODO: Need HashDictionary so we can support null keys here
            smallMap[new long?(25)] = null;
            var unmodMap = smallMap.AsReadOnly();

            assertNull("Trying to use a null value in map failed", unmodMap[new long?(25)]);
            //assertTrue("Trying to use a null key in map failed", unmodMap[null] // J2N TODO: Need HashDictionary so we can support null keys here
            //        .Equals(new long?(30)));

            smallMap = new Dictionary <object, object>();
            for (int counter = 0; counter < 100; counter++)
            {
                smallMap[objArray[counter].ToString()] = objArray[counter];
            }
            unmodMap = smallMap.AsReadOnly();
            new Support_UnmodifiableMapTest("", unmodMap).RunTest();

#if FEATURE_SERIALIZABLE
            // Serialization
            var col   = unmodMap;
            var clone = Clone(col);

            assertNotSame(col, clone);
            assertNotSame(col.Dictionary, clone.Dictionary);
            assertEquals(col.Count, clone.Count);

            using (var it1 = col.GetEnumerator())
                using (var it2 = col.GetEnumerator())
                {
                    while (it1.MoveNext() && it2.MoveNext())
                    {
                        assertTrue(
                            "UnmodifiableDictionaryTest - Deserialized clone returned incorrect values",
                            it1.Current.Equals(it2.Current));
                    }
                }
#endif
        }
Beispiel #27
0
        public TermExpression(IDictionary<TermExpression, TermExpression> terms)
        {
            if (terms == null || terms.Count == 0)
                throw new CqlLinqException("Empty dictionaries are not allowed");

            var firstElement = terms.First();
            _type = typeof(IDictionary<,>).MakeGenericType(firstElement.Key.Type, firstElement.Value.Type);
            _dictionaryTerms = terms.AsReadOnly();
            _termType = CqlExpressionType.Map;
        }
Beispiel #28
0
 public Lookup(IDictionary <TIn, TOut> dictionary) : this(dictionary.AsReadOnly())
 {
 }
        public void IDictionaryAsReadOnlyNullTest()
        {
            IDictionary <string, int> dict = null;

            Assert.Throws(typeof(ArgumentNullException), () => dict.AsReadOnly());
        }
Beispiel #30
0
        public static ReadOnlyDictionary <TKey, TElement> ToReadOnlyDictionary <TSource, TKey, TElement>(this IEnumerable <TSource> source, Func <TSource, TKey> keySelector, Func <TSource, TElement> elementSelector, IEqualityComparer <TKey> comparer)
        {
            IDictionary <TKey, TElement> dict = source.ToDictionary(keySelector, elementSelector, comparer);

            return(dict.AsReadOnly());
        }
        public void AsReadOnly_NullIDictionary_ThrowsArgumentNullException()
        {
            IDictionary <string, string> dictionary = null;

            Assert.Throws <ArgumentNullException>("dictionary", () => dictionary.AsReadOnly());
        }
        private SegmentInfo ReadUpgradedSegmentInfo(string name, Directory dir, IndexInput input)
        {
            CodecUtil.CheckHeader(input, Lucene3xSegmentInfoFormat.UPGRADED_SI_CODEC_NAME, Lucene3xSegmentInfoFormat.UPGRADED_SI_VERSION_START, Lucene3xSegmentInfoFormat.UPGRADED_SI_VERSION_CURRENT);
            string version = input.ReadString();

            int docCount = input.ReadInt32();

            IDictionary <string, string> attributes = input.ReadStringStringMap();

            bool isCompoundFile = input.ReadByte() == SegmentInfo.YES;

            IDictionary <string, string> diagnostics = input.ReadStringStringMap();

            ISet <string> files = input.ReadStringSet();

            SegmentInfo info = new SegmentInfo(dir, version, name, docCount, isCompoundFile, null, diagnostics, attributes.AsReadOnly());

            info.SetFiles(files);
            return(info);
        }
Beispiel #33
0
 /** <inheritDoc /> */
 public IDictionary <string, object> GetAttributes()
 {
     return(_attrs.AsReadOnly());
 }