Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1819714e70308ff6c43fa47e3cef1d018f4023a2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
 * Copyright (c) 2014, 2015 Eike Stepper (Loehne, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v2.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v20.html
 *
 * Contributors:
 *    Eike Stepper - initial API and implementation
 */
package org.eclipse.oomph.setup;

import org.eclipse.oomph.util.StringUtil;

/**
 * @author Eike Stepper
 */
public final class LicenseInfo
{
  private static final String SEPARATOR = " ";

  private final String uuid;

  private final String name;

  public LicenseInfo(String string)
  {
    if (string == null)
    {
      throw new IllegalArgumentException("string is null"); //$NON-NLS-1$
    }

    int pos = string.indexOf(SEPARATOR);
    if (pos != -1)
    {
      uuid = string.substring(0, pos);
      name = string.substring(pos + 1).trim();
    }
    else
    {
      uuid = string;
      name = null;
    }
  }

  public LicenseInfo(String uuid, String name)
  {
    if (uuid == null)
    {
      throw new IllegalArgumentException("uuid is null"); //$NON-NLS-1$
    }

    if (uuid.indexOf(' ') != -1)
    {
      throw new IllegalArgumentException("uuid contains a space"); //$NON-NLS-1$
    }

    this.uuid = uuid;
    this.name = name;
  }

  public String getUUID()
  {
    return uuid;
  }

  public String getName()
  {
    return name;
  }

  public String getLabel()
  {
    if (!StringUtil.isEmpty(name))
    {
      return name;
    }

    return uuid;
  }

  @Override
  public int hashCode()
  {
    final int prime = 31;
    int result = 1;
    result = prime * result + (uuid == null ? 0 : uuid.hashCode());
    return result;
  }

  @Override
  public boolean equals(Object obj)
  {
    if (this == obj)
    {
      return true;
    }

    if (obj == null)
    {
      return false;
    }

    if (getClass() != obj.getClass())
    {
      return false;
    }

    LicenseInfo other = (LicenseInfo)obj;
    if (uuid == null)
    {
      if (other.uuid != null)
      {
        return false;
      }
    }
    else if (!uuid.equals(other.uuid))
    {
      return false;
    }

    return true;
  }

  @Override
  public String toString()
  {
    String string = uuid;
    if (!StringUtil.isEmpty(name))
    {
      string += SEPARATOR + name;
    }

    return string;
  }

  public static String getFirstLine(String body)
  {
    int i = body.indexOf('\n');
    int j = body.indexOf('\r');
    if (i > 0)
    {
      if (j > 0)
      {
        return body.substring(0, i < j ? i : j);
      }

      return body.substring(0, i);
    }

    if (j > 0)
    {
      return body.substring(0, j);
    }

    return body;
  }
}

Back to the top