9package org.dartlang.analysis.server.protocol;
11import java.util.Arrays;
14import com.google.common.collect.Lists;
15import com.google.dart.server.utilities.general.JsonUtilities;
16import com.google.dart.server.utilities.general.ObjectUtilities;
17import com.google.gson.JsonArray;
18import com.google.gson.JsonElement;
19import com.google.gson.JsonObject;
20import com.google.gson.JsonPrimitive;
21import org.apache.commons.lang3.builder.HashCodeBuilder;
22import java.util.ArrayList;
23import java.util.Iterator;
24import org.apache.commons.lang3.StringUtils;
31@SuppressWarnings(
"unused")
46 private final int[] offsets;
57 this.element = element;
58 this.offsets = offsets;
63 for (
int offset : offsets) {
76 ObjectUtilities.
equals(other.element, element) &&
77 Arrays.equals(other.offsets, offsets) &&
85 int[] offsets = JsonUtilities.decodeIntArray(jsonObject.get(
"offsets").getAsJsonArray());
86 int length = jsonObject.get(
"length").getAsInt();
91 if (jsonArray ==
null) {
94 ArrayList<Occurrences> list =
new ArrayList<Occurrences>(jsonArray.size());
95 Iterator<JsonElement> iterator = jsonArray.iterator();
96 while (iterator.hasNext()) {
97 list.add(fromJson(iterator.next().getAsJsonObject()));
125 HashCodeBuilder builder =
new HashCodeBuilder();
126 builder.append(element);
127 builder.append(offsets);
129 return builder.toHashCode();
133 JsonObject jsonObject =
new JsonObject();
134 jsonObject.add(
"element", element.
toJson());
135 JsonArray jsonArrayOffsets =
new JsonArray();
136 for (
int elt : offsets) {
137 jsonArrayOffsets.add(
new JsonPrimitive(elt));
139 jsonObject.add(
"offsets", jsonArrayOffsets);
140 jsonObject.addProperty(
"length",
length);
146 StringBuilder builder =
new StringBuilder();
148 builder.append(
"element=");
149 builder.append(element +
", ");
150 builder.append(
"offsets=");
151 builder.append(StringUtils.join(offsets,
", ") +
", ");
152 builder.append(
"length=");
155 return builder.toString();
static Element fromJson(JsonObject jsonObject)
static List< Occurrences > fromJsonArray(JsonArray jsonArray)
static Occurrences fromJson(JsonObject jsonObject)
Occurrences(Element element, int[] offsets, int length)
boolean containsInclusive(int x)
boolean equals(Object obj)