Skip to main content
deleted 35 characters in body
Source Link

You could define a mapping of your replacements, as follows:

private static final Map<VR, String> stringReplacements = new HashedMap<>();
static {
  stringReplacements.put(VR.DA, "20150101");
  stringReplacements.put(VR.DT, "20150101");
  stringReplacements.put(VR.SH, "testingThis");
  // ....
}

private static final Map<VR, Integer> intReplacements = new HashedMap<>();
static {
  intReplacements.put(VR.UL, 25);
  // ....
}

Note that I've created two different maps, as you substitute both strings and ints. You could have one map of Object values, but then your replacement code needs to do instanceof checks.

Your long series of conditional statements then reduces to:

VR replaceTagVR = dcmObj.vrOf(valueofReplaceTag);

ifString (s = stringReplacements.containsKeyget(replaceTagVR);
if (s != null) {
  dcmObj.putString(valueofReplaceTag, replaceTagVR, stringReplacements.get(replaceTagVR)s);
}

ifInteger (i = intReplacements.containsKeyget(replaceTagVR);
if (i != null) {
  dcmObj.putInt(valueofReplaceTag, replaceTagVR, intReplacements.get(replaceTagVR)i);
} 

You could define a mapping of your replacements, as follows:

private static final Map<VR, String> stringReplacements = new HashedMap<>();
static {
  stringReplacements.put(VR.DA, "20150101");
  stringReplacements.put(VR.DT, "20150101");
  stringReplacements.put(VR.SH, "testingThis");
  // ....
}

private static final Map<VR, Integer> intReplacements = new HashedMap<>();
static {
  intReplacements.put(VR.UL, 25);
  // ....
}

Note that I've created two different maps, as you substitute both strings and ints. You could have one map of Object values, but then your replacement code needs to do instanceof checks.

Your long series of conditional statements then reduces to:

VR replaceTagVR = dcmObj.vrOf(valueofReplaceTag);

if (stringReplacements.containsKey(replaceTagVR)) {
  dcmObj.putString(valueofReplaceTag, replaceTagVR, stringReplacements.get(replaceTagVR));
}

if (intReplacements.containsKey(replaceTagVR)) {
  dcmObj.putInt(valueofReplaceTag, replaceTagVR, intReplacements.get(replaceTagVR));
}

You could define a mapping of your replacements, as follows:

private static final Map<VR, String> stringReplacements = new HashedMap<>();
static {
  stringReplacements.put(VR.DA, "20150101");
  stringReplacements.put(VR.DT, "20150101");
  stringReplacements.put(VR.SH, "testingThis");
  // ....
}

private static final Map<VR, Integer> intReplacements = new HashedMap<>();
static {
  intReplacements.put(VR.UL, 25);
  // ....
}

Note that I've created two different maps, as you substitute both strings and ints. You could have one map of Object values, but then your replacement code needs to do instanceof checks.

Your long series of conditional statements then reduces to:

VR replaceTagVR = dcmObj.vrOf(valueofReplaceTag);

String s = stringReplacements.get(replaceTagVR);
if (s != null) {
  dcmObj.putString(valueofReplaceTag, replaceTagVR, s);
}

Integer i = intReplacements.get(replaceTagVR);
if (i != null) {
  dcmObj.putInt(valueofReplaceTag, replaceTagVR, i);
} 
Source Link

You could define a mapping of your replacements, as follows:

private static final Map<VR, String> stringReplacements = new HashedMap<>();
static {
  stringReplacements.put(VR.DA, "20150101");
  stringReplacements.put(VR.DT, "20150101");
  stringReplacements.put(VR.SH, "testingThis");
  // ....
}

private static final Map<VR, Integer> intReplacements = new HashedMap<>();
static {
  intReplacements.put(VR.UL, 25);
  // ....
}

Note that I've created two different maps, as you substitute both strings and ints. You could have one map of Object values, but then your replacement code needs to do instanceof checks.

Your long series of conditional statements then reduces to:

VR replaceTagVR = dcmObj.vrOf(valueofReplaceTag);

if (stringReplacements.containsKey(replaceTagVR)) {
  dcmObj.putString(valueofReplaceTag, replaceTagVR, stringReplacements.get(replaceTagVR));
}

if (intReplacements.containsKey(replaceTagVR)) {
  dcmObj.putInt(valueofReplaceTag, replaceTagVR, intReplacements.get(replaceTagVR));
}