public override EvaluationResult evaluate <T1>(IEnumerable <T1> iterable, CalculationFunctions functions, string firstToken, IList <string> remainingTokens)
        {
            string token = firstToken.ToLower(Locale.ENGLISH);
            int?   index = Ints.tryParse(token);

            if (index != null)
            {
                try
                {
                    return(EvaluationResult.success(Iterables.get(iterable, index), remainingTokens));
                }
                catch (System.IndexOutOfRangeException)
                {
                    return(invalidTokenFailure(iterable, token));
                }
            }
            ISet <string> tokens = this.tokens(iterable);

            foreach (object item in iterable)
            {
                if (!fieldValues(item).Contains(token))
                {
                    continue;
                }
                if (!tokens.Contains(token))
                {
                    return(ambiguousTokenFailure(iterable, token));
                }
                return(EvaluationResult.success(item, remainingTokens));
            }
            return(invalidTokenFailure(iterable, token));
        }
Beispiel #2
0
            private bool createActionImages(Ints actions, Floats buttonXY)
            {
                int actionCount = actions.count();

                for (int i = 0; i < actionCount; i++)
                {
                    int         cmdIndex    = actions.get(i);
                    ImageSource imageSource = WPFImageSourceHelper.Instance.ActionImageSource(cmdIndex);

                    if (imageSource == null)
                    {
                        continue;
                    }

                    string cmdName = GetButtonCaption(cmdIndex);
                    System.Diagnostics.Trace.WriteLine(string.Format("{0},{1}", cmdIndex, cmdName));

                    Image image = new Image()
                    {
                        Source  = imageSource,
                        ToolTip = cmdName,
                        Tag     = cmdIndex,
                        Width   = imageSource.Width,
                        Height  = imageSource.Height
                    };
                    image.MouseDown += new MouseButtonEventHandler(button_Click);
                    _owner.TempCanvas.Children.Add(image);
                    Canvas.SetLeft(image, buttonXY.get(2 * i) - image.Width / 2);
                    Canvas.SetTop(image, buttonXY.get(2 * i + 1) - image.Height / 2);
                    ActionImages.Add(image);
                    ActionImages.Add(image);
                }

                return(actionCount == 0 || ActionImages.Count > 0);
            }
 public void Clear()
 {
     Strings.Clear();
     Bools.Clear();
     Ints.Clear();
     Floats.Clear();
 }
Beispiel #4
0
        static public Mesh CreateCircleOutline(float width, int number_vertexs)
        {
            Mesh mesh = new Mesh();

            int ring_vertexs = number_vertexs / 2;

            mesh.vertices = Floats.Line(0.0f, 360.0f, ring_vertexs, true)
                            .Convert(a => Vector2Extensions.CreateDirectionFromDegrees(a).GetSpacar() * 0.5f)
                            .Append(
                Floats.Line(0.0f, 360.0f, ring_vertexs, true)
                .Convert(a => Vector2Extensions.CreateDirectionFromDegrees(a).GetSpacar() * (0.5f - width))
                )
                            .ToArray();

            mesh.triangles = Ints.Range(0, ring_vertexs, false)
                             .ConvertConnections((p1, p2) =>
                                                 Enumerable.New(
                                                     p1 + ring_vertexs, p2, p1,
                                                     p1 + ring_vertexs, p2 + ring_vertexs, p2
                                                     )
                                                 )
                             .ToArray();

            mesh.RecalculateNormals();
            mesh.RecalculateBounds();
            return(mesh);
        }
Beispiel #5
0
            private void createActionButtons(Ints actions, Floats buttonXY)
            {
                if (ActionButtons == null)
                {
                    ActionButtons = new List <Button>();
                }

                int actionCount = actions.count();

                for (int i = 0; i < actionCount; i++)
                {
                    int cmdIndex = actions.get(i);
                    if (cmdIndex >= buttonCaptions.Length)
                    {
                        continue;
                    }

                    string cmdName = buttonCaptions[cmdIndex];

                    Button button = new Button()
                    {
                        Content = cmdName,
                        Tag     = cmdIndex,
                        Width   = cmdName.Length * 14 + 8,
                        Height  = 24
                    };
                    button.Click += new RoutedEventHandler(button_Click);
                    _owner.TempCanvas.Children.Add(button);
                    Canvas.SetLeft(button, buttonXY.get(2 * i) - button.Width / 2);
                    Canvas.SetTop(button, buttonXY.get(2 * i + 1) - button.Height / 2);
                    ActionButtons.Add(button);
                }
            }
        public void ShouldEnumerateEnumerable()
        {
            var ints = new Ints(1, 2, 3);

            ints.Enumerate();
            ints.EnumerationCount.ShouldBe(1);
        }
Beispiel #7
0
 static public void CalculateTrianglesAsSequentialQuads(this Mesh item)
 {
     item.triangles = Ints.Range(0, item.vertexCount, 4, false)
                      .Convert(i => Enumerable.New(i, i + 1, i + 2, i, i + 2, i + 3))
                      .Flatten()
                      .ToArray();
 }
Beispiel #8
0
        public virtual bool TryGetDetail(string key, out object detail)
        {
            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException("key");
            }

            bool containsDetail = false;

            detail = null;
            if (Ids.ContainsKey(key))
            {
                containsDetail = true;
                detail         = Ids[key];
            }
            else if (Strings.ContainsKey(key))
            {
                containsDetail = true;
                detail         = Strings[key];
            }
            else if (Ints.ContainsKey(key))
            {
                containsDetail = true;
                detail         = Ints[key];
            }
            else if (Doubles.ContainsKey(key))
            {
                containsDetail = true;
                detail         = Doubles[key];
            }

            return(containsDetail);
        }
Beispiel #9
0
 public virtual void setSelectedShapeIDs(Ints ids)
 {
     touchvgPINVOKE.MgCoreView_setSelectedShapeIDs(swigCPtr, Ints.getCPtr(ids));
     if (touchvgPINVOKE.SWIGPendingException.Pending)
     {
         throw touchvgPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Beispiel #10
0
    public static int GetInt(string key)
    {
        if (Ints == null)
        {
            Ints = new Dictionary <string, int>();
        }

        return((Ints.ContainsKey(key)) ? Ints[key] : 0);
    }
        public void Load(string save)
        {
            var data = JsonUtility.FromJson <SaveData>(save);

            Strings.Load(data.strings);
            Bools.Load(data.bools);
            Ints.Load(data.ints);
            Floats.Load(data.floats);
        }
 public string Save()
 {
     return(JsonUtility.ToJson(new SaveData {
         strings = Strings.Save(),
         bools = Bools.Save(),
         ints = Ints.Save(),
         floats = Floats.Save(),
     }));
 }
Beispiel #13
0
 [Show, Category(Single)] void ClearSingles()
 {
     Ints.Clear();
     Strings.Clear();
     Floats.Clear();
     Bools.Clear();
     Vector3s.Clear();
     Colors.Clear();
 }
Beispiel #14
0
        public virtual void TestIntFieldCache()
        {
            Directory         dir = NewDirectory();
            IndexWriterConfig cfg = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()));

            cfg.SetMergePolicy(NewLogMergePolicy());
            RandomIndexWriter iw    = new RandomIndexWriter(Random(), dir, cfg);
            Document          doc   = new Document();
            IntField          field = new IntField("f", 0, Field.Store.YES);

            doc.Add(field);
            int[] values = new int[TestUtil.NextInt(Random(), 1, 10)];
            for (int i = 0; i < values.Length; ++i)
            {
                int v;
                switch (Random().Next(10))
                {
                case 0:
                    v = int.MinValue;
                    break;

                case 1:
                    v = 0;
                    break;

                case 2:
                    v = int.MaxValue;
                    break;

                default:
                    v = TestUtil.NextInt(Random(), -10, 10);
                    break;
                }
                values[i] = v;
                if (v == 0 && Random().NextBoolean())
                {
                    // missing
                    iw.AddDocument(new Document());
                }
                else
                {
                    field.IntValue = v;
                    iw.AddDocument(doc);
                }
            }
            iw.ForceMerge(1);
            DirectoryReader reader = iw.Reader;
            Ints            ints   = FieldCache.DEFAULT.GetInts(GetOnlySegmentReader(reader), "f", false);

            for (int i = 0; i < values.Length; ++i)
            {
                Assert.AreEqual(values[i], ints.Get(i));
            }
            reader.Dispose();
            iw.Dispose();
            dir.Dispose();
        }
Beispiel #15
0
 protected override LayerMask DrawBuiltInInternal(Rect rect, GUIContent label, LayerMask value)
 {
     return(EditorGUI.MaskField(
                rect,
                label,
                value.value,
                Ints.Range(0, 31, true).Convert(i => LayerMask.LayerToName(i)).ToArray()
                ));
 }
Beispiel #16
0
        public virtual int addShapeActions(MgMotion sender, Ints actions, int n, MgShape sp)
        {
            int ret = touchvgPINVOKE.CmdObserver_addShapeActions(swigCPtr, MgMotion.getCPtr(sender), Ints.getCPtr(actions), n, MgShape.getCPtr(sp));

            if (touchvgPINVOKE.SWIGPendingException.Pending)
            {
                throw touchvgPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Beispiel #17
0
 public virtual void Clear()
 {
     Strings.Clear();
     Ints.Clear();
     Floats.Clear();
     Bools.Clear();
     Colors.Clear();
     Vec2s.Clear();
     Vec3s.Clear();
 }
Beispiel #18
0
        public int getSkipDrawIds(Ints ids)
        {
            int ret = touchvgPINVOKE.GiCoreView_getSkipDrawIds(swigCPtr, Ints.getCPtr(ids));

            if (touchvgPINVOKE.SWIGPendingException.Pending)
            {
                throw touchvgPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Beispiel #19
0
 public override bool showContextActions(Ints actions, Floats buttonXY,
                                         float x, float y, float w, float h)
 {
     ClearActions();
     if (actions != null && !createActionImages(actions, buttonXY))
     {
         createActionButtons(actions, buttonXY);
     }
     return(isContextActionsVisible());
 }
Beispiel #20
0
        public override int addShapeActions(MgMotion sender, Ints actions, int n, MgShape sp)
        {
            int ret = (SwigDerivedClassHasMethod("addShapeActions", swigMethodTypes4) ? touchvgPINVOKE.CmdObserverDefault_addShapeActionsSwigExplicitCmdObserverDefault(swigCPtr, MgMotion.getCPtr(sender), Ints.getCPtr(actions), n, MgShape.getCPtr(sp)) : touchvgPINVOKE.CmdObserverDefault_addShapeActions(swigCPtr, MgMotion.getCPtr(sender), Ints.getCPtr(actions), n, MgShape.getCPtr(sp)));

            if (touchvgPINVOKE.SWIGPendingException.Pending)
            {
                throw touchvgPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Beispiel #21
0
        public int drawAll(Longs docs, int gs, GiCanvas canvas, Ints ignoreIds)
        {
            int ret = touchvgPINVOKE.GiCoreView_drawAll__SWIG_2(swigCPtr, Longs.getCPtr(docs), gs, GiCanvas.getCPtr(canvas), Ints.getCPtr(ignoreIds));

            if (touchvgPINVOKE.SWIGPendingException.Pending)
            {
                throw touchvgPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Beispiel #22
0
        public virtual bool showContextActions(Ints actions, Floats buttonXY, float x, float y, float w, float h)
        {
            bool ret = (SwigDerivedClassHasMethod("showContextActions", swigMethodTypes5) ? touchvgPINVOKE.GiView_showContextActionsSwigExplicitGiView(swigCPtr, Ints.getCPtr(actions), Floats.getCPtr(buttonXY), x, y, w, h) : touchvgPINVOKE.GiView_showContextActions(swigCPtr, Ints.getCPtr(actions), Floats.getCPtr(buttonXY), x, y, w, h));

            if (touchvgPINVOKE.SWIGPendingException.Pending)
            {
                throw touchvgPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Beispiel #23
0
        static public Mesh MakeFlatMesh(this IEnumerable <Triangle3> item)
        {
            Mesh mesh = new Mesh();

            mesh.vertices  = item.Convert(t => t.GetPoints()).Flatten().ToArray();
            mesh.triangles = Ints.Range(0, mesh.vertexCount, false).ToArray();

            mesh.RecalculateBounds();
            mesh.RecalculateNormals();
            return(mesh);
        }
Beispiel #24
0
        public void MultiMemberDataAttribute_succeeds_for_multiple_data_sources_with_multple_values( )
        {
            var method          = IntDoubleDoubleMethod(default(int), default(double), default(double));
            var attribute       = new MultiMemberDataAttribute(IntsName, MultiDoublesName);
            var rawPropertyData = new[] { Ints.ToArray( ), multiDoubles_ };
            var propertyData    = GetFlattenedPermutations(rawPropertyData);

            var attributeData = attribute.GetData(method).ToArray( );

            Assert.Equal(propertyData, attributeData, Comparer);
        }
 public void CopyFrom(ICustomProperties properties)
 {
     if (properties == null)
     {
         return;
     }
     Ints.CopyFrom(properties.Ints);
     Floats.CopyFrom(properties.Floats);
     Strings.CopyFrom(properties.Strings);
     Bools.CopyFrom(properties.Bools);
     Entities.CopyFrom(properties.Entities);
 }
Beispiel #26
0
        public virtual void TestDocsWithField()
        {
            IFieldCache cache = FieldCache.DEFAULT;

            cache.PurgeAllCaches();
            Assert.AreEqual(0, cache.CacheEntries.Length);
            cache.GetDoubles(Reader, "theDouble", true);

            // The double[] takes two slots (one w/ null parser, one
            // w/ real parser), and docsWithField should also
            // have been populated:
            Assert.AreEqual(3, cache.CacheEntries.Length);
            Bits bits = cache.GetDocsWithField(Reader, "theDouble");

            // No new entries should appear:
            Assert.AreEqual(3, cache.CacheEntries.Length);
            Assert.IsTrue(bits is Bits_MatchAllBits);

            Ints ints = cache.GetInts(Reader, "sparse", true);

            Assert.AreEqual(6, cache.CacheEntries.Length);
            Bits docsWithField = cache.GetDocsWithField(Reader, "sparse");

            Assert.AreEqual(6, cache.CacheEntries.Length);
            for (int i = 0; i < docsWithField.Length(); i++)
            {
                if (i % 2 == 0)
                {
                    Assert.IsTrue(docsWithField.Get(i));
                    Assert.AreEqual(i, ints.Get(i));
                }
                else
                {
                    Assert.IsFalse(docsWithField.Get(i));
                }
            }

            Ints numInts = cache.GetInts(Reader, "numInt", Random().NextBoolean());

            docsWithField = cache.GetDocsWithField(Reader, "numInt");
            for (int i = 0; i < docsWithField.Length(); i++)
            {
                if (i % 2 == 0)
                {
                    Assert.IsTrue(docsWithField.Get(i));
                    Assert.AreEqual(i, numInts.Get(i));
                }
                else
                {
                    Assert.IsFalse(docsWithField.Get(i));
                }
            }
        }
Beispiel #27
0
        /// <summary>Expire the ZK session of the given service.</summary>
        /// <remarks>
        /// Expire the ZK session of the given service. This requires
        /// (and asserts) that the given service be the current active.
        /// </remarks>
        /// <exception cref="Org.Apache.Zookeeper.KeeperException.NoNodeException">if no service holds the lock
        ///     </exception>
        public virtual void ExpireActiveLockHolder(int idx)
        {
            Stat stat = new Stat();

            byte[] data = zks.GetZKDatabase().GetData(MiniZKFCCluster.DummyZKFC.LockZnode, stat
                                                      , null);
            Assert.AssertArrayEquals(Ints.ToByteArray(svcs[idx].index), data);
            long session = stat.GetEphemeralOwner();

            Log.Info("Expiring svc " + idx + "'s zookeeper session " + session);
            zks.CloseSession(session);
        }
Beispiel #28
0
        /// <summary>Calculate the usable size of a shared memory segment.</summary>
        /// <remarks>
        /// Calculate the usable size of a shared memory segment.
        /// We round down to a multiple of the slot size and do some validation.
        /// </remarks>
        /// <param name="stream">The stream we're using.</param>
        /// <returns>The usable size of the shared memory segment.</returns>
        /// <exception cref="System.IO.IOException"/>
        private static int GetUsableLength(FileInputStream stream)
        {
            int intSize = Ints.CheckedCast(stream.GetChannel().Size());
            int slots   = intSize / BytesPerSlot;

            if (slots == 0)
            {
                throw new IOException("size of shared memory segment was " + intSize + ", but that is not enough to hold even one slot."
                                      );
            }
            return(slots * BytesPerSlot);
        }
Beispiel #29
0
        public ResourceRecord2(string DBCulture, int IndexPos, string[] fields)
        {
            this.DBCulture = DBCulture;
            this.IndexPos  = IndexPos;

            Row = Ints.ParseStorage(fields[0]);

            if (fields.Length != 5)
            {
                Row     = 0;
                Name    = null;
                Meal    = null;
                Brand   = null;
                DataPos = 0;
                return;
            }

            Meal    = fields[1];
            Name    = fields[2];
            Brand   = fields[3];
            DataPos = Ints.ParseStorage(fields[4]);

            if (Name != null && Name.Length == 0)
            {
                Name = null;
            }
            if (Meal != null && Meal.Length == 0)
            {
                Meal = null;
            }
            if (Brand != null && Brand.Length == 0)
            {
                Brand = null;
            }

            if (Name != null && Brand != null)
            {
                Name += " (" + Brand + ")";
            }

            if (Meal == null)
            {
                if (Brand == null && Row % 3 != 0)
                {
                    Meal = "P";
                }
                if (Brand != null && Row % 5 != 0)
                {
                    Meal = "P";
                }
            }
        }
Beispiel #30
0
        /// <summary>
        /// Makes an array containing the morgan numbers of the atoms of
        /// atomContainer. These number are the extended connectivity values and not
        /// the lexicographic smallest labelling on the graph.
        /// </summary>
        /// <param name="molecule">the molecule to analyse.</param>
        /// <returns>The morgan numbers value.</returns>
        public static long[] GetMorganNumbers(IAtomContainer molecule)
        {
            int order = molecule.Atoms.Count;

            long[] currentInvariants  = new long[order];
            long[] previousInvariants = new long[order];

            int[][] graph  = Arrays.CreateJagged <int>(order, InitialDegree);
            int[]   degree = new int[order];

            // which atoms are the non-hydrogens.
            int[] nonHydrogens = new int[order];

            for (int v = 0; v < order; v++)
            {
                nonHydrogens[v] = molecule.Atoms[v].AtomicNumber.Equals(AtomicNumbers.H) ? 0 : 1;
            }

            // build the graph and initialise the current connectivity
            // value to the number of connected non-hydrogens
            foreach (var bond in molecule.Bonds)
            {
                int u = molecule.Atoms.IndexOf(bond.Begin);
                int v = molecule.Atoms.IndexOf(bond.End);
                graph[u] = Ints.EnsureCapacity(graph[u], degree[u] + 1, InitialDegree);
                graph[v] = Ints.EnsureCapacity(graph[v], degree[v] + 1, InitialDegree);
                graph[u][degree[u]++] = v;
                graph[v][degree[v]++] = u;
                currentInvariants[u] += nonHydrogens[v];
                currentInvariants[v] += nonHydrogens[u];
            }

            // iteratively sum the connectivity values for each vertex
            for (int i = 0; i < order; i++)
            {
                Array.Copy(currentInvariants, 0, previousInvariants, 0, order);
                for (int u = 0; u < order; u++)
                {
                    currentInvariants[u] = 0;

                    // for each of the vertices adjacent to <paramref name="u"/> sum their
                    // previous connectivity value
                    int[] neighbors = graph[u];
                    for (int j = 0; j < degree[u]; j++)
                    {
                        int v = neighbors[j];
                        currentInvariants[u] += previousInvariants[v] * nonHydrogens[v];
                    }
                }
            }
            return(currentInvariants);
        }
Beispiel #31
0
 public virtual void setSelectedShapeIDs(Ints ids)
 {
     touchvgPINVOKE.MgCoreView_setSelectedShapeIDs(swigCPtr, Ints.getCPtr(ids));
     if (touchvgPINVOKE.SWIGPendingException.Pending) throw touchvgPINVOKE.SWIGPendingException.Retrieve();
 }
Beispiel #32
0
 public override int addShapeActions(MgMotion sender, Ints actions, int n, MgShape sp)
 {
     int ret = (SwigDerivedClassHasMethod("addShapeActions", swigMethodTypes4) ? touchvgPINVOKE.CmdObserverDefault_addShapeActionsSwigExplicitCmdObserverDefault(swigCPtr, MgMotion.getCPtr(sender), Ints.getCPtr(actions), n, MgShape.getCPtr(sp)) : touchvgPINVOKE.CmdObserverDefault_addShapeActions(swigCPtr, MgMotion.getCPtr(sender), Ints.getCPtr(actions), n, MgShape.getCPtr(sp)));
     if (touchvgPINVOKE.SWIGPendingException.Pending) throw touchvgPINVOKE.SWIGPendingException.Retrieve();
     return ret;
 }
Beispiel #33
0
 public virtual int addShapeActions(MgMotion sender, Ints actions, int n, MgShape sp)
 {
     int ret = touchvgPINVOKE.CmdObserver_addShapeActions(swigCPtr, MgMotion.getCPtr(sender), Ints.getCPtr(actions), n, MgShape.getCPtr(sp));
     if (touchvgPINVOKE.SWIGPendingException.Pending) throw touchvgPINVOKE.SWIGPendingException.Retrieve();
     return ret;
 }
Beispiel #34
0
 public virtual bool showContextActions(Ints actions, Floats buttonXY, float x, float y, float w, float h)
 {
     bool ret = (SwigDerivedClassHasMethod("showContextActions", swigMethodTypes5) ? touchvgPINVOKE.GiView_showContextActionsSwigExplicitGiView(swigCPtr, Ints.getCPtr(actions), Floats.getCPtr(buttonXY), x, y, w, h) : touchvgPINVOKE.GiView_showContextActions(swigCPtr, Ints.getCPtr(actions), Floats.getCPtr(buttonXY), x, y, w, h));
     if (touchvgPINVOKE.SWIGPendingException.Pending) throw touchvgPINVOKE.SWIGPendingException.Retrieve();
     return ret;
 }
Beispiel #35
0
 public int getSkipDrawIds(Ints ids)
 {
     int ret = touchvgPINVOKE.GiCoreView_getSkipDrawIds(swigCPtr, Ints.getCPtr(ids));
     if (touchvgPINVOKE.SWIGPendingException.Pending) throw touchvgPINVOKE.SWIGPendingException.Retrieve();
     return ret;
 }
Beispiel #36
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Ints obj)
 {
     return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
 }
Beispiel #37
0
 public int drawAll(Longs docs, int gs, GiCanvas canvas, Ints ignoreIds)
 {
     int ret = touchvgPINVOKE.GiCoreView_drawAll__SWIG_2(swigCPtr, Longs.getCPtr(docs), gs, GiCanvas.getCPtr(canvas), Ints.getCPtr(ignoreIds));
     if (touchvgPINVOKE.SWIGPendingException.Pending) throw touchvgPINVOKE.SWIGPendingException.Retrieve();
     return ret;
 }