File: MediaList.java

package info (click to toggle)
gpsprune 26.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,824 kB
  • sloc: java: 52,154; sh: 25; makefile: 21; python: 15
file content (236 lines) | stat: -rw-r--r-- 4,345 bytes parent folder | download | duplicates (2)
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
package tim.prune.data;

import java.util.ArrayList;

/**
 * Class to hold a list of MediaObjects, either Photos or Audio files
 */
public class MediaList<T extends MediaObject>
{
	/** list of media objects */
	protected final ArrayList<T> _media = new ArrayList<>();

	/**
	 * @return the number of media in the list
	 */
	public int getCount() {
		return _media.size();
	}

	/**
	 * Add an object to the list
	 * @param inObject object to add
	 */
	public void add(T inObject)
	{
		if (inObject != null) {
			_media.add(inObject);
		}
	}

	/**
	 * Add an object to the list at a specified index (used for undo)
	 * @param inObject object to add
	 * @param inIndex index at which to add
	 */
	public void add(T inObject, int inIndex)
	{
		if (inObject != null) {
			_media.add(inIndex, inObject);
		}
	}


	/**
	 * Remove the selected media from the list
	 * @param inIndex index number to remove
	 */
	public void delete(int inIndex)
	{
		// Maybe throw exception if this fails?
		_media.remove(inIndex);
	}

	/**
	 * Remove the selected media from the list
	 * @param inMedia object to remove
	 */
	public void delete(T inMedia)
	{
		int index = getIndexOf(inMedia);
		if (index > -1) {
			_media.remove(index);
		}
	}

	/**
	 * Checks if the specified object is already in the list
	 * @param inMedia media object to check
	 * @return true if it's already in the list
	 */
	public boolean contains(T inMedia) {
		return getIndexOf(inMedia) > -1;
	}

	/**
	 * Get the index of the given media
	 * @param inMedia object to check
	 * @return index of this object in the list, or -1 if not found
	 */
	public int getIndexOf(T inMedia)
	{
		// Check if we need to check
		final int num = getCount();
		if (num <= 0 || inMedia == null) {
			return -1;
		}
		// Loop over list
		for (int i=0; i<num; i++)
		{
			T m = _media.get(i);
			if (m == inMedia) {
				return i;
			}
		}
		// not found
		return -1;
	}

	/**
	 * Checks if a media object _like_ the given one is already in the list
	 * @param inMedia media object to check
	 * @return true if there's a duplicate one already in the list
	 */
	public boolean hasDuplicate(T inMedia)
	{
		final int num = getCount();
		if (num <= 0 || inMedia == null) {
			return false;
		}
		for (int i=0; i<num; i++)
		{
			T m = _media.get(i);
			if (inMedia.equals(m)) {
				return true;
			}
		}
		return false;
	}

	/**
	 * Get the media at the given index
	 * @param inIndex index number, starting at 0
	 * @return specified object
	 */
	public T get(int inIndex)
	{
		if (inIndex < 0 || inIndex >= getCount()) {
			return null;
		}
		return _media.get(inIndex);
	}

	/**
	 * @return true if this list has any media
	 */
	public boolean hasAny() {
		return !_media.isEmpty();
	}

	/**
	 * @return true if list contains correlated media
	 */
	public boolean hasCorrelatedMedia()
	{
		for (T m : _media)
		{
			if (m.getDataPoint() != null) {
				return true;
			}
		}
		return false;
	}

	/**
	 * @return true if list contains uncorrelated media
	 */
	public boolean hasUncorrelatedMedia()
	{
		for (T m : _media)
		{
			if (m.getDataPoint() == null && m.hasTimestamp()) {
				return true;
			}
		}
		return false;
	}


	/**
	 * Remove all correlated media from the list
	 */
	public void removeCorrelatedMedia()
	{
		if (getCount() > 0)
		{
			// Construct new list to copy into
			ArrayList<T> listCopy = new ArrayList<>();
			// Loop over list
			for (T m : _media)
			{
				// Copy media if it has no point
				if (m != null)
				{
					if (m.getDataPoint() == null) {
						listCopy.add(m);
					}
				}
			}
			// Switch list contents
			_media.clear();
			_media.addAll(listCopy);
		}
	}

	/**
	 * @return true if any of the media objects have Files
	 */
	public boolean hasMediaWithFile()
	{
		for (T m: _media)
		{
			if (m.getFile() != null) {
				return true;
			}
		}
		return false;
	}

	/**
	 * @return true if there are any modified media in the list
	 */
	public boolean hasModifiedMedia()
	{
		for (T m : _media)
		{
			if (m.isModified()) {
				return true;
			}
		}
		return false;
	}

	/**
	 * Restore contents from other MediaList
	 * @param inOther MediaList with cloned contents
	 */
	public void restore(MediaList<T> inOther)
	{
		_media.clear();
		if (inOther != null && inOther.getCount() > 0)
		{
			// Copy contents from other list
			_media.addAll(inOther._media);
		}
	}
}