1 /**
2 * Copyright 2006-2016 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.mybatis.generator.api.dom.xml;
17
18 /**
19 * The Class Attribute.
20 *
21 * @author Jeff Butler
22 */
23 public class Attribute implements Comparable<Attribute>{
24
25 /** The name. */
26 private String name;
27
28 /** The value. */
29 private String value;
30
31 /**
32 * Instantiates a new attribute.
33 *
34 * @param name
35 * the name
36 * @param value
37 * the value
38 */
39 public Attribute(String name, String value) {
40 super();
41 this.name = name;
42 this.value = value;
43 }
44
45 /**
46 * Gets the name.
47 *
48 * @return Returns the name.
49 */
50 public String getName() {
51 return name;
52 }
53
54 /**
55 * Gets the value.
56 *
57 * @return Returns the value.
58 */
59 public String getValue() {
60 return value;
61 }
62
63 /**
64 * Gets the formatted content.
65 *
66 * @return the formatted content
67 */
68 public String getFormattedContent() {
69 StringBuilder sb = new StringBuilder();
70 sb.append(name);
71 sb.append("=\""); //$NON-NLS-1$
72 sb.append(value);
73 sb.append('\"');
74
75 return sb.toString();
76 }
77
78 @Override
79 public int compareTo(Attribute o) {
80 if (this.name == null) {
81 return o.name == null ? 0: -1;
82 } else {
83 if (o.name == null) {
84 return 0;
85 } else {
86 return this.name.compareTo(o.name);
87 }
88 }
89 }
90 }