1 /*******************************************************************************
2 * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
3 * Rapperswil, University of applied sciences and others
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Institute for Software - initial API and implementation
11 *******************************************************************************/
12 package org.eclipse.cdt.internal.ui.refactoring;
14 import java.util.Comparator;
15 import java.util.TreeSet;
17 import org.eclipse.ltk.core.refactoring.Change;
18 import org.eclipse.ltk.core.refactoring.CompositeChange;
20 import org.eclipse.cdt.ui.refactoring.CTextFileChange;
23 * @author Emanuel Graf
26 public class ChangeTreeSet {
28 private static final class ChangePositionComparator implements Comparator<CTextFileChange> {
29 public int compare(CTextFileChange o1, CTextFileChange o2) {
30 if(o1.getFile().equals(o2.getFile())){
31 return o2.getEdit().getOffset() - o1.getEdit().getOffset();
33 return o2.getFile().hashCode() - o1.getFile().hashCode();
37 private final TreeSet<CTextFileChange> changes = new TreeSet<CTextFileChange>(new ChangePositionComparator());
39 public void add(CTextFileChange change) {
43 public CompositeChange getCompositeChange(String name) {
44 CompositeChange allChanges = new CompositeChange(name);
46 for (Change change : changes) {
47 allChanges.add(change);
53 public String toString() {
54 return changes.toString();