Skip to content

Commit c2784c3

Browse files
committed
Converted for loop to java8 lambda
1 parent 7d661fa commit c2784c3

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

src/main/java/org/jenkinsci/plugins/gogs/GogsUtils.java

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,25 @@
55

66
class GogsUtils {
77

8-
private GogsUtils() {
9-
}
8+
private GogsUtils() {
9+
}
10+
11+
/**
12+
* Search in Jenkins for a item with type T based on the job name
13+
*
14+
* @param jobName job to find, for jobs inside a folder use : {@literal <folder>/<folder>/<jobName>}
15+
* @return the Job matching the given name, or {@code null} when not found
16+
*/
17+
static <T extends Item> T find(String jobName, Class<T> type) {
18+
Jenkins jenkins = Jenkins.getActiveInstance();
19+
// direct search, can be used to find folder based items <folder>/<folder>/<jobName>
20+
T item = jenkins.getItemByFullName(jobName, type);
21+
if (item == null) {
22+
// not found in a direct search, search in all items since the item might be in a folder but given without folder structure
23+
// (to keep it backwards compatible)
24+
item = jenkins.getAllItems(type).stream().filter(i -> i.getName().equals(jobName)).findFirst().get();
25+
}
26+
return item;
27+
}
1028

11-
/**
12-
* Search in Jenkins for a item with type T based on the job name
13-
* @param jobName job to find, for jobs inside a folder use : {@literal <folder>/<folder>/<jobName>}
14-
* @return the Job matching the given name, or {@code null} when not found
15-
*/
16-
static <T extends Item> T find(String jobName, Class<T> type) {
17-
Jenkins jenkins = Jenkins.getActiveInstance();
18-
// direct search, can be used to find folder based items <folder>/<folder>/<jobName>
19-
T item = jenkins.getItemByFullName(jobName, type);
20-
if (item == null) {
21-
// not found in a direct search, search in all items since the item might be in a folder but given without folder structure
22-
// (to keep it backwards compatible)
23-
for (T allItem : jenkins.getAllItems(type)) {
24-
if (allItem.getName().equals(jobName)) {
25-
item = allItem;
26-
break;
27-
}
28-
}
29-
}
30-
return item;
31-
}
3229
}

0 commit comments

Comments
 (0)