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.

FeedModel.java 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright 2011 gitblit.com.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of 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,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.gitblit.models;
  17. import java.io.Serializable;
  18. import java.util.Date;
  19. import com.gitblit.utils.StringUtils;
  20. /**
  21. * FeedModel represents a syndication (RSS) feed.
  22. *
  23. * @author James Moger
  24. */
  25. public class FeedModel implements Serializable, Comparable<FeedModel> {
  26. public String repository;
  27. public String branch;
  28. public Date lastRefreshDate;
  29. public Date currentRefreshDate;
  30. public boolean subscribed;
  31. private static final long serialVersionUID = 1L;
  32. public FeedModel() {
  33. this("");
  34. subscribed = false;
  35. }
  36. public FeedModel(String definition) {
  37. subscribed = true;
  38. lastRefreshDate = new Date(0);
  39. currentRefreshDate = new Date(0);
  40. String[] fields = definition.split(":");
  41. repository = fields[0];
  42. if (fields.length > 1) {
  43. branch = fields[1];
  44. }
  45. }
  46. @Override
  47. public String toString() {
  48. if (StringUtils.isEmpty(branch)) {
  49. return repository;
  50. }
  51. return repository + ":" + branch;
  52. }
  53. @Override
  54. public int compareTo(FeedModel o) {
  55. int repositoryCompare = StringUtils.compareRepositoryNames(repository, o.repository);
  56. if (repositoryCompare == 0) {
  57. // same repository
  58. if (StringUtils.isEmpty(branch)) {
  59. return 1;
  60. } else if (StringUtils.isEmpty(o.branch)) {
  61. return -1;
  62. }
  63. return branch.compareTo(o.branch);
  64. }
  65. return repositoryCompare;
  66. }
  67. @Override
  68. public int hashCode() {
  69. return toString().toLowerCase().hashCode();
  70. }
  71. @Override
  72. public boolean equals(Object o) {
  73. if (o instanceof FeedModel) {
  74. return hashCode() == o.hashCode();
  75. }
  76. return false;
  77. }
  78. }