001/* 002 * (C) Copyright 2014 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Anahide Tchertchian 018 */ 019package org.nuxeo.targetplatforms.api.impl; 020 021import java.util.ArrayList; 022import java.util.List; 023 024import org.nuxeo.targetplatforms.api.TargetPackage; 025 026/** 027 * @since 5.7.1 028 */ 029public class TargetPackageImpl extends TargetImpl implements TargetPackage, Comparable<TargetPackage> { 030 031 private static final long serialVersionUID = 1L; 032 033 protected List<String> dependencies; 034 035 protected TargetPackage parent; 036 037 // needed by GWT serialization 038 protected TargetPackageImpl() { 039 super(); 040 } 041 042 public TargetPackageImpl(String id, String name, String version, String refVersion, String label) { 043 super(id, name, version, refVersion, label); 044 dependencies = new ArrayList<String>(); 045 } 046 047 public void addDependency(String dependency) { 048 dependencies.add(dependency); 049 } 050 051 @Override 052 public List<String> getDependencies() { 053 return dependencies; 054 } 055 056 public void setDependencies(List<String> dependencies) { 057 if (dependencies == null) { 058 this.dependencies = null; 059 } else { 060 this.dependencies = new ArrayList<String>(dependencies); 061 } 062 } 063 064 @Override 065 public TargetPackage getParent() { 066 return parent; 067 } 068 069 public void setParent(TargetPackage parent) { 070 this.parent = parent; 071 } 072 073 @Override 074 public int compareTo(TargetPackage o) { 075 // compare first on name, then on version 076 int comp = getName().compareTo(o.getName()); 077 if (comp == 0) { 078 comp = getVersion().compareTo(o.getVersion()); 079 } 080 return comp; 081 } 082 083}