Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
66 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,6 @@ | |
import com.intellij.openapi.util.Pair; | ||
import com.intellij.openapi.vfs.VirtualFile; | ||
import com.intellij.openapi.vfs.VirtualFileManager; | ||
import com.intellij.util.containers.ContainerUtil; | ||
import org.apache.commons.lang.StringUtils; | ||
import org.apache.commons.lang.builder.HashCodeBuilder; | ||
import org.jetbrains.annotations.NotNull; | ||
|
@@ -37,8 +36,6 @@ | |
import java.io.DataOutput; | ||
import java.io.IOException; | ||
import java.io.Serializable; | ||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
|
@@ -58,8 +55,8 @@ public class IgnoreEntryOccurrence implements Serializable { | |
private VirtualFile file; | ||
|
||
/** Collection of ignore entries converted to {@link Pattern}. */ | ||
@NotNull | ||
private final List<Pair<Matcher, Boolean>> items = ContainerUtil.newArrayList(); | ||
@Nullable | ||
private Pair<Pattern, Boolean>[] items; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
/** | ||
* Constructor. | ||
|
@@ -97,7 +94,15 @@ public IgnoreEntryOccurrence(@NotNull String url, @Nullable VirtualFile file) { | |
*/ | ||
@Override | ||
public int hashCode() { | ||
return new HashCodeBuilder().append(url).append(items.toString()).toHashCode(); | ||
HashCodeBuilder builder = new HashCodeBuilder().append(url); | ||
|
||
if (items != null) { | ||
for (Pair<Pattern, Boolean> item : items) { | ||
builder = builder.append(item.first).append(item.second); | ||
} | ||
} | ||
|
||
return builder.toHashCode(); | ||
} | ||
|
||
/** | ||
|
@@ -113,9 +118,16 @@ public boolean equals(@Nullable Object obj) { | |
} | ||
|
||
final IgnoreEntryOccurrence entry = (IgnoreEntryOccurrence) obj; | ||
boolean equals = url.equals(entry.url) && items.size() == entry.items.size(); | ||
for (int i = 0; i < items.size(); i++) { | ||
equals = equals && items.get(i).toString().equals(entry.items.get(i).toString()); | ||
if (items == null && entry.items == null) { | ||
return true; | ||
} | ||
if (items == null || entry.items == null) { | ||
return false; | ||
} | ||
|
||
boolean equals = url.equals(entry.url) && items.length == entry.items.length; | ||
for (int i = 0; i < items.length; i++) { | ||
equals = equals && items[i].toString().equals(entry.items[i].toString()); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
fractile81
|
||
} | ||
|
||
return equals; | ||
|
@@ -139,19 +151,14 @@ public VirtualFile getFile() { | |
* | ||
* @return entries | ||
*/ | ||
@NotNull | ||
public List<Pair<Matcher, Boolean>> getItems() { | ||
@Nullable | ||
public Pair<Pattern, Boolean>[] getItems() { | ||
return items; | ||
} | ||
|
||
/** | ||
* Adds new element to {@link #items}. | ||
* | ||
* @param matcher entry converted to {@link Matcher} | ||
* @param isNegated entry is negated | ||
*/ | ||
public void add(@NotNull Matcher matcher, boolean isNegated) { | ||
items.add(Pair.create(matcher, isNegated)); | ||
/** Set entries for current file. */ | ||
public void setItems(@Nullable Pair<Pattern, Boolean>[] items) { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
this.items = items; | ||
} | ||
|
||
/** | ||
|
@@ -164,9 +171,9 @@ public void add(@NotNull Matcher matcher, boolean isNegated) { | |
public static synchronized void serialize(@NotNull DataOutput out, @NotNull IgnoreEntryOccurrence entry) | ||
throws IOException { | ||
out.writeUTF(entry.url); | ||
out.writeInt(entry.items.size()); | ||
for (Pair<Matcher, Boolean> item : entry.items) { | ||
out.writeUTF(item.first.pattern().pattern()); | ||
out.writeInt(entry.items == null ? 0 : entry.items.length); | ||
for (Pair<Pattern, Boolean> item : entry.items) { | ||
out.writeUTF(item.first.pattern()); | ||
out.writeBoolean(item.second); | ||
} | ||
} | ||
|
@@ -186,11 +193,15 @@ public static synchronized IgnoreEntryOccurrence deserialize(@NotNull DataInput | |
|
||
final IgnoreEntryOccurrence entry = new IgnoreEntryOccurrence(url); | ||
int size = in.readInt(); | ||
|
||
@SuppressWarnings("unchecked") | ||
Pair<Pattern, Boolean>[] items = (Pair<Pattern, Boolean>[]) new Pair[size]; | ||
for (int i = 0; i < size; i++) { | ||
final Pattern pattern = Pattern.compile(in.readUTF()); | ||
Boolean isNegated = in.readBoolean(); | ||
entry.add(pattern.matcher(""), isNegated); | ||
items[i] = Pair.create(pattern, isNegated); | ||
} | ||
entry.setItems(items); | ||
|
||
return entry; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
items is potentially mutable variable