Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 67fc7400f22c3c8a208c4e8e0d9d28627911d3d7 (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
/*******************************************************************************
 * Copyright (c) 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.internal.ui.history;

import java.util.ArrayList;
import com.ibm.icu.util.Calendar;

import org.eclipse.team.core.history.IFileRevision;

public class DateHistoryCategory extends AbstractHistoryCategory {
	
	private String name;
	private Calendar fromDate;
	private Calendar toDate;
	
	private IFileRevision[] revisions;
	
	/**
	 * Creates a new instance of DateCVSHistoryCategory. 
	 * 
	 * @param name	the name of this category
	 * @param fromDate	the start date for this category or <code>null</code> if you want everything up to the end date
	 * @param toDate	the end point for this category or <code>null</code> if you want just all entries in the
	 * start date
	 */
	public DateHistoryCategory(String name, Calendar fromDate, Calendar toDate){
		this.name = name;
		this.fromDate = fromDate;
		this.toDate = toDate;
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.team.internal.ccvs.ui.AbstractCVSHistoryCategory#getName()
	 */
	@Override
	public String getName() {
		return name;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.team.internal.ccvs.ui.AbstractCVSHistoryCategory#collectFileRevisions(org.eclipse.team.core.history.IFileRevision[], boolean)
	 */
	@Override
	public boolean collectFileRevisions(IFileRevision[] fileRevisions, boolean shouldRemove) {
		
		ArrayList pertinentRevisions = new ArrayList();
		ArrayList nonPertinentRevisions = new ArrayList();
		
		for (int i = 0; i < fileRevisions.length; i++) {
			//get the current file revision's date
			Calendar fileRevDate = Calendar.getInstance();
			fileRevDate.setTimeInMillis(fileRevisions[i].getTimestamp());
			
			int fileRevDay = fileRevDate.get(Calendar.DAY_OF_YEAR);
			int fileRevYear = fileRevDate.get(Calendar.YEAR);
			
			if (fromDate == null){
				//check to see if this revision is within the toDate range
				if (((fileRevDay<toDate.get(Calendar.DAY_OF_YEAR)) && (fileRevYear == toDate.get(Calendar.YEAR))) ||
					(fileRevYear < toDate.get(Calendar.YEAR))){
					pertinentRevisions.add(fileRevisions[i]);
				} else {
					//revision is equal or later then the to date, add to rejects list
					nonPertinentRevisions.add(fileRevisions[i]);
				}
			} else if (toDate == null){
				//check to see if this revision falls on the same day as the fromDate
				if ((fileRevDay == fromDate.get(Calendar.DAY_OF_YEAR)) &&
					(fileRevYear == fromDate.get(Calendar.YEAR))){
					pertinentRevisions.add(fileRevisions[i]);
				} else {
					nonPertinentRevisions.add(fileRevisions[i]);
				}
			} else {
				//check the range
				if ((fileRevYear >= fromDate.get(Calendar.YEAR)) &&
					(fileRevYear <= toDate.get(Calendar.YEAR)) &&
					(fileRevDay >= fromDate.get(Calendar.DAY_OF_YEAR)) &&
					(fileRevDay < toDate.get(Calendar.DAY_OF_YEAR))
				) {
					pertinentRevisions.add(fileRevisions[i]);
				} else {
					nonPertinentRevisions.add(fileRevisions[i]);
				}
			}			
		}
		
		//check mode
		if (shouldRemove){
			//TODO: pass in an object containing the file revision arrays and modify the contents
			/*IFileRevision[] tempRevision = (IFileRevision[]) nonPertinentRevisions.toArray(new IFileRevision[nonPertinentRevisions.size()]);
			System.arraycopy(tempRevision, 0, fileRevisions, 0, tempRevision.length);*/
		}
		
		if (pertinentRevisions.size() > 0){
			IFileRevision[] tempRevision = (IFileRevision[]) pertinentRevisions.toArray(new IFileRevision[pertinentRevisions.size()]);
			revisions = new IFileRevision[tempRevision.length];
			System.arraycopy(tempRevision, 0, revisions, 0, tempRevision.length);
			return true;
		}
		
		return false;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.team.internal.ccvs.ui.AbstractCVSHistoryCategory#getRevisions()
	 */
	@Override
	public IFileRevision[] getRevisions() {
		return revisions;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.team.internal.ccvs.ui.AbstractCVSHistoryCategory#hasRevisions()
	 */
	@Override
	public boolean hasRevisions() {
		if (revisions != null && revisions.length > 0)
			return true;
		
		return false;
	}

}

Back to the top