RowComparer.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright © 2005, Mathew Hall
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * - Redistributions of source code must retain the above copyright notice,
  9. * this list of conditions and the following disclaimer.
  10. *
  11. * - Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  16. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  18. * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  19. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  20. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  21. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  22. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  23. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  24. * OF SUCH DAMAGE.
  25. */
  26. using System;
  27. using System.Collections;
  28. namespace XPTable.Models.Design
  29. {
  30. /// <summary>
  31. ///
  32. /// </summary>
  33. internal class RowComparer : IComparer
  34. {
  35. /// <summary>
  36. ///
  37. /// </summary>
  38. /// <param name="x"></param>
  39. /// <param name="y"></param>
  40. /// <returns></returns>
  41. public int Compare(object x, object y)
  42. {
  43. Row row1 = (Row) x;
  44. Row row2 = (Row) y;
  45. // check for null rows
  46. if (row1 == null && row2 == null)
  47. {
  48. return 0;
  49. }
  50. else if (row1 == null)
  51. {
  52. return -1;
  53. }
  54. else if (row2 == null)
  55. {
  56. return 1;
  57. }
  58. if (row1.InternalIndex < row2.InternalIndex)
  59. {
  60. return -1;
  61. }
  62. else if (row1.InternalIndex < row2.InternalIndex)
  63. {
  64. return 1;
  65. }
  66. return 0;
  67. }
  68. }
  69. }