Generify Refactoring never finishes

I tried to generify a single class in a fairly small project and refactoring
never finished. I let it run for 5 minutes and canceled it. It used to be
pretty much instanteneous


6 comments

On 2007-04-03 05:38:47 +0400, "Alex Roytman" <nospam@domain.com> said:

I tried to generify a single class in a fairly small project and refactoring
never finished. I let it run for 5 minutes and canceled it. It used to be
pretty much instanteneous


A code snippet please? Or at least a CPU snapshot.

Thanks,
Max

0

I tried to generify following class. Clicked Preview - it showed "Looking
for usages" dialog and never finished

package peacetech.gao.ogc.gctrack.jdo.helpers;

import com.peacetech.jdo.collections.Filter;

import java.util.*;

public class CollectionUtils {
private static final Comparator COMPARABLE = new Comparator() {
public int compare(Object o1, Object o2) {
throw new UnsupportedOperationException();
}
};

public static List toList(Collection c, Filter filter, boolean sort) {
return toList(c, filter, sort ? COMPARABLE : null, null);
}

public static List toList(Collection c, Filter filter, Comparator
comparator) {
return toList(c, filter, comparator, null);
}

public static List toList(Collection c, Filter filter, boolean sort, List
toList) {
return toList(c, filter, sort ? COMPARABLE : null, toList);
}

public static List toList(Collection c, Filter filter, Comparator
comparator, List toList) {
return toList(c, filter, comparator, toList, false);
}

public static List toList(Collection c, Filter filter, List toList,
boolean append) {
return toList(c, filter, null, toList, append);
}

private static List toList(Collection c, Filter filter, Comparator
comparator, List toList, boolean append) {
if (toList != null && !append) {
toList.clear();
}
if (c == null || c.isEmpty()) {
return (toList == null) ? new ArrayList() : toList;
}
if (filter == null) {
if (toList == null) {
toList = new ArrayList(c);
} else {
toList.addAll(c);
}
} else {
if (toList == null) {
toList = new ArrayList(c.size());
}
for (Iterator iter = c.iterator(); iter.hasNext();) {
Object o = iter.next();
if (filter.test(o)) {
toList.add(o);
}
}
}
if (comparator != null && toList.size() > 1) {
if (comparator == COMPARABLE) {
Collections.sort(toList);
} else {
Collections.sort(toList, comparator);
}
}
return toList;
}

public static Set toSet(Collection c, Filter filter, Set toSet, boolean
append) {
if (!append) {
toSet.clear();
}
if (c == null || c.isEmpty()) {
return toSet;
}
if (filter == null) {
toSet.addAll(c);
} else {
for (Iterator iter = c.iterator(); iter.hasNext();) {
Object o = iter.next();
if (filter.test(o)) {
toSet.add(o);
}
}
}
return toSet;
}

}


"Maxim Shafirov" <max@jetbrains.com> wrote in message
news:eut62k$spo$2@is.intellij.net...

On 2007-04-03 05:38:47 +0400, "Alex Roytman" <nospam@domain.com> said:

>
>> I tried to generify a single class in a fairly small project and
>> refactoring
>> never finished. I let it run for 5 minutes and canceled it. It used to be
>> pretty much instanteneous
>

A code snippet please? Or at least a CPU snapshot.

>

Thanks,
Max



0

On 2007-04-03 19:25:59 +0400, "Alex Roytman" <nospam@domain.com> said:

import java.util.*;

public class CollectionUtils {
private static final Comparator COMPARABLE = new Comparator() {
public int compare(Object o1, Object o2) {
throw new UnsupportedOperationException();
}
};

public static List toList(Collection c, Filter filter, boolean sort) {
return toList(c, filter, sort ? COMPARABLE : null, null);
}

public static List toList(Collection c, Filter filter, Comparator
comparator) {
return toList(c, filter, comparator, null);
}

public static List toList(Collection c, Filter filter, boolean sort, List
toList) {
return toList(c, filter, sort ? COMPARABLE : null, toList);
}

public static List toList(Collection c, Filter filter, Comparator
comparator, List toList) {
return toList(c, filter, comparator, toList, false);
}

public static List toList(Collection c, Filter filter, List toList,
boolean append) {
return toList(c, filter, null, toList, append);
}

private static List toList(Collection c, Filter filter, Comparator
comparator, List toList, boolean append) {
if (toList != null && !append) {
toList.clear();
}
if (c == null || c.isEmpty()) {
return (toList == null) ? new ArrayList() : toList;
}
if (filter == null) {
if (toList == null) {
toList = new ArrayList(c);
} else {
toList.addAll(c);
}
} else {
if (toList == null) {
toList = new ArrayList(c.size());
}
for (Iterator iter = c.iterator(); iter.hasNext();) {
Object o = iter.next();
if (filter.test(o)) {
toList.add(o);
}
}
}
if (comparator != null && toList.size() > 1) {
if (comparator == COMPARABLE) {
Collections.sort(toList);
} else {
Collections.sort(toList, comparator);
}
}
return toList;
}

public static Set toSet(Collection c, Filter filter, Set toSet, boolean
append) {
if (!append) {
toSet.clear();
}
if (c == null || c.isEmpty()) {
return toSet;
}
if (filter == null) {
toSet.addAll(c);
} else {
for (Iterator iter = c.iterator(); iter.hasNext();) {
Object o = iter.next();
if (filter.test(o)) {
toSet.add(o);
}
}
}
return toSet;
}

}


Works fine. Replaces 4 occurrences. Do you have any exception
stacktraces in the log, while performing this?

0

What options did you select in the refactoring?

0

No Exceptions in idea.log

Works fine. Replaces 4 occurrences. Do you have any exception stacktraces
in the log, while performing this?



0

All checked but exhaustive search

"Eugene Vigdorchik" <no_reply@jetbrains.com> wrote in message
news:21859853.1175615952880.JavaMail.itn@is.intellij.net...

What options did you select in the refactoring?



0

Please sign in to leave a comment.