PageRenderTime 61ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/cunningt/core-1
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. */
  22. package org.jboss.forge.project.dependencies;
  23. import org.jboss.forge.parser.java.util.Strings;
  24. import org.jboss.forge.project.facets.DependencyFacet.KnownRepository;
  25. /**
  26. * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
  27. *
  28. */
  29. public class DependencyRepositoryImpl implements DependencyRepository
  30. {
  31. private final String id;
  32. private final String url;
  33. public DependencyRepositoryImpl(final String id, final String url)
  34. {
  35. if (Strings.isNullOrEmpty(id))
  36. {
  37. throw new IllegalArgumentException("must specify repository id");
  38. }
  39. if (Strings.isNullOrEmpty(url))
  40. {
  41. throw new IllegalArgumentException("must specify repository url");
  42. }
  43. this.id = id;
  44. this.url = url;
  45. }
  46. public DependencyRepositoryImpl(KnownRepository repo)
  47. {
  48. this(repo.getId(), repo.getUrl());
  49. }
  50. @Override
  51. public String getId()
  52. {
  53. return id;
  54. }
  55. @Override
  56. public String getUrl()
  57. {
  58. return url;
  59. }
  60. @Override
  61. public String toString()
  62. {
  63. return "[id=" + id + ", url=" + url + "]";
  64. }
  65. @Override
  66. public int hashCode()
  67. {
  68. final int prime = 31;
  69. int result = 1;
  70. result = prime * result + ((id == null) ? 0 : id.hashCode());
  71. result = prime * result + ((url == null) ? 0 : url.hashCode());
  72. return result;
  73. }
  74. @Override
  75. public boolean equals(final Object obj)
  76. {
  77. if (this == obj)
  78. return true;
  79. if (obj == null)
  80. return false;
  81. if (getClass() != obj.getClass())
  82. return false;
  83. DependencyRepositoryImpl other = (DependencyRepositoryImpl) obj;
  84. if (id == null)
  85. {
  86. if (other.id != null)
  87. return false;
  88. }
  89. else if (!id.equals(other.id))
  90. return false;
  91. if (url == null)
  92. {
  93. if (other.url != null)
  94. return false;
  95. }
  96. else if (!url.equals(other.url))
  97. return false;
  98. return true;
  99. }
  100. }