public VR getVR(String privateCreator, int tag) { int index = indexOf(privateCreator, tag); if (index < 0) return null; return vrs[index]; }
private int indexForInsertOf(int tag) { return size == 0 ? -1 : tags[size-1] < tag ? -(size+1) : indexOf(tag); }
public Object getValue(String privateCreator, int tag, VR.Holder vr) { int index = indexOf(privateCreator, tag); if (index < 0) return null; if (vr != null) vr.vr = vrs[index]; return values[index]; }
public boolean contains(int tag) { return indexOf(tag) >= 0; }
public boolean contains(String privateCreator, int tag) { return indexOf(privateCreator, tag) >= 0; }
public Sequence getSequence(String privateCreator, int tag) { int index = indexOf(privateCreator, tag); if (index < 0) return null; Object value = values[index]; if (value == Value.NULL) return (Sequence) (values[index] = new Sequence(this, 0)); return value instanceof Sequence ? (Sequence) value : null; }
private int indexOf(String privateCreator, int tag) { if (privateCreator != null) { int creatorTag = creatorTagOf(privateCreator, tag, false); if (creatorTag == -1) return -1; tag = TagUtils.toPrivateTag(creatorTag, tag); } return indexOf(tag); }
public int diff(Attributes other, int[] selection, Attributes diff) { int count = 0; for (int tag : selection) { int index = indexOf(tag); int otherIndex = other.indexOf(tag); if (!equalValues(other, index, otherIndex)) { if (diff != null) { Object value = index < 0 ? Value.NULL : values[index]; if (value instanceof Sequence) { diff.set(null, tag, (Sequence) value, null); } else { diff.set(tag, index < 0 ? other.vrs[otherIndex] : vrs[index], value); } } count++; } } return count; }
private int creatorIndexOf(String privateCreator, int groupNumber) { if ((groupNumber & 1) == 0) throw new IllegalArgumentException( "(" + TagUtils.shortToHexString(groupNumber) + ",xxxx) is not a private Group"); int group = groupNumber << 16; int creatorTag = group | 0x10; int index = indexOf(creatorTag); if (index < 0) index = -index-1; while (index < size && (tags[index] & 0xffffff00) == group) { if (vrs[index] == VR.LO) { Object creatorID = decodeStringValue(index); if (privateCreator.equals(creatorID)) return index; } index++; creatorTag++; } return -1; }
public boolean containsValue(String privateCreator, int tag) { int index = indexOf(privateCreator, tag); return index >= 0 && !isEmpty(vrs[index].isStringType() ? decodeStringValue(index) : values[index]); }
public String privateCreatorOf(int tag) { if (!TagUtils.isPrivateTag(tag)) return null; int creatorTag = (tag & 0xffff0000) | ((tag >>> 8) & 0xff); int index = indexOf(creatorTag); if (index < 0 || vrs[index] != VR.LO || values[index] == Value.NULL) return null; Object value = decodeStringValue(index); if (value == Value.NULL) return null; return VR.LO.toString(value, false, 0, null); }
public byte[] getBytes(String privateCreator, int tag) throws IOException { int index = indexOf(privateCreator, tag); if (index < 0) return null; Object value = values[index]; VR vr = vrs[index]; try { if (value instanceof Value) return ((Value) value).toBytes(vr, bigEndian); return vr.toBytes(value, getSpecificCharacterSet(vr)); } catch (UnsupportedOperationException e) { LOG.info("Attempt to access {} {} as bytes", TagUtils.toString(tag), vr); return null; } }
public double[] getDoubles(String privateCreator, int tag, VR vr) { int index = indexOf(privateCreator, tag); if (index < 0) return null; Object value = values[index]; if (value == Value.NULL) return ByteUtils.EMPTY_DOUBLES; if (vr == null) vr = vrs[index]; else updateVR(index, vr); try { value = loadBulkData(index); if (vr == VR.DS) value = decodeDSValue(index); return vr.toDoubles(value, bigEndian); } catch (UnsupportedOperationException e) { LOG.info("Attempt to access {} {} as double", TagUtils.toString(tag), vr); return null; } catch (IllegalArgumentException e) { LOG.info("Invalid value of {} {}", TagUtils.toString(tag), vr); return null; } }
public void writeTo(DicomOutputStream out) throws IOException { if (isEmpty()) return; if (groupLengths == null && out.getEncodingOptions().groupLength) throw new IllegalStateException( "groupLengths not initialized by calcLength()"); SpecificCharacterSet cs = getSpecificCharacterSet(); if (tags[0] < 0) { int index0 = -(1 + indexOf(0)); writeTo(out, cs, index0, size, groupLengthIndex0); writeTo(out, cs, 0, index0, 0); } else { writeTo(out, cs, 0, size, 0); } }
public double getDouble(String privateCreator, int tag, VR vr, int valueIndex, double defVal) { int index = indexOf(privateCreator, tag); if (index < 0) return defVal; Object value = values[index]; if (value == Value.NULL) return defVal; if (vr == null) vr = vrs[index]; else updateVR(index, vr); try { value = loadBulkData(index); if (vr == VR.DS) value = decodeDSValue(index); return vr.toDouble(value, bigEndian, valueIndex, defVal); } catch (UnsupportedOperationException e) { LOG.info("Attempt to access {} {} as double", TagUtils.toString(tag), vr); return defVal; } catch (IllegalArgumentException e) { LOG.info("Invalid value of {} {}", TagUtils.toString(tag), vr); return defVal; } }
public boolean addSelected(Attributes other, String privateCreator, int tag) { int index = other.indexOf(privateCreator, tag); if (index < 0) return false; Object value = other.values[index]; if (value instanceof Sequence) { set(privateCreator, tag, (Sequence) value, null); } else if (value instanceof Fragments) { set(privateCreator, tag, (Fragments) value); } else { VR vr = other.vrs[index]; set(privateCreator, tag, vr, toggleEndian(vr, value, bigEndian != other.bigEndian)); } return true; }
public DateRange getDateRange(String privateCreator, int tag, VR vr, DateRange defVal) { int index = indexOf(privateCreator, tag); if (index < 0) return defVal; Object value = values[index]; if (value == Value.NULL) return defVal; if (vr == null) vr = vrs[index]; else updateVR(index, vr); if (!vr.isTemporalType()) { LOG.info("Attempt to access {} {} as date", TagUtils.toString(tag), vr); return defVal; } value = decodeStringValue(index); if (value == Value.NULL) return defVal; try { return toDateRange((value instanceof String) ? (String) value : ((String[]) value)[0], vr); } catch (IllegalArgumentException e) { LOG.info("Invalid value of {} {}", TagUtils.toString(tag), vr); return defVal; } }
/** * Invokes {@link Visitor#visit} for each attribute in this instance. The * operation will be aborted if <code>visitor.visit()</code> returns <code>false</code>. * * @param visitor * @param visitNestedDatasets controls if <code>visitor.visit()</code> * is also invoked for attributes in nested datasets * @return <code>true</code> if the operation was not aborted. */ public boolean accept(Visitor visitor, boolean visitNestedDatasets) throws Exception{ if (isEmpty()) return true; if (tags[0] < 0) { int index0 = -(1 + indexOf(0)); return accept(visitor, visitNestedDatasets, index0, size) && accept(visitor, visitNestedDatasets, 0, index0); } else { return accept(visitor, visitNestedDatasets, 0, size); } }
public Sequence ensureSequence(String privateCreator, int tag, int initialCapacity) { if (privateCreator != null) { int creatorTag = creatorTagOf(privateCreator, tag, true); tag = TagUtils.toPrivateTag(creatorTag, tag); } Sequence seq; int index = indexOf(tag); if (index >= 0) { Object oldValue = values[index]; if (oldValue instanceof Sequence) seq = (Sequence) oldValue; else values[index] = seq = new Sequence(this, initialCapacity); } else { seq = new Sequence(this, initialCapacity); insert(-index-1, tag, VR.SQ, seq); } return seq; }