GitReference: better javadocs, style

This commit is contained in:
Kirill Likhodedov
2012-10-18 17:53:59 +04:00
parent 32a59dc39f
commit 6c4b6af547
@@ -17,31 +17,20 @@ package git4idea;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
/**
* The base class for named git references
* The base class for named git references, like branches and tags.
*/
public abstract class GitReference implements Comparable<GitReference> {
/**
* The name of the reference
*/
protected final String myName;
/**
* The constructor
*
* @param name the used name
*/
@NotNull protected final String myName;
public GitReference(@NotNull String name) {
myName = new String(name);
}
/**
* @return the local name of the reference
* @return the name of the reference, e.g. "origin/master" or "feature".
* @see #getFullName()
*/
@NotNull
public String getName() {
@@ -49,70 +38,28 @@ public abstract class GitReference implements Comparable<GitReference> {
}
/**
* @return the full name of the object
* @return the full name of the reference, e.g. "refs/remotes/origin/master" or "refs/heads/master".
*/
@NotNull
public abstract String getFullName();
/**
* @return the full name for the reference ({@link #getFullName()}.
*/
@Override
public String toString() {
return getFullName();
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(final Object obj) {
public boolean equals(Object obj) {
return obj instanceof GitReference &&
toString().equals(obj.toString()); //To change body of overridden methods use File | Settings | File Templates.
toString().equals(obj.toString());
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return toString().hashCode();
}
/**
* {@inheritDoc}
*/
public int compareTo(final GitReference o) {
public int compareTo(GitReference o) {
return o == null ? 1 : getFullName().compareTo(o.getFullName());
}
/**
* Get name clashes for the for the sequence of the collections
*
* @param collections the collection list
* @return the conflict set
*/
public static Set<String> getNameClashes(Collection<? extends GitReference>... collections) {
ArrayList<HashSet<String>> individual = new ArrayList<HashSet<String>>();
// collect individual key sets
for (Collection<? extends GitReference> c : collections) {
HashSet<String> s = new HashSet<String>();
individual.add(s);
for (GitReference r : c) {
s.add(r.getName());
}
}
HashSet<String> rc = new HashSet<String>();
// all pairs from array
for (int i = 0; i < collections.length - 1; i++) {
HashSet<String> si = individual.get(i);
for (int j = i + 1; j < collections.length; j++) {
HashSet<String> sj = individual.get(i);
final HashSet<String> copy = new HashSet<String>(si);
copy.retainAll(sj);
rc.addAll(copy);
}
}
return rc;
}
}