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

GetSeedFromId() public static method

From a generated id - return the seed (i.e. minus the count)
public static GetSeedFromId ( String id ) : String
id String /// A ///
return String
        public static String GetSeedFromId(String id)
        {
            String result = id;

            if(id != null)
            {
                int index = id.LastIndexOf(':');
                if(index > 0 && (index + 1) < id.Length)
                {
                    result = id.Substring(0, index + 1);
                }
            }

            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);
        }