Apache.NMS.ActiveMQ.Util.IdGenerator.GetSequenceFromId C# (CSharp) Method

GetSequenceFromId() public static method

From a generated id - return the generator count
public static GetSequenceFromId ( String id ) : long
id String /// A ///
return long
        public static long GetSequenceFromId(String id)
        {
            long result = -1;
            if(id != null)
            {
                int index = id.LastIndexOf(':');

                if(index > 0 && (index + 1) < id.Length)
                {
                    String numStr = id.Substring(index + 1, id.Length);
                    result = Int64.Parse(numStr);
                }
            }
            return result;
        }

Usage Example

Beispiel #1
0
        /// <summary>
        /// Does a proper compare on the ids
        /// </summary>
        /// <param name="id1">
        /// A <see cref="String"/>
        /// </param>
        /// <param name="id2">
        /// A <see cref="String"/>
        /// </param>
        /// <returns>
        /// A <see cref="System.Int32"/>
        /// </returns>
        public static int Compare(String id1, String id2)
        {
            int result = -1;

            String seed1 = IdGenerator.GetSeedFromId(id1);
            String seed2 = IdGenerator.GetSeedFromId(id2);

            if (seed1 != null && seed2 != null)
            {
                result = seed1.CompareTo(seed2);

                if (result == 0)
                {
                    long count1 = IdGenerator.GetSequenceFromId(id1);
                    long count2 = IdGenerator.GetSequenceFromId(id2);
                    result = (int)(count1 - count2);
                }
            }

            return(result);
        }