Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
Releases |
|
| 1.4615384615384615;1.462 | ||||
Releases$Smart |
|
| 1.4615384615384615;1.462 | ||||
Releases$Smart$AjcClosure1 |
|
| 1.4615384615384615;1.462 | ||||
Releases$Smart$AjcClosure11 |
|
| 1.4615384615384615;1.462 | ||||
Releases$Smart$AjcClosure13 |
|
| 1.4615384615384615;1.462 | ||||
Releases$Smart$AjcClosure3 |
|
| 1.4615384615384615;1.462 | ||||
Releases$Smart$AjcClosure5 |
|
| 1.4615384615384615;1.462 | ||||
Releases$Smart$AjcClosure7 |
|
| 1.4615384615384615;1.462 | ||||
Releases$Smart$AjcClosure9 |
|
| 1.4615384615384615;1.462 |
1 | 2 | /** |
2 | * Copyright (c) 2013-2017, jcabi.com | |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions | |
7 | * are met: 1) Redistributions of source code must retain the above | |
8 | * copyright notice, this list of conditions and the following | |
9 | * disclaimer. 2) Redistributions in binary form must reproduce the above | |
10 | * copyright notice, this list of conditions and the following | |
11 | * disclaimer in the documentation and/or other materials provided | |
12 | * with the distribution. 3) Neither the name of the jcabi.com nor | |
13 | * the names of its contributors may be used to endorse or promote | |
14 | * products derived from this software without specific prior written | |
15 | * permission. | |
16 | * | |
17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
18 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT | |
19 | * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
20 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL | |
21 | * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |
22 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
26 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | |
28 | * OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 | */ | |
30 | package com.jcabi.github; | |
31 | ||
32 | import com.jcabi.aspects.Immutable; | |
33 | import com.jcabi.aspects.Loggable; | |
34 | import java.io.IOException; | |
35 | import lombok.EqualsAndHashCode; | |
36 | import lombok.ToString; | |
37 | ||
38 | /** | |
39 | * Github Releases. | |
40 | * | |
41 | * @author Paul Polishchuk (ppol@ua.fm) | |
42 | * @version $Id: d35b80965ab58c09c9062e1cf0d5d43b77a639d9 $ | |
43 | * @since 0.8 | |
44 | */ | |
45 | @Immutable | |
46 | public interface Releases { | |
47 | /** | |
48 | * Owner of them. | |
49 | * @return Repo | |
50 | */ | |
51 | Repo repo(); | |
52 | ||
53 | /** | |
54 | * Iterate them all. | |
55 | * @return Iterator of releases | |
56 | * @see <a href="http://developer.github.com/v3/repos/releases/#list">List</a> | |
57 | */ | |
58 | Iterable<Release> iterate(); | |
59 | ||
60 | /** | |
61 | * Get a single release. | |
62 | * @param number Release id | |
63 | * @return Release | |
64 | * @see <a href="http://developer.github.com/v3/repos/releases/#get-a-single-release">Get a single release</a> | |
65 | */ | |
66 | Release get(int number); | |
67 | ||
68 | /** | |
69 | * Create new release. | |
70 | * @param tag The name of the tag | |
71 | * @return Release just created | |
72 | * @throws java.io.IOException If there is any I/O problem | |
73 | * @see <a href="http://developer.github.com/v3/repos/releases/#create-a-release">Create an Release</a> | |
74 | */ | |
75 | Release create( | |
76 | String tag) | |
77 | throws IOException; | |
78 | ||
79 | /** | |
80 | * Remove a release. | |
81 | * | |
82 | * @param number ID of the release to remove. | |
83 | * @throws IOException If an IO problem occurs. | |
84 | * @see <a href="http://developer.github.com/v3/repos/releases/#delete-a-release">Delete a release.</a> | |
85 | */ | |
86 | void remove(int number) throws IOException; | |
87 | ||
88 | /** | |
89 | * Smart releases. | |
90 | * @since 0.17 | |
91 | */ | |
92 | @Immutable | |
93 | 0 | @ToString |
94 | @Loggable(Loggable.DEBUG) | |
95 | 0 | @EqualsAndHashCode(of = "releases") |
96 | final class Smart implements Releases { | |
97 | /** | |
98 | * Encapsulated releases. | |
99 | */ | |
100 | private final transient Releases releases; | |
101 | ||
102 | /** | |
103 | * Public CTOR. | |
104 | * @param original Original releases | |
105 | */ | |
106 | public Smart( | |
107 | final Releases original | |
108 | 2 | ) { |
109 | 2 | this.releases = original; |
110 | 2 | } |
111 | @Override | |
112 | public Repo repo() { | |
113 | 0 | return this.releases.repo(); |
114 | } | |
115 | @Override | |
116 | public Iterable<Release> iterate() { | |
117 | 4 | return this.releases.iterate(); |
118 | } | |
119 | @Override | |
120 | public Release get(final int number) { | |
121 | 0 | return this.releases.get(number); |
122 | } | |
123 | @Override | |
124 | public Release create(final String tag) throws IOException { | |
125 | 0 | return this.releases.create(tag); |
126 | } | |
127 | @Override | |
128 | public void remove(final int number) throws IOException { | |
129 | 0 | this.releases.remove(number); |
130 | 0 | } |
131 | /** | |
132 | * This release exists by the tag. | |
133 | * @param tag The tag | |
134 | * @return TRUE if it already exists | |
135 | * @throws IOException If fails | |
136 | */ | |
137 | public boolean exists(final String tag) throws IOException { | |
138 | 2 | boolean exists = false; |
139 | 1 | final Iterable<Release.Smart> rels = new Smarts<Release.Smart>( |
140 | 1 | this.iterate() |
141 | ); | |
142 | 1 | for (final Release.Smart rel : rels) { |
143 | 1 | if (rel.tag().equals(tag)) { |
144 | 1 | exists = true; |
145 | 1 | break; |
146 | } | |
147 | 0 | } |
148 | 1 | return exists; |
149 | } | |
150 | /** | |
151 | * Find release by the tag (runtime exception if not found). | |
152 | * @param tag The tag | |
153 | * @return Release found | |
154 | * @throws IOException If fails | |
155 | */ | |
156 | public Release find(final String tag) throws IOException { | |
157 | 2 | Release found = null; |
158 | 1 | final Iterable<Release.Smart> rels = new Smarts<Release.Smart>( |
159 | 1 | this.iterate() |
160 | ); | |
161 | 1 | for (final Release.Smart rel : rels) { |
162 | 1 | if (rel.tag().equals(tag)) { |
163 | 1 | found = rel; |
164 | 1 | break; |
165 | } | |
166 | 0 | } |
167 | 1 | if (found == null) { |
168 | 0 | throw new IllegalArgumentException( |
169 | 0 | String.format("release not found by tag '%s'", tag) |
170 | ); | |
171 | } | |
172 | 1 | return found; |
173 | } | |
174 | } | |
175 | } |