コード例 #1
0
 public void FromJSON(FloorController api, JSONNode root)
 {
     collection = root["collection"] ?? "";
     begin      = new CallNumber(root["call_start"]);
     end        = new CallNumber(root["call_end"]);
     isSideA    = root["side"].AsInt == 0;
 }
コード例 #2
0
        /// <summary>
        /// Updates the editing object with this editor's values.
        /// </summary>
        public void UpdateObject()
        {
            if (editingObject == null)
            {
                return;
            }

            // TODO: this part seems a bit ugly. Can we do better here?
            string collection = "";

            if (collectionDropdown.currentlySelected == 0)
            {
                collection = CallNumberCollection.Regular;
            }
            else if (collectionDropdown.currentlySelected == 1)
            {
                collection = CallNumberCollection.OversizedPlus;
            }
            else if (collectionDropdown.currentlySelected == 2)
            {
                collection = CallNumberCollection.OversizedPlusPlus;
            }

            editingObject.collection = collection;
            editingObject.isSideA    = sideDropdown.currentlySelected == 0;

            // We check if all fields are properly set up. If not we don't update the
            // ranges.
            bool allValid = true;

            allValid &= !startInputField.validationText.isActiveAndEnabled;
            allValid &= !endInputField.validationText.isActiveAndEnabled;

            if (!allValid)
            {
                return;
            }

            // This is called every single time we edit the field.
            // We want to create new call numbers each time, to validate the input.
            CallNumber begin = new CallNumber(startInputField.inputField.text);
            CallNumber end   = new CallNumber(endInputField.inputField.text);

            // Check if there is any change
            bool changed = !(begin.ToString().Equals(editingObject.GetBegin().ToString()) &&
                             end.ToString().Equals(editingObject.GetEnd().ToString()));

            allValid &= editingObject.SetBegin(begin);
            allValid &= editingObject.SetEnd(end);

            if (allValid && changed)
            {
                ActionManager.shared.Push();
            }

            warningIcon.gameObject.SetActive(!allValid);
        }
コード例 #3
0
        /// <summary>
        /// Sets the ending call number of this range. Returns false if b is
        /// smaller than begin.
        /// </summary>
        /// <returns><c>true</c>, if end was set, <c>false</c> otherwise.</returns>
        public bool SetEnd(CallNumber b)
        {
            if (b == null || b.CompareTo(begin) < 0)
            {
                return(false);
            }

            end = b;
            return(true);
        }
コード例 #4
0
        /// <summary>
        /// Sets the beginning call number of this range. Returns false if b is
        /// larger than end.
        /// </summary>
        /// <returns><c>true</c>, if begin was set, <c>false</c> otherwise.</returns>
        public bool SetBegin(CallNumber b)
        {
            if (b == null || b.CompareTo(end) > 0)
            {
                return(false);
            }

            begin = b;
            return(true);
        }
コード例 #5
0
        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                return(1);
            }

            CallNumber other = obj as CallNumber;

            if (other != null)
            {
                // We first compare class.
                int classComp = cnClass.CompareTo(other.cnClass);

                if (classComp != 0)
                {
                    return(classComp);
                }

                // Then we compare subclass.

                if ((HasSubclass() && !other.HasSubclass()))
                {
                    return(1);
                }
                else if ((!HasSubclass() && other.HasSubclass()))
                {
                    return(-1);
                }
                else if (!HasSubclass() && !other.HasSubclass())
                {
                    return(0);
                }
                else
                {
                    int result = cnSubclass.CompareTo(other.cnSubclass);

                    if (result != 0)
                    {
                        return(result);
                    }
                }

                // Then we compare the cutters.
                if ((HasCutter1() && !other.HasCutter1()))
                {
                    return(1);
                }
                else if ((!HasCutter1() && other.HasCutter1()))
                {
                    return(-1);
                }
                else if (!HasCutter1() && !other.HasCutter1())
                {
                    return(0);
                }
                else
                {
                    int result = LetterPart(cnCutter1).CompareTo(LetterPart(other.cnCutter1));

                    if (result != 0)
                    {
                        return(result);
                    }

                    if (NumberPart(cnCutter1) > NumberPart(other.cnCutter1))
                    {
                        return(1);
                    }
                    else if (NumberPart(cnCutter1) < NumberPart(other.cnCutter1))
                    {
                        return(-1);
                    }
                }

                if ((HasCutter2() && !other.HasCutter2()))
                {
                    return(1);
                }
                else if ((!HasSubclass() && other.HasSubclass()))
                {
                    return(-1);
                }
                else if (!HasCutter2() && !other.HasCutter2())
                {
                    return(0);
                }
                else
                {
                    int result = LetterPart(cnCutter2).CompareTo(LetterPart(other.cnCutter2));

                    if (result != 0)
                    {
                        return(result);
                    }

                    if (NumberPart(cnCutter2) > NumberPart(other.cnCutter2))
                    {
                        return(1);
                    }
                    else if (NumberPart(cnCutter2) < NumberPart(other.cnCutter2))
                    {
                        return(-1);
                    }
                }

                return(0);
            }
            else
            {
                throw new ArgumentException("Object is not a call number");
            }
        }