Skip to content

Commit

Permalink
modify Attributes.addAll() to preserve non-conflicting Private Creato…
Browse files Browse the repository at this point in the history
…r ID tag positions
  • Loading branch information
gunterze committed Sep 23, 2011
1 parent a6d4272 commit 7c1d8f4
Showing 1 changed file with 36 additions and 29 deletions.
65 changes: 36 additions & 29 deletions dcm4che-core/src/main/java/org/dcm4che/data/Attributes.java
Original file line number Diff line number Diff line change
Expand Up @@ -1214,32 +1214,40 @@ private Attributes addAll(Attributes other, int[] include, int[] exclude,
for (int i = 0; i < otherSize; i++) {
int tag = tags[i];
VR vr = srcVRs[i];
if (!(TagUtils.isPrivateCreator(tag) && vr == VR.LO)
&& (include == null || Arrays.binarySearch(
include, fromIndex, toIndex, tag) >= 0)
&& (exclude == null || Arrays.binarySearch(
exclude, fromIndex, toIndex, tag) < 0)) {
if (TagUtils.isPrivateTag(tag)) {
int tmp = TagUtils.creatorTagOf(tag);
if (creatorTag != tmp) {
creatorTag = tmp;
privateCreator = other.privateCreatorOf(tag);
}
} else {
creatorTag = 0;
privateCreator = null;
}
Object value = srcValues[i];
if (value instanceof Sequence) {
set(tag, privateCreator, (Sequence) value);
} else if (value instanceof Fragments) {
set(tag, privateCreator, (Fragments) value);
} else {
set(tag, privateCreator, vr,
(value instanceof byte[] && toggleEndian)
? vr.toggleEndian((byte[]) value, true)
: value);
Object value = srcValues[i];
if (TagUtils.isPrivateCreator(tag)) {
if (contains(tag))
continue; // do not overwrite private creator IDs
if (vr == VR.LO && value != Value.NULL
&& creatorTagOf(tag,
VR.LO.toString(other.decodeStringValue(i), false, 0, null),
false)
!= -1)
continue; // do not add duplicate private creator ID
}
if (include != null && Arrays.binarySearch(include, fromIndex, toIndex, tag) >= 0)
continue;
if (exclude != null && Arrays.binarySearch(include, fromIndex, toIndex, tag) < 0)
continue;
if (TagUtils.isPrivateTag(tag)) {
int tmp = TagUtils.creatorTagOf(tag);
if (creatorTag != tmp) {
creatorTag = tmp;
privateCreator = other.privateCreatorOf(tag);
}
} else {
creatorTag = 0;
privateCreator = null;
}
if (value instanceof Sequence) {
set(tag, privateCreator, (Sequence) value);
} else if (value instanceof Fragments) {
set(tag, privateCreator, (Fragments) value);
} else {
set(tag, privateCreator, vr,
(value instanceof byte[] && toggleEndian)
? vr.toggleEndian((byte[]) value, true)
: value);
}
}
return this;
Expand Down Expand Up @@ -1276,7 +1284,8 @@ public StringBuilder toStringBuilder(StringBuilder sb) {
}

public StringBuilder toStringBuilder(int limit, int maxWidth, StringBuilder sb) {
appendAttributes(limit, maxWidth, sb, "");
if (appendAttributes(limit, maxWidth, sb, "") > limit)
sb.append("...\n");
return sb;
}

Expand Down Expand Up @@ -1304,8 +1313,6 @@ private int appendAttributes(int limit, int maxWidth, StringBuilder sb, String p
if (value instanceof Sequence)
lines += appendItems((Sequence) value, limit - lines, maxWidth, sb, prefix + '>');
}
if (prefix.isEmpty() && lines > limit)
sb.append("...\n");
return lines;
}

Expand All @@ -1315,7 +1322,7 @@ private int appendItems(Sequence sq, int limit, int maxWidth, StringBuilder sb,
int itemNo = 0;
for (Attributes item : sq) {
if (++lines > limit)
return lines;
break;
sb.append(prefix).append("Item #").append(++itemNo).append('\n');
lines += item.appendAttributes(limit - lines, maxWidth, sb, prefix);
}
Expand Down

0 comments on commit 7c1d8f4

Please sign in to comment.