Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Resolution.java 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright 2000-2016 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.shared.ui.datefield;
  17. import java.util.ArrayList;
  18. import java.util.List;
  19. /**
  20. * Resolutions for DateFields
  21. *
  22. * @author Vaadin Ltd.
  23. * @since 7.0
  24. */
  25. public enum Resolution {
  26. DAY, MONTH, YEAR;
  27. /**
  28. * Returns the resolutions that are higher or equal to the given resolution,
  29. * starting from the given resolution. In other words passing DAY to this
  30. * methods returns DAY,MONTH,YEAR
  31. *
  32. * @param r
  33. * The resolution to start from
  34. * @return An iterable for the resolutions higher or equal to r
  35. */
  36. public static Iterable<Resolution> getResolutionsHigherOrEqualTo(
  37. Resolution r) {
  38. List<Resolution> resolutions = new ArrayList<>();
  39. Resolution[] values = Resolution.values();
  40. for (int i = r.ordinal(); i < values.length; i++) {
  41. resolutions.add(values[i]);
  42. }
  43. return resolutions;
  44. }
  45. /**
  46. * Returns the resolutions that are lower than the given resolution,
  47. * starting from the given resolution. In other words passing DAY to this
  48. * methods returns HOUR,MINUTE,SECOND.
  49. *
  50. * @param r
  51. * The resolution to start from
  52. * @return An iterable for the resolutions lower than r
  53. */
  54. public static List<Resolution> getResolutionsLowerThan(Resolution r) {
  55. List<Resolution> resolutions = new ArrayList<>();
  56. Resolution[] values = Resolution.values();
  57. for (int i = r.ordinal() - 1; i >= 0; i--) {
  58. resolutions.add(values[i]);
  59. }
  60. return resolutions;
  61. }
  62. }