if (srcLoc.getLocatorIndices().length != destLoc.getLocatorIndices().length) throw new IllegalArgumentException("Src and Dest locator indices differ in length!!");  for (int i = 0; i < srcLoc.getAttributeIndices().length; i++) { int instIndex  = instSrcCompat ? srcLoc.getActualIndex(srcLoc.getAttributeIndices()[i]) : destLoc.getActualIndex(destLoc.getAttributeIndices()[i]); Attribute src  = srcDataset.attribute(srcLoc.getActualIndex(srcLoc.getAttributeIndices()[i])); Attribute dest = destDataset.attribute(destLoc.getActualIndex(destLoc.getAttributeIndices()[i])); if (!instance.isMissing(instIndex)) { int valIndex = dest.addRelation(src.relation((int)instance.value(instIndex))); instance.setValue(instIndex, (double)valIndex); } }   int[] srcIndices  = srcLoc.getLocatorIndices(); int[] destIndices = destLoc.getLocatorIndices(); for (int i = 0; i < srcIndices.length; i++) { Instances rel = instSrcCompat ? instance.relationalValue(srcLoc.getActualIndex(srcIndices[i])) : instance.relationalValue(destLoc.getActualIndex(destIndices[i])); AttributeLocator srcRelAttsNew = srcLoc.getLocator(srcIndices[i]); Instances srcDatasetNew = srcRelAttsNew.getData(); AttributeLocator destRelAttsNew = destLoc.getLocator(destIndices[i]); Instances destDatasetNew = destRelAttsNew.getData(); for (int n = 0; n < rel.numInstances(); n++) { copyRelationalValues(rel.instance(n), instSrcCompat, srcDatasetNew, srcRelAttsNew, destDatasetNew, destRelAttsNew); } }
if (inst.dataset() == null) { throw new IllegalArgumentException("Instance has no dataset assigned!!"); } else if (inst.dataset().numAttributes() != destDataset.numAttributes()) { throw new IllegalArgumentException("Src and Dest differ in # of attributes!!"); } copyRelationalValues(inst, true, inst.dataset(), strAtts, destDataset, strAtts);
  public static void copyRelationalValues(Instance instance, boolean instSrcCompat,                                  Instances srcDataset, AttributeLocator srcLoc,                                  Instances destDataset, AttributeLocator destLoc) {    if (srcDataset == destDataset)      return;        if (srcLoc.getAttributeIndices().length != destLoc.getAttributeIndices().length)      throw new IllegalArgumentException("Src and Dest relational indices differ in length!!");    if (srcLoc.getLocatorIndices().length != destLoc.getLocatorIndices().length)      throw new IllegalArgumentException("Src and Dest locator indices differ in length!!");    for (int i = 0; i < srcLoc.getAttributeIndices().length; i++) {      int instIndex  = instSrcCompat       		 	  ? srcLoc.getActualIndex(srcLoc.getAttributeIndices()[i])       		 	  : destLoc.getActualIndex(destLoc.getAttributeIndices()[i]);      Attribute src  = srcDataset.attribute(srcLoc.getActualIndex(srcLoc.getAttributeIndices()[i]));      Attribute dest = destDataset.attribute(destLoc.getActualIndex(destLoc.getAttributeIndices()[i]));      if (!instance.isMissing(instIndex)) {        int valIndex = dest.addRelation(src.relation((int)instance.value(instIndex)));        instance.setValue(instIndex, (double)valIndex);      }    }        // recurse if necessary    int[] srcIndices  = srcLoc.getLocatorIndices();    int[] destIndices = destLoc.getLocatorIndices();    for (int i = 0; i < srcIndices.length; i++) {      Instances rel = instSrcCompat      		         ? instance.relationalValue(srcLoc.getActualIndex(srcIndices[i]))      		         : instance.relationalValue(destLoc.getActualIndex(destIndices[i]));      AttributeLocator srcRelAttsNew = srcLoc.getLocator(srcIndices[i]);      Instances srcDatasetNew = srcRelAttsNew.getData();      AttributeLocator destRelAttsNew = destLoc.getLocator(destIndices[i]);      Instances destDatasetNew = destRelAttsNew.getData();      for (int n = 0; n < rel.numInstances(); n++) {        copyRelationalValues(rel.instance(n), instSrcCompat, srcDatasetNew, srcRelAttsNew, destDatasetNew, destRelAttsNew);      }    }  }