Пример #1
0
 public XmlCounterElement(CounterElement counterElement)
 {
     if (counterElement != null) {
         Instance = new XmlCounterInstance(counterElement.Instance);
         Sprites = new XmlSpriteListElement(counterElement.Sprites);
     }
 }
Пример #2
0
        public void Add_AddsToExistingElement(HashSet <CounterElement> existingElements, int add, Guid nodeId)
        {
            var existingElement = new CounterElement(999, nodeId);

            existingElements.Add(existingElement);

            var counter = new G_Counter(existingElements.ToImmutableHashSet());

            counter = counter.Add(add, nodeId);

            var element = counter.Elements.FirstOrDefault(e => e.Node.Id == nodeId);

            Assert.Equal(999 + add, element.Value);
        }
        public PN_Counter Subtract(int value, Guid nodeId)
        {
            var element = Subtractions.FirstOrDefault(e => e.Node.Id == nodeId);

            if (element is null)
            {
                element = new CounterElement(value, nodeId);
            }
            else
            {
                element.Add(Math.Abs(value));
            }

            var subtractions = Subtractions.Where(e => e.Node.Id != nodeId).ToImmutableHashSet();

            subtractions = subtractions.Add(element);

            return(new PN_Counter(Additions, subtractions));
        }
Пример #4
0
        public G_Counter Add(int value, Guid nodeId)
        {
            var element = Elements.FirstOrDefault(e => e.Node.Id == nodeId);

            if (element is null)
            {
                element = new CounterElement(value, nodeId);
            }
            else
            {
                element.Add(value);
            }

            var elements = Elements.Where(e => e.Node.Id != nodeId).ToImmutableHashSet();

            elements = elements.Add(element);

            return(new G_Counter(elements.ToImmutableHashSet()));
        }
        public PN_Counter Add(int value, Guid nodeId)
        {
            var element = Additions.FirstOrDefault(e => e.Node.Id == nodeId);

            if (element is null)
            {
                element = new CounterElement(value, nodeId);
            }
            else
            {
                element.Add(value);
            }

            var additions = Additions.Where(e => e.Node.Id != nodeId).ToImmutableHashSet();

            additions = additions.Add(element);

            return(new PN_Counter(additions, Subtractions));
        }