You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SortOrder.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.data.sort;
  17. import java.io.Serializable;
  18. import com.vaadin.shared.data.sort.SortDirection;
  19. /**
  20. * Sort order descriptor. Links together a {@link SortDirection} value and a
  21. * Vaadin container property ID.
  22. *
  23. * @since 7.4
  24. * @author Vaadin Ltd
  25. */
  26. public class SortOrder implements Serializable {
  27. private final Object propertyId;
  28. private final SortDirection direction;
  29. /**
  30. * Create a SortOrder object. Both arguments must be non-null.
  31. *
  32. * @param propertyId
  33. * id of the data source property to sort by
  34. * @param direction
  35. * value indicating whether the property id should be sorted in
  36. * ascending or descending order
  37. */
  38. public SortOrder(Object propertyId, SortDirection direction) {
  39. if (propertyId == null) {
  40. throw new IllegalArgumentException("Property ID can not be null!");
  41. }
  42. if (direction == null) {
  43. throw new IllegalArgumentException(
  44. "Direction value can not be null!");
  45. }
  46. this.propertyId = propertyId;
  47. this.direction = direction;
  48. }
  49. /**
  50. * Returns the property ID.
  51. *
  52. * @return a property ID
  53. */
  54. public Object getPropertyId() {
  55. return propertyId;
  56. }
  57. /**
  58. * Returns the {@link SortDirection} value.
  59. *
  60. * @return a sort direction value
  61. */
  62. public SortDirection getDirection() {
  63. return direction;
  64. }
  65. @Override
  66. public String toString() {
  67. return propertyId + " " + direction;
  68. }
  69. @Override
  70. public int hashCode() {
  71. final int prime = 31;
  72. int result = 1;
  73. result = prime * result + direction.hashCode();
  74. result = prime * result + propertyId.hashCode();
  75. return result;
  76. }
  77. @Override
  78. public boolean equals(Object obj) {
  79. if (this == obj) {
  80. return true;
  81. } else if (obj == null) {
  82. return false;
  83. } else if (getClass() != obj.getClass()) {
  84. return false;
  85. }
  86. SortOrder other = (SortOrder) obj;
  87. if (direction != other.direction) {
  88. return false;
  89. } else if (!propertyId.equals(other.propertyId)) {
  90. return false;
  91. }
  92. return true;
  93. }
  94. }