View Javadoc
1   /*
2    * dpkg - Debian Package library and the Debian Package Maven plugin
3    * (c) Copyright 2015 Gerrit Hohl
4    *
5    * This program is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU General Public License
7    * as published by the Free Software Foundation; either version 2
8    * of the License, or (at your option) any later version.
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with this program; if not, write to the Free Software
17   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18   */
19  package net.sourceforge.javadpkg.control.impl;
20  
21  import java.util.ArrayList;
22  import java.util.LinkedList;
23  import java.util.List;
24  
25  import net.sourceforge.javadpkg.control.Architecture;
26  import net.sourceforge.javadpkg.control.BinaryControl;
27  import net.sourceforge.javadpkg.control.Description;
28  import net.sourceforge.javadpkg.control.Homepage;
29  import net.sourceforge.javadpkg.control.PackageDependency;
30  import net.sourceforge.javadpkg.control.PackageMaintainer;
31  import net.sourceforge.javadpkg.control.PackageMultiArchitecture;
32  import net.sourceforge.javadpkg.control.PackageName;
33  import net.sourceforge.javadpkg.control.PackagePriority;
34  import net.sourceforge.javadpkg.control.PackageVersion;
35  import net.sourceforge.javadpkg.control.Section;
36  import net.sourceforge.javadpkg.control.Size;
37  
38  
39  /**
40   * <p>
41   * A {@link BinaryControl} implementation.
42   * </p>
43   *
44   * @author Gerrit Hohl (gerrit-hohl@users.sourceforge.net)
45   * @version <b>1.0</b>, 31.12.2015 by Gerrit Hohl
46   */
47  public class BinaryControlImpl extends AbstractControl implements BinaryControl {
48  
49  
50  	/** The name of the binary package. */
51  	private PackageName				packageName;
52  	/** The section. */
53  	private Section					section;
54  	/** The priority. */
55  	private PackagePriority			priority;
56  	/**
57  	 * <p>
58  	 * The flag if the package is essential for the system and can't be removed.
59  	 * </p>
60  	 */
61  	private Boolean					essential;
62  	/** The packages on which this package depends on. */
63  	private List<PackageDependency>	depends;
64  	/**
65  	 * <p>
66  	 * The packages which this package has a strong, but not absolute,
67  	 * dependency.
68  	 * </p>
69  	 */
70  	private List<PackageDependency>	recommends;
71  	/**
72  	 * <p>
73  	 * The packages which this package suggests to install for enhancing its
74  	 * functionality.
75  	 * </p>
76  	 */
77  	private List<PackageDependency>	suggest;
78  	/**
79  	 * <p>
80  	 * The packages which are enhanced in their functionality by this package.
81  	 * </p>
82  	 */
83  	private List<PackageDependency>	enhances;
84  	/**
85  	 * <p>
86  	 * The packages which must be installed before this package is installed.
87  	 * </p>
88  	 */
89  	private List<PackageDependency>	preDepends;
90  	/** The packages which will &quot;broken&quot; by this package. */
91  	private List<PackageDependency>	breaks;
92  	/** The packages which will be in conflict with this package. */
93  	private List<PackageDependency>	conflicts;
94  	/** The virtual packages which are provided by this package. */
95  	private List<PackageDependency>	provides;
96  	/** The packages which are replaced by this package. */
97  	private List<PackageDependency>	replaces;
98  	/** The packages which were used to built this package. */
99  	private List<PackageDependency>	builtUsing;
100 	/**
101 	 * <p>
102 	 * The estimate of the total amount of disk space required to install this
103 	 * package.
104 	 * </p>
105 	 */
106 	private Size					installedSize;
107 	/** The module aliases. */
108 	private String					moduleAliases;
109 	/** The description. */
110 	private Description				description;
111 
112 
113 	/**
114 	 * <p>
115 	 * Creates a binary control.
116 	 * </p>
117 	 */
118 	public BinaryControlImpl() {
119 		super();
120 		
121 		this.packageName = null;
122 		this.section = null;
123 		this.priority = null;
124 		this.essential = null;
125 		this.depends = new LinkedList<>();
126 		this.recommends = new LinkedList<>();
127 		this.suggest = new LinkedList<>();
128 		this.enhances = new LinkedList<>();
129 		this.preDepends = new LinkedList<>();
130 		this.breaks = new LinkedList<>();
131 		this.conflicts = new LinkedList<>();
132 		this.provides = new LinkedList<>();
133 		this.replaces = new LinkedList<>();
134 		this.builtUsing = new LinkedList<>();
135 		this.installedSize = null;
136 		this.moduleAliases = null;
137 		this.description = null;
138 	}
139 	
140 	
141 	/**
142 	 * <p>
143 	 * Creates a binary control.
144 	 * </p>
145 	 *
146 	 * @param source
147 	 *            The source package dependency.
148 	 * @param version
149 	 *            The version of the package.
150 	 * @param architecture
151 	 *            The architecture.
152 	 * @param multiArchitecture
153 	 *            The multiple architecture property.
154 	 * @param maintainer
155 	 *            The maintainer.
156 	 * @param homepage
157 	 *            The home-page.
158 	 * @param packageName
159 	 *            The name of the binary package.
160 	 * @param section
161 	 *            The section.
162 	 * @param priority
163 	 *            The priority.
164 	 * @param essential
165 	 *            The flag if the package is essential for the system and can't
166 	 *            be removed.
167 	 * @param depends
168 	 *            The packages on which this package depends on.
169 	 * @param recommends
170 	 *            The packages which this package has a strong, but not
171 	 *            absolute, dependency.
172 	 * @param suggest
173 	 *            The packages which this package suggests to install for
174 	 *            enhancing its functionality.
175 	 * @param enhances
176 	 *            The packages which are enhanced in their functionality by this
177 	 *            package.
178 	 * @param preDepends
179 	 *            The packages which must be installed before this package is
180 	 *            installed.
181 	 * @param breaks
182 	 *            The packages which will &quot;broken&quot; by this package.
183 	 * @param conflicts
184 	 *            The packages which will be in conflict with this package.
185 	 * @param provides
186 	 *            The virtual packages which are provided by this package.
187 	 * @param replaces
188 	 *            The packages which are replaced by this package.
189 	 * @param builtUsing
190 	 *            The packages which were used to built this package.
191 	 * @param installedSize
192 	 *            The estimate of the total amount of disk space required to
193 	 *            install this package.
194 	 * @param description
195 	 *            The description.
196 	 */
197 	public BinaryControlImpl(PackageDependency source, PackageVersion version, Architecture architecture,
198 			PackageMultiArchitecture multiArchitecture, PackageMaintainer maintainer, Homepage homepage,
199 			PackageName packageName, Section section, PackagePriority priority, Boolean essential,
200 			List<PackageDependency> depends, List<PackageDependency> recommends, List<PackageDependency> suggest,
201 			List<PackageDependency> enhances, List<PackageDependency> preDepends, List<PackageDependency> breaks,
202 			List<PackageDependency> conflicts, List<PackageDependency> provides, List<PackageDependency> replaces,
203 			List<PackageDependency> builtUsing, Size installedSize, Description description) {
204 			
205 		super(source, version, architecture, multiArchitecture, maintainer, homepage);
206 		
207 		this.packageName = packageName;
208 		this.section = section;
209 		this.priority = priority;
210 		this.essential = essential;
211 		this.depends = getList(depends);
212 		this.recommends = getList(recommends);
213 		this.suggest = getList(suggest);
214 		this.enhances = getList(enhances);
215 		this.preDepends = getList(preDepends);
216 		this.breaks = getList(breaks);
217 		this.conflicts = getList(conflicts);
218 		this.provides = getList(provides);
219 		this.replaces = getList(replaces);
220 		this.builtUsing = getList(builtUsing);
221 		this.installedSize = null;
222 		this.description = null;
223 	}
224 
225 
226 	/**
227 	 * <p>
228 	 * Returns a list.
229 	 * </p>
230 	 * <p>
231 	 * If a list is passed a copy of that list will be returned. Otherwise an
232 	 * empty list will be returned.
233 	 * </p>
234 	 *
235 	 * @param list
236 	 *            The list (optional).
237 	 * @return The list.
238 	 */
239 	private static <T> List<T> getList(List<T> list) {
240 		if (list == null)
241 			return new LinkedList<>();
242 		return (new LinkedList<>(list));
243 	}
244 	
245 	
246 	@Override
247 	public PackageName getPackage() {
248 		return this.packageName;
249 	}
250 
251 
252 	/**
253 	 * <p>
254 	 * Sets the name of the binary package.
255 	 * </p>
256 	 *
257 	 * @param packageName
258 	 *            The name.
259 	 */
260 	public void setPackage(PackageName packageName) {
261 		this.packageName = packageName;
262 	}
263 	
264 	
265 	@Override
266 	public Section getSection() {
267 		return this.section;
268 	}
269 
270 
271 	/**
272 	 * <p>
273 	 * Sets the section.
274 	 * </p>
275 	 *
276 	 * @param section
277 	 *            The section.
278 	 */
279 	public void setSection(Section section) {
280 		this.section = section;
281 	}
282 	
283 	
284 	@Override
285 	public PackagePriority getPriority() {
286 		return this.priority;
287 	}
288 	
289 	
290 	/**
291 	 * <p>
292 	 * Sets the priority.
293 	 * </p>
294 	 *
295 	 * @param priority
296 	 *            The priority.
297 	 */
298 	public void setPriority(PackagePriority priority) {
299 		this.priority = priority;
300 	}
301 	
302 	
303 	@Override
304 	public Boolean getEssential() {
305 		return this.essential;
306 	}
307 	
308 	
309 	/**
310 	 * <p>
311 	 * Sets the flag if the package is essential for the system and can't be
312 	 * removed.
313 	 * </p>
314 	 *
315 	 * @param essential
316 	 *            The flag.
317 	 */
318 	public void setEssential(Boolean essential) {
319 		this.essential = essential;
320 	}
321 	
322 	
323 	@Override
324 	public List<PackageDependency> getDepends() {
325 		return (new ArrayList<>(this.depends));
326 	}
327 
328 
329 	/**
330 	 * <p>
331 	 * Sets the the packages on which this package depends on.
332 	 * </p>
333 	 *
334 	 * @param depends
335 	 *            The dependencies.
336 	 */
337 	public void setDepends(List<PackageDependency> depends) {
338 		this.depends = getList(depends);
339 	}
340 	
341 	
342 	@Override
343 	public List<PackageDependency> getRecommends() {
344 		return (new ArrayList<>(this.recommends));
345 	}
346 	
347 	
348 	/**
349 	 * <p>
350 	 * Sets the packages which this package has a strong, but not absolute,
351 	 * dependency.
352 	 * </p>
353 	 *
354 	 * @param recommends
355 	 *            The dependencies.
356 	 */
357 	public void setRecommends(List<PackageDependency> recommends) {
358 		this.recommends = getList(recommends);
359 	}
360 
361 
362 	@Override
363 	public List<PackageDependency> getSuggests() {
364 		return (new ArrayList<>(this.suggest));
365 	}
366 	
367 	
368 	/**
369 	 * <p>
370 	 * Sets the packages which this package suggests to install for enhancing
371 	 * its functionality.
372 	 * </p>
373 	 *
374 	 * @param suggest
375 	 *            The dependencies.
376 	 */
377 	public void setSuggests(List<PackageDependency> suggest) {
378 		this.suggest = getList(suggest);
379 	}
380 
381 
382 	@Override
383 	public List<PackageDependency> getEnhances() {
384 		return (new ArrayList<>(this.enhances));
385 	}
386 	
387 	
388 	/**
389 	 * <p>
390 	 * Sets the packages which are enhanced in their functionality by this
391 	 * package.
392 	 * </p>
393 	 *
394 	 * @param enhances
395 	 *            The dependencies.
396 	 */
397 	public void setEnhances(List<PackageDependency> enhances) {
398 		this.enhances = getList(enhances);
399 	}
400 
401 
402 	@Override
403 	public List<PackageDependency> getPreDepends() {
404 		return (new ArrayList<>(this.preDepends));
405 	}
406 	
407 	
408 	/**
409 	 * <p>
410 	 * Sets the packages which must be installed before this package is
411 	 * installed.
412 	 * </p>
413 	 *
414 	 * @param preDepends
415 	 *            The dependencies.
416 	 */
417 	public void setPreDepends(List<PackageDependency> preDepends) {
418 		this.preDepends = getList(preDepends);
419 	}
420 
421 
422 	@Override
423 	public List<PackageDependency> getBreaks() {
424 		return (new ArrayList<>(this.breaks));
425 	}
426 	
427 	
428 	/**
429 	 * <p>
430 	 * Sets the packages which will "broken" by this package.
431 	 * </p>
432 	 *
433 	 * @param breaks
434 	 *            The dependencies.
435 	 */
436 	public void setBreaks(List<PackageDependency> breaks) {
437 		this.breaks = getList(breaks);
438 	}
439 
440 
441 	@Override
442 	public List<PackageDependency> getConflicts() {
443 		return (new ArrayList<>(this.conflicts));
444 	}
445 	
446 	
447 	/**
448 	 * <p>
449 	 * Sets the packages which will be in conflict with this package.
450 	 * </p>
451 	 *
452 	 * @param conflicts
453 	 *            The dependencies.
454 	 */
455 	public void setConflicts(List<PackageDependency> conflicts) {
456 		this.conflicts = getList(conflicts);
457 	}
458 
459 
460 	@Override
461 	public List<PackageDependency> getProvides() {
462 		return (new ArrayList<>(this.provides));
463 	}
464 	
465 	
466 	/**
467 	 * <p>
468 	 * Sets the virtual packages which are provided by this package.
469 	 * </p>
470 	 *
471 	 * @param provides
472 	 *            The dependencies.
473 	 */
474 	public void setProvides(List<PackageDependency> provides) {
475 		this.provides = getList(provides);
476 	}
477 
478 
479 	@Override
480 	public List<PackageDependency> getReplaces() {
481 		return (new ArrayList<>(this.replaces));
482 	}
483 	
484 	
485 	/**
486 	 * <p>
487 	 * Sets the packages which are replaced by this package.
488 	 * </p>
489 	 *
490 	 * @param replaces
491 	 *            The dependencies.
492 	 */
493 	public void setReplaces(List<PackageDependency> replaces) {
494 		this.replaces = getList(replaces);
495 	}
496 
497 
498 	@Override
499 	public List<PackageDependency> getBuiltUsing() {
500 		return (new ArrayList<>(this.builtUsing));
501 	}
502 	
503 	
504 	/**
505 	 * <p>
506 	 * Sets the packages which were used to built this package.
507 	 * </p>
508 	 *
509 	 * @param builtUsing
510 	 *            The dependencies.
511 	 */
512 	public void setBuiltUsing(List<PackageDependency> builtUsing) {
513 		this.builtUsing = getList(builtUsing);
514 	}
515 
516 
517 	@Override
518 	public Size getInstalledSize() {
519 		return this.installedSize;
520 	}
521 	
522 	
523 	/**
524 	 * <p>
525 	 * Sets an estimate of the total amount of disk space required to install
526 	 * this package.
527 	 * </p>
528 	 *
529 	 * @param installedSize
530 	 *            The installed size.
531 	 */
532 	public void setInstalledSize(Size installedSize) {
533 		this.installedSize = installedSize;
534 	}
535 	
536 	
537 	@Override
538 	public String getModuleAliases() {
539 		return this.moduleAliases;
540 	}
541 	
542 	
543 	/**
544 	 * <p>
545 	 * Sets the module aliases.
546 	 * </p>
547 	 *
548 	 * @param moduleAliases
549 	 *            The module aliases.
550 	 */
551 	public void setModuleAliases(String moduleAliases) {
552 		this.moduleAliases = moduleAliases;
553 	}
554 	
555 	
556 	@Override
557 	public Description getDescription() {
558 		return this.description;
559 	}
560 	
561 	
562 	/**
563 	 * <p>
564 	 * Sets the description.
565 	 * </p>
566 	 *
567 	 * @param description
568 	 *            The description.
569 	 */
570 	public void setDescription(Description description) {
571 		this.description = description;
572 	}
573 	
574 	
575 }