1 | package org.farng.mp3; |
2 | |
3 | /** |
4 | * This class represents parts of tags. It contains methods that they all use use. ID3v2 tags have frames. Lyrics3 tags |
5 | * have fields. ID3v1 tags do not have parts. It also contains thier header while the body contains the actual |
6 | * fragments. |
7 | * |
8 | * @author Eric Farng |
9 | * @version $Revision: 1.2 $ |
10 | */ |
11 | public abstract class AbstractMP3Fragment extends AbstractMP3FileItem { |
12 | |
13 | /** |
14 | * actual data this fragment holds |
15 | */ |
16 | private AbstractMP3FragmentBody body; |
17 | |
18 | /** |
19 | * Creates a new AbstractMP3Fragment object. |
20 | */ |
21 | protected AbstractMP3Fragment() { |
22 | super(); |
23 | } |
24 | |
25 | /** |
26 | * Creates a new AbstractMP3Fragment object. |
27 | */ |
28 | protected AbstractMP3Fragment(final AbstractMP3FragmentBody body) { |
29 | super(); |
30 | this.body = body; |
31 | } |
32 | |
33 | /** |
34 | * Creates a new AbstractMP3Fragment object. |
35 | */ |
36 | protected AbstractMP3Fragment(final AbstractMP3Fragment copyObject) { |
37 | super(copyObject); |
38 | final AbstractMP3FragmentBody copyObjectBody = copyObject.getBody(); |
39 | body = (AbstractMP3FragmentBody) TagUtility.copyObject(copyObjectBody); |
40 | } |
41 | |
42 | /** |
43 | * Sets the body object for this fragment. The body object contains the actual information for the fragment. |
44 | * |
45 | * @param body the body object |
46 | */ |
47 | public void setBody(final AbstractMP3FragmentBody body) { |
48 | this.body = body; |
49 | } |
50 | |
51 | /** |
52 | * Returns the body object for this fragment. The body object contains the actual information for the fragment. |
53 | * |
54 | * @return the body object |
55 | */ |
56 | public AbstractMP3FragmentBody getBody() { |
57 | return body; |
58 | } |
59 | |
60 | /** |
61 | * Returns true if this object and it's body is a subset of the argument. This object is a subset if the argument is |
62 | * the same class. |
63 | * |
64 | * @param object object to determine if subset of |
65 | * |
66 | * @return true if this object and it's body is a subset of the argument. |
67 | */ |
68 | public boolean isSubsetOf(final Object object) { |
69 | final boolean subsetOf; |
70 | final AbstractMP3FragmentBody localBody = body; |
71 | if (object == null) { |
72 | subsetOf = false; |
73 | } else if (!(object instanceof AbstractMP3Fragment)) { |
74 | subsetOf = false; |
75 | } else { |
76 | final AbstractMP3FragmentBody superSetBody = ((AbstractMP3Fragment) object).getBody(); |
77 | if (localBody == null && superSetBody == null) { |
78 | subsetOf = true; |
79 | } else { |
80 | subsetOf = localBody != null && |
81 | superSetBody != null && |
82 | localBody.isSubsetOf(superSetBody) && |
83 | super.isSubsetOf(object); |
84 | } |
85 | } |
86 | return subsetOf; |
87 | } |
88 | |
89 | /** |
90 | * Returns true if this object and its body equals the argument and its body. this object is equal if and only if |
91 | * they are the same class and have the same <code>getIdentifier</code> id string. |
92 | * |
93 | * @param obj object to determine equality of |
94 | * |
95 | * @return true if this object and its body equals the argument and its body. |
96 | */ |
97 | public boolean equals(final Object obj) { |
98 | final boolean equals; |
99 | if (obj instanceof AbstractMP3Fragment) { |
100 | final AbstractMP3Fragment abstractMP3Fragment = (AbstractMP3Fragment) obj; |
101 | final String equalsIdentifier = abstractMP3Fragment.getIdentifier(); |
102 | final String thisIdentifier = getIdentifier(); |
103 | if (thisIdentifier.equals(equalsIdentifier)) { |
104 | final AbstractMP3FragmentBody equalsBody = abstractMP3Fragment.getBody(); |
105 | final AbstractMP3FragmentBody thisBody = getBody(); |
106 | if (thisBody.equals(equalsBody)) { |
107 | equals = super.equals(obj); |
108 | } else { |
109 | equals = false; |
110 | } |
111 | } else { |
112 | equals = false; |
113 | } |
114 | } else { |
115 | equals = false; |
116 | } |
117 | return equals; |
118 | } |
119 | } |