PageRenderTime 43ms CodeModel.GetById 37ms app.highlight 5ms RepoModel.GetById 0ms app.codeStats 0ms

/shell-api/src/main/java/org/jboss/forge/project/dependencies/DependencyRepositoryImpl.java

https://github.com/pmuir/forge-core
Java | 110 lines | 75 code | 10 blank | 25 comment | 22 complexity | 73d71377acbe21c7f108f11002a929e3 MD5 | raw file
  1/*
  2 * JBoss, Home of Professional Open Source
  3 * Copyright 2011, Red Hat, Inc., and individual contributors
  4 * by the @authors tag. See the copyright.txt in the distribution for a
  5 * full listing of individual contributors.
  6 *
  7 * This is free software; you can redistribute it and/or modify it
  8 * under the terms of the GNU Lesser General Public License as
  9 * published by the Free Software Foundation; either version 2.1 of
 10 * the License, or (at your option) any later version.
 11 *
 12 * This software is distributed in the hope that it will be useful,
 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 15 * Lesser General Public License for more details.
 16 *
 17 * You should have received a copy of the GNU Lesser General Public
 18 * License along with this software; if not, write to the Free
 19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 21 */
 22package org.jboss.forge.project.dependencies;
 23
 24import org.jboss.forge.parser.java.util.Strings;
 25import org.jboss.forge.project.facets.DependencyFacet.KnownRepository;
 26
 27/**
 28 * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
 29 * 
 30 */
 31public class DependencyRepositoryImpl implements DependencyRepository
 32{
 33   private final String id;
 34   private final String url;
 35
 36   public DependencyRepositoryImpl(final String id, final String url)
 37   {
 38      if (Strings.isNullOrEmpty(id))
 39      {
 40         throw new IllegalArgumentException("must specify repository id");
 41      }
 42      if (Strings.isNullOrEmpty(url))
 43      {
 44         throw new IllegalArgumentException("must specify repository url");
 45      }
 46      this.id = id;
 47      this.url = url;
 48   }
 49
 50   public DependencyRepositoryImpl(KnownRepository repo)
 51   {
 52      this(repo.getId(), repo.getUrl());
 53   }
 54
 55   @Override
 56   public String getId()
 57   {
 58      return id;
 59   }
 60
 61   @Override
 62   public String getUrl()
 63   {
 64      return url;
 65   }
 66
 67   @Override
 68   public String toString()
 69   {
 70      return "[id=" + id + ", url=" + url + "]";
 71   }
 72
 73   @Override
 74   public int hashCode()
 75   {
 76      final int prime = 31;
 77      int result = 1;
 78      result = prime * result + ((id == null) ? 0 : id.hashCode());
 79      result = prime * result + ((url == null) ? 0 : url.hashCode());
 80      return result;
 81   }
 82
 83   @Override
 84   public boolean equals(final Object obj)
 85   {
 86      if (this == obj)
 87         return true;
 88      if (obj == null)
 89         return false;
 90      if (getClass() != obj.getClass())
 91         return false;
 92      DependencyRepositoryImpl other = (DependencyRepositoryImpl) obj;
 93      if (id == null)
 94      {
 95         if (other.id != null)
 96            return false;
 97      }
 98      else if (!id.equals(other.id))
 99         return false;
100      if (url == null)
101      {
102         if (other.url != null)
103            return false;
104      }
105      else if (!url.equals(other.url))
106         return false;
107      return true;
108   }
109
110}