- * Must be passed the same number of labels are were passed to {@link #labelNames}.
- */
- public Child labels(String... labelValues) {
- if (labelValues.length != labelNames.size()) {
- throw new IllegalArgumentException("Incorrect number of labels.");
+ /**
+ * It is just reimplementing in a more JIT-friendly way both equals/hashCode to avoid
+ * using Iterators like the original {@link AbstractList}.
+ */
+ private static final class LabelNames extends ArrayList This implementation uses exactly the code that is used to define the
+ * list hash function in the documentation for the {@link List#hashCode}
+ * method.
+ *
+ * @return the hash code value for this list
+ */
+ public int hashCode() {
+ int hashCode = 1;
+ for (int i = 0, size = size(); i < size; i++) {
+ final Object e = get(i);
+ final int objHash = (e == null ? 0 : e.hashCode());
+ hashCode = 31 * hashCode + objHash;
+ }
+ return hashCode;
+ }
}
- for (String label: labelValues) {
- if (label == null) {
- throw new IllegalArgumentException("Label cannot be null.");
- }
+
+ /**
+ * Return the Child with the given labels, creating it if needed.
+ *
+ * Must be passed the same number of labels are were passed to {@link #labelNames}.
+ */
+ public Child labels(String... labelValues) {
+ final List