use of java.util.Comparator in project onebusaway-gtfs-modules by OneBusAway.
the class GtfsEntitySchemaFactory method getEntityComparators.
public static Map<Class<?>, Comparator<?>> getEntityComparators() {
Map<Class<?>, Comparator<?>> comparators = new HashMap<Class<?>, Comparator<?>>();
comparators.put(Agency.class, getComparatorForIdentityBeanType(Agency.class));
comparators.put(Block.class, getComparatorForIdentityBeanType(Block.class));
comparators.put(Route.class, getComparatorForIdentityBeanType(Route.class));
comparators.put(Stop.class, getComparatorForIdentityBeanType(Stop.class));
comparators.put(Trip.class, getComparatorForIdentityBeanType(Trip.class));
comparators.put(StopTime.class, new StopTimeComparator());
comparators.put(ShapePoint.class, new ShapePointComparator());
comparators.put(ServiceCalendar.class, new ServiceCalendarComparator());
comparators.put(ServiceCalendarDate.class, new ServiceCalendarDateComparator());
return comparators;
}
use of java.util.Comparator in project OpenGrok by OpenGrok.
the class JFlexXref method writeSymbolTable.
/**
* Write a JavaScript function that returns an array with the definitions to
* list in the navigation panel. Each element of the array is itself an
* array containing the name of the definition type, the CSS class name for
* the type, and an array of (symbol, line) pairs for the definitions of
* that type.
*/
private void writeSymbolTable() throws IOException {
if (defs == null) {
// No definitions, no symbol table to write
return;
}
// We want the symbol table to be sorted
Comparator<Tag> cmp = new Comparator<Tag>() {
@Override
public int compare(Tag tag1, Tag tag2) {
// Order by symbol name, and then by line number if multiple
// definitions use the same symbol name
int ret = tag1.symbol.compareTo(tag2.symbol);
if (ret == 0) {
ret = tag1.line - tag2.line;
}
return ret;
}
};
Map<String, SortedSet<Tag>> symbols = new HashMap<>();
for (Tag tag : defs.getTags()) {
Style style = getStyle(tag.type);
if (style != null && style.title != null) {
SortedSet<Tag> tags = symbols.get(style.name);
if (tags == null) {
tags = new TreeSet<>(cmp);
symbols.put(style.name, tags);
}
tags.add(tag);
}
}
//TODO try to get rid of included js scripts generated from here (all js should ideally be in util)
out.append("<script type=\"text/javascript\">/* <![CDATA[ */\n");
out.append("function get_sym_list(){return [");
boolean first = true;
for (Style style : DEFINITION_STYLES) {
SortedSet<Tag> tags = symbols.get(style.name);
if (tags != null) {
if (!first) {
out.append(',');
}
out.append("[\"");
out.append(style.title);
out.append("\",\"");
out.append(style.ssClass);
out.append("\",[");
boolean firstTag = true;
for (Tag tag : tags) {
if (!firstTag) {
out.append(',');
}
out.append('[');
out.append(Util.jsStringLiteral(tag.symbol));
out.append(',');
out.append(Integer.toString(tag.line));
out.append(']');
firstTag = false;
}
out.append("]]");
first = false;
}
}
/* no LF intentionally - xml is whitespace aware ... */
out.append("];} /* ]]> */</script>");
}
use of java.util.Comparator in project DataX by alibaba.
the class RangeSplit method splitIntegerRange.
/**
* 切分数值类型 注意: 当begin和end相等时,函数将返回空的List
*
* @param begin
* @param end
* @param count
* @return
*/
public static List<Long> splitIntegerRange(long begin, long end, int count) {
if (count <= 1) {
throw new IllegalArgumentException("Input count <= 1 .");
}
List<Long> is = new ArrayList<Long>();
BigInteger bigBegin = BigInteger.valueOf(begin);
BigInteger bigEnd = BigInteger.valueOf(end);
BigInteger bigCount = BigInteger.valueOf(count);
BigInteger abs = (bigEnd.subtract(bigBegin)).abs();
if (abs.compareTo(BigInteger.ZERO) == 0) {
// partition key 相等的情况
return is;
}
if (bigCount.compareTo(abs) > 0) {
bigCount = abs;
}
if (bigEnd.subtract(bigBegin).compareTo(BigInteger.ZERO) > 0) {
// 正向
return splitIntegerRange(bigBegin, bigEnd, bigCount);
} else {
// 逆向
List<Long> tmp = splitIntegerRange(bigEnd, bigBegin, bigCount);
Comparator<Long> comparator = new Comparator<Long>() {
public int compare(Long arg0, Long arg1) {
return arg0.compareTo(arg1);
}
};
Collections.sort(tmp, Collections.reverseOrder(comparator));
return tmp;
}
}
use of java.util.Comparator in project jersey by jersey.
the class EntityTypesTest method testJAXBListRepresentationJSON.
@Test
public void testJAXBListRepresentationJSON() throws Exception {
final WebTarget target = target("JAXBListResourceJSON");
Collection<JaxbBean> a = target.request().get(new GenericType<Collection<JaxbBean>>() {
});
Collection<JaxbBean> b = target.request().post(Entity.entity(new GenericEntity<Collection<JaxbBean>>(a) {
}, "application/json"), new GenericType<Collection<JaxbBean>>() {
});
assertEquals(a, b);
b = target.path("type").request().post(Entity.entity(new GenericEntity<Collection<JaxbBean>>(a) {
}, "application/json"), new GenericType<Collection<JaxbBean>>() {
});
assertEquals(a, b);
a = new LinkedList<>(a);
b = target.path("queue").request().post(Entity.entity(new GenericEntity<Queue<JaxbBean>>((Queue<JaxbBean>) a) {
}, "application/json"), new GenericType<Queue<JaxbBean>>() {
});
assertEquals(a, b);
a = new HashSet<>(a);
b = target.path("set").request().post(Entity.entity(new GenericEntity<Set<JaxbBean>>((Set<JaxbBean>) a) {
}, "application/json"), new GenericType<Set<JaxbBean>>() {
});
final Comparator<JaxbBean> c = new Comparator<JaxbBean>() {
@Override
public int compare(final JaxbBean t, final JaxbBean t1) {
return t.value.compareTo(t1.value);
}
};
final TreeSet<JaxbBean> t1 = new TreeSet<>(c);
final TreeSet<JaxbBean> t2 = new TreeSet<>(c);
t1.addAll(a);
t2.addAll(b);
assertEquals(t1, t2);
final Stack<JaxbBean> s = new Stack<>();
s.addAll(a);
b = target.path("stack").request().post(Entity.entity(new GenericEntity<Stack<JaxbBean>>(s) {
}, "application/json"), new GenericType<Stack<JaxbBean>>() {
});
assertEquals(s, b);
a = new MyArrayList<>(a);
b = target.path("custom").request().post(Entity.entity(new GenericEntity<MyArrayList<JaxbBean>>((MyArrayList<JaxbBean>) a) {
}, "application/json"), new GenericType<MyArrayList<JaxbBean>>() {
});
assertEquals(a, b);
// TODO: would be nice to produce/consume a real JSON array like following
// instead of what we have now:
// JSONArray a = r.get(JSONArray.class);
// JSONArray b = new JSONArray().
// put(new JSONObject().put("value", "one")).
// put(new JSONObject().put("value", "two")).
// put(new JSONObject().put("value", "three"));
// assertEquals(a.toString(), b.toString());
// JSONArray c = r.post(JSONArray.class, b);
// assertEquals(a.toString(), c.toString());
}
use of java.util.Comparator in project jersey by jersey.
the class EntityTypesTest method testJAXBListRepresentationFastInfoset.
/**
* TODO, the unmarshalling fails.
*/
@Test
@Ignore("TODO: unignore once fi support implemented (JERSEY-1190)")
public // TODO: unignore once fi support implemented (JERSEY-1190)
void testJAXBListRepresentationFastInfoset() {
final WebTarget target = target("JAXBListResourceFastInfoset");
Collection<JaxbBean> a = target.request().get(new GenericType<Collection<JaxbBean>>() {
});
Collection<JaxbBean> b = target.request().post(Entity.entity(new GenericEntity<Collection<JaxbBean>>(a) {
}, "application/fastinfoset"), new GenericType<Collection<JaxbBean>>() {
});
assertEquals(a, b);
b = target.path("type").request().post(Entity.entity(new GenericEntity<Collection<JaxbBean>>(a) {
}, "application/fastinfoset"), new GenericType<Collection<JaxbBean>>() {
});
assertEquals(a, b);
a = new LinkedList<>(a);
b = target.path("queue").request().post(Entity.entity(new GenericEntity<Queue<JaxbBean>>((Queue<JaxbBean>) a) {
}, "application/fastinfoset"), new GenericType<Queue<JaxbBean>>() {
});
assertEquals(a, b);
a = new HashSet<>(a);
b = target.path("set").request().post(Entity.entity(new GenericEntity<Set<JaxbBean>>((Set<JaxbBean>) a) {
}, "application/fastinfoset"), new GenericType<Set<JaxbBean>>() {
});
final Comparator<JaxbBean> c = new Comparator<JaxbBean>() {
@Override
public int compare(final JaxbBean t, final JaxbBean t1) {
return t.value.compareTo(t1.value);
}
};
final TreeSet<JaxbBean> t1 = new TreeSet<>(c);
final TreeSet<JaxbBean> t2 = new TreeSet<>(c);
t1.addAll(a);
t2.addAll(b);
assertEquals(t1, t2);
final Stack<JaxbBean> s = new Stack<>();
s.addAll(a);
b = target.path("stack").request().post(Entity.entity(new GenericEntity<Stack<JaxbBean>>(s) {
}, "application/fastinfoset"), new GenericType<Stack<JaxbBean>>() {
});
assertEquals(s, b);
a = new MyArrayList<>(a);
b = target.path("custom").request().post(Entity.entity(new GenericEntity<MyArrayList<JaxbBean>>((MyArrayList<JaxbBean>) a) {
}, "application/fastinfoset"), new GenericType<MyArrayList<JaxbBean>>() {
});
assertEquals(a, b);
}
Aggregations