/** Add a collection of tags to the set. */ ArrayTagSet addAll(Tag[] ts, int tsLength) { if (tsLength == 0) { return this; } else if (length == 0) { Arrays.sort(ts, 0, tsLength, TAG_COMPARATOR); int len = dedup(ts, 0, ts, 0, tsLength); return new ArrayTagSet(toStringArray(ts, len)); } else { String[] newTags = new String[(length + tsLength) * 2]; Arrays.sort(ts, 0, tsLength, TAG_COMPARATOR); int newLength = merge(newTags, tags, length, ts, tsLength); return new ArrayTagSet(newTags, newLength); } }
/** Add a collection of tags to the set. */ ArrayTagSet addAll(Tag[] ts, int tsLength) { if (tsLength == 0) { return this; } else if (length == 0) { Arrays.sort(ts, 0, tsLength, TAG_COMPARATOR); int len = dedup(ts, 0, ts, 0, tsLength); return new ArrayTagSet(toStringArray(ts, len)); } else { String[] newTags = new String[(length + tsLength) * 2]; Arrays.sort(ts, 0, tsLength, TAG_COMPARATOR); int newLength = merge(newTags, tags, length, ts, tsLength); return new ArrayTagSet(newTags, newLength); } }
/** Add a new tag to the set. */ @SuppressWarnings("PMD.AvoidArrayLoops") ArrayTagSet add(Tag tag) { if (length == 0) { return new ArrayTagSet(new String[] {tag.key(), tag.value()}); } else { String[] newTags = new String[length + 2]; String k = tag.key(); int i = 0; for (; i < length && tags[i].compareTo(k) < 0; i += 2) { newTags[i] = tags[i]; newTags[i + 1] = tags[i + 1]; } if (i < length && tags[i].equals(k)) { // Override newTags[i++] = tag.key(); newTags[i++] = tag.value(); System.arraycopy(tags, i, newTags, i, length - i); i = length; } else { // Insert newTags[i] = tag.key(); newTags[i + 1] = tag.value(); System.arraycopy(tags, i, newTags, i + 2, length - i); i = newTags.length; } return new ArrayTagSet(newTags, i); } }
/** Add a new tag to the set. */ @SuppressWarnings("PMD.AvoidArrayLoops") ArrayTagSet add(Tag tag) { if (length == 0) { return new ArrayTagSet(new String[] {tag.key(), tag.value()}); } else { String[] newTags = new String[length + 2]; String k = tag.key(); int i = 0; for (; i < length && tags[i].compareTo(k) < 0; i += 2) { newTags[i] = tags[i]; newTags[i + 1] = tags[i + 1]; } if (i < length && tags[i].equals(k)) { // Override newTags[i++] = tag.key(); newTags[i++] = tag.value(); System.arraycopy(tags, i, newTags, i, length - i); i = length; } else { // Insert newTags[i] = tag.key(); newTags[i + 1] = tag.value(); System.arraycopy(tags, i, newTags, i + 2, length - i); i = newTags.length; } return new ArrayTagSet(newTags, i); } }