commit | author | age
|
17820f
|
1 |
/*
|
JM |
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 |
|
|
18 |
import java.io.Serializable;
|
|
19 |
import java.util.Date;
|
|
20 |
|
|
21 |
import com.gitblit.utils.StringUtils;
|
|
22 |
|
|
23 |
/**
|
|
24 |
* FeedModel represents a syndication (RSS) feed.
|
|
25 |
*
|
|
26 |
* @author James Moger
|
|
27 |
*/
|
|
28 |
public class FeedModel implements Serializable, Comparable<FeedModel> {
|
|
29 |
|
|
30 |
public String repository;
|
|
31 |
public String branch;
|
bab9c9
|
32 |
public Date lastRefreshDate;
|
JM |
33 |
public Date currentRefreshDate;
|
17820f
|
34 |
|
JM |
35 |
public boolean subscribed;
|
|
36 |
|
|
37 |
private static final long serialVersionUID = 1L;
|
|
38 |
|
|
39 |
public FeedModel() {
|
|
40 |
this("");
|
c25a1d
|
41 |
subscribed = false;
|
17820f
|
42 |
}
|
JM |
43 |
|
|
44 |
public FeedModel(String definition) {
|
c25a1d
|
45 |
subscribed = true;
|
bab9c9
|
46 |
lastRefreshDate = new Date(0);
|
JM |
47 |
currentRefreshDate = new Date(0);
|
17820f
|
48 |
|
JM |
49 |
String[] fields = definition.split(":");
|
|
50 |
repository = fields[0];
|
|
51 |
if (fields.length > 1) {
|
|
52 |
branch = fields[1];
|
|
53 |
}
|
|
54 |
}
|
|
55 |
|
|
56 |
@Override
|
|
57 |
public String toString() {
|
c25a1d
|
58 |
if (StringUtils.isEmpty(branch)) {
|
JM |
59 |
return repository;
|
|
60 |
}
|
|
61 |
return repository + ":" + branch;
|
17820f
|
62 |
}
|
JM |
63 |
|
|
64 |
@Override
|
|
65 |
public int compareTo(FeedModel o) {
|
38688b
|
66 |
int repositoryCompare = StringUtils.compareRepositoryNames(repository, o.repository);
|
17820f
|
67 |
if (repositoryCompare == 0) {
|
JM |
68 |
// same repository
|
|
69 |
if (StringUtils.isEmpty(branch)) {
|
|
70 |
return 1;
|
|
71 |
} else if (StringUtils.isEmpty(o.branch)) {
|
|
72 |
return -1;
|
|
73 |
}
|
|
74 |
return branch.compareTo(o.branch);
|
|
75 |
}
|
|
76 |
return repositoryCompare;
|
|
77 |
}
|
|
78 |
|
|
79 |
@Override
|
|
80 |
public int hashCode() {
|
bab9c9
|
81 |
return toString().toLowerCase().hashCode();
|
17820f
|
82 |
}
|
JM |
83 |
|
|
84 |
@Override
|
|
85 |
public boolean equals(Object o) {
|
|
86 |
if (o instanceof FeedModel) {
|
|
87 |
return hashCode() == o.hashCode();
|
|
88 |
}
|
|
89 |
return false;
|
|
90 |
}
|
|
91 |
}
|