((instAlpTypeId != null) ?  (instAsset.getItemIdentificationPG().getItemIdentification()) : (instAsset.getUID().toString()));
((instAlpTypeId != null) ? ((hasItemID) ? instAsset.getItemIdentificationPG().getItemIdentification() : instAlpTypeId) : instAsset.getUID().toString());
  private static String registerCargoPrototype(					       Registry toReg, 					       Asset instAsset,					       boolean isLowFiCargo,					       LowFidelityAssetPG lowFiAssetPG) {    // given an "instance" of a cargoAsset, register it with    //   it's "template" (== "prototype").    //    // check for the typical case in TOPS, where an instance is    //   equivalent to it's prototype.  This often happens for    //   tanks, pallets, etc.    if (DEBUG)      System.out.println (Thread.currentThread () + 			  ".registerCargoPrototype - trying to register " + instAsset.getUID());    Asset protAsset = instAsset.getPrototype();  typical_case:    if (protAsset instanceof GLMAsset) {      // instAsset must also be an GLMAsset      GLMAsset alpInst = (GLMAsset)instAsset;      GLMAsset alpProt = (GLMAsset)protAsset;      // compare asset classes (CLASS_I, CLASS_IV, etc)      //   and type (CONTAINER or !CONTAINER)      int protAssetClass = getAssetClass(protAsset);      if (alpInst.getClass() != alpProt.getClass()) {        int instAssetClass = getAssetClass(instAsset);        if (instAssetClass != protAssetClass) {          // break to the general case          break typical_case;        }      }      // compare physicalPGs (weight, width, height, depth)      PhysicalPG instPhysPG = alpInst.getPhysicalPG();      PhysicalPG protPhysPG = alpProt.getPhysicalPG();            if (instPhysPG != protPhysPG) {	if (DEBUG)	  System.out.println (Thread.currentThread () + 			      ".registerCargoPrototype - Comparing pgs for " + instAsset.getUID () + 			      " - " + instAsset + " - not equal.");        break typical_case;      }      // compare typeIdPGs (typeId, nomen)      TypeIdentificationPG instTypeIdPG = 	instAsset.getTypeIdentificationPG();      TypeIdentificationPG protTypeIdPG = 	protAsset.getTypeIdentificationPG();      if (instTypeIdPG != protTypeIdPG) {	break typical_case;      }      // instance is equivalent to it's prototype!      //      // register the prototype      String protId;      if ((protTypeIdPG == null) ||	  ((protId = protTypeIdPG.getTypeIdentification()) == null)) {	// typically use typeId, but here use UID	protId = alpProt.getUID().toString();      }      if (toReg.cargoPrototypes.getPrototype(protId) == null) {	// must register this cargo prototype	//	// create a new cargo prototype	Prototype toProt = new Prototype();	toProt.UID = protId;	toProt.isLowFidelity = isLowFiCargo;	double weight = 0.0;	double width  = 0.0;	double height = 0.0;	double depth  = 0.0;	double area   = 0.0;	double volume = 0.0;	// toProt.parentUID is null, since we're using the prototype	//	// asset class (CLASS_I, CLASS_IV, etc)	toProt.assetClass = protAssetClass;	// asset type (CONTAINER or !CONTAINER)	toProt.assetType = 	  ((protAssetClass == Prototype.ASSET_CLASS_CONTAINER) ?	   (Prototype.ASSET_TYPE_CONTAINER) :	   (Prototype.ASSET_TYPE_ASSET));	if (protPhysPG != null) {	  if (DEBUG)	    System.out.println (Thread.currentThread () + "." +"registerCargoPrototype - Using prototype dimensions, e.g. " + 				protPhysPG.getMass().getTons());	  // weight in grams	  Mass protWeight = protPhysPG.getMass();	  if (protWeight != null) {	    weight = protWeight.getGrams();	  }	  // width in meters	  Distance protWidth = protPhysPG.getWidth();	  if (protWidth != null) {	    width = protWidth.getMeters();	  }	  // height in meters	  Distance protHeight = protPhysPG.getHeight();	  if (protHeight != null) {	    height = protHeight.getMeters();	  }	  // depth in meters	  Distance protDepth = protPhysPG.getLength();	  if (protDepth != null) {	    depth = protDepth.getMeters();	  }	  // area in square meters	  Area protArea = protPhysPG.getFootprintArea();	  if (protArea != null) {	    area = protArea.getSquareMeters();	  }	  // volume in cubic meters	  Volume protVolume = protPhysPG.getVolume();	  if (protVolume != null) {	    volume = protVolume.getCubicMeters();	  }	}	if (protTypeIdPG != null) {	  // type id	  toProt.alpTypeID = 	    protTypeIdPG.getTypeIdentification();	  // nomen	  toProt.nomenclature = 	    protTypeIdPG.getNomenclature();	}	// register the cargo prototype	toReg.cargoPrototypes.addPrototype(toProt);	if (lowFiAssetPG != null) {	  if (lowFiAssetPG.getCCCDims() != null) // not always applied...?	    registerCargoCatCodes (toReg.cargoPrototypes, toProt.UID, lowFiAssetPG.getCCCDims());	}	else	  toReg.cargoPrototypes.addCCCEntry(getCCCDim(toProt.UID, width, height, depth, weight, area, volume, (GLMAsset)protAsset));      }      // return the id      return protId;    }    // general case.  must grab all "cargo" fields and compare    //   values.    //    // FIXME this could be optimized, but we've already caught    //   the "typical" case...     // always need the prototype for cargo    String protId = null;    //    int protAssetClass = 0;    int protAssetType = 0;    String protAlpTypeId = null;    String protNomenclature = null;    double protWeight = 0.0;    double protWidth  = 0.0;    double protHeight = 0.0;    double protDepth  = 0.0;    double protArea   = 0.0;    double protVolume = 0.0;    if (protAsset != null) {      protAssetClass = getAssetClass(protAsset);      protAssetType = 	((protAssetClass == Prototype.ASSET_CLASS_CONTAINER) ?	 (Prototype.ASSET_TYPE_CONTAINER) :	 (Prototype.ASSET_TYPE_ASSET));      TypeIdentificationPG protTypePG = 	protAsset.getTypeIdentificationPG();      if (protTypePG != null) {	protAlpTypeId = 	  protTypePG.getTypeIdentification();	protNomenclature = 	  protTypePG.getNomenclature();      }      if (protAsset instanceof GLMAsset) {	PhysicalPG protPhysPG = 	  ((GLMAsset)protAsset).getPhysicalPG();	if (protPhysPG != null) {	  Mass weight = protPhysPG.getMass();	  if (weight != null) {	    protWeight = weight.getGrams();	  }	  Distance width = protPhysPG.getWidth();	  if (width != null) {	    protWidth = width.getMeters();	  }	  Distance height = protPhysPG.getHeight();	  if (height != null) {	    protHeight = height.getMeters();	  }	  Distance depth = protPhysPG.getLength();	  if (depth != null) {	    protDepth = depth.getMeters();	  }	  // area in square meters	  Area area = protPhysPG.getFootprintArea();	  if (area != null) {	    protArea = area.getSquareMeters();	  }	  // volume in cubic meters	  Volume volume = protPhysPG.getVolume();	  if (volume != null) {	    protVolume = volume.getCubicMeters();	  }	}      }      // register the prototype      protId =	((protAlpTypeId != null) ?	 (protAlpTypeId) :	 (protAsset.getUID().toString()));      if (toReg.cargoPrototypes.getPrototype(protId) == null) {	// must register this prototype	//	// create a new cargo prototype	Prototype toProt = new Prototype();	toProt.UID = protId;	toProt.isLowFidelity = isLowFiCargo;	toProt.assetClass = protAssetClass;	toProt.assetType = protAssetType;	toProt.alpTypeID = protAlpTypeId;	toProt.nomenclature = protNomenclature;	// register the cargo prototype	if (DEBUG)	  System.out.println (Thread.currentThread () + 			      ".registerCargoPrototype - register proto proto for "+instAsset.getUID());	toReg.cargoPrototypes.addPrototype(toProt);	if (lowFiAssetPG != null)	  registerCargoCatCodes (toReg.cargoPrototypes, toProt.UID, lowFiAssetPG.getCCCDims());	else	  toReg.cargoPrototypes.addCCCEntry(getCCCDim(toProt.UID, protWidth, protHeight, protDepth, protWeight, protArea, protVolume, (GLMAsset)protAsset));      }      // don't return the protId just yet!    }    // get all the instance values    int instAssetClass = 0;    int instAssetType = 0;    String instAlpTypeId = null;    String instNomenclature = null;    double instWeight = 0.0;    double instWidth = 0.0;    double instHeight = 0.0;    double instDepth = 0.0;    double instArea = 0.0;    double instVolume = 0.0;    //    instAssetClass = getAssetClass(instAsset);    instAssetType =       ((instAssetClass == Prototype.ASSET_CLASS_CONTAINER) ?       (Prototype.ASSET_TYPE_CONTAINER) :       (Prototype.ASSET_TYPE_ASSET));    TypeIdentificationPG instTypeIdPG =       instAsset.getTypeIdentificationPG();    if (instTypeIdPG != null) {      instAlpTypeId = 	instTypeIdPG.getTypeIdentification();      instNomenclature = 	instTypeIdPG.getNomenclature();    }    if (instAsset instanceof GLMAsset) {      PhysicalPG instPhysPG = 	((GLMAsset)instAsset).getPhysicalPG();      if (instPhysPG != null) {	if (DEBUG)	  System.out.println (Thread.currentThread () + ".registerCargoPrototype - Instance dimensions for " + instAsset.getUID() + 			      " - mass " + instPhysPG.getMass().getTons());	Mass weight = instPhysPG.getMass();	if (weight != null) {	  instWeight = weight.getGrams();	}	Distance width = instPhysPG.getWidth();	if (width != null) {	  instWidth = width.getMeters();	}	Distance height = instPhysPG.getHeight();	if (height != null) {	  instHeight = height.getMeters();	}	Distance depth = instPhysPG.getLength();	if (depth != null) {	  instDepth = depth.getMeters();	}	// area in square meters	Area area = instPhysPG.getFootprintArea();	if (area != null) {	  instArea = area.getSquareMeters();	}	// volume in cubic meters	Volume volume = instPhysPG.getVolume();	if (volume != null) {	  instVolume = volume.getCubicMeters();	}      }    }    // compare the "instance" to the "prototype"    //    // FIXME double equality should probably use +/- epsilon    if ((protId != null) &&	(instAssetClass == protAssetClass) &&	(instAssetType == protAssetType) &&	((instAlpTypeId == protAlpTypeId) ||	 ((protAlpTypeId != null) &&	  (protAlpTypeId.equals(instAlpTypeId)))) &&	((instNomenclature == protNomenclature) ||	 ((protNomenclature != null) &&	  (protNomenclature.equals(instNomenclature)))) &&	(instWeight == protWeight) &&	(instWidth == protWidth) &&	(instHeight == protHeight) &&	(instDepth == protDepth)) {      // instance is equivalent to it's prototype!      //      // already registered the prototype, so just       //   return it's id      if (DEBUG)	System.out.println (Thread.currentThread () + ".registerCargoPrototype - returning already registered proto " + protId);      return protId;    } else {      // instAsset is different than it's prototype      //      // register the instance      String instId =	((instAlpTypeId != null) ?	 //         (instAlpTypeId) :	 (instAsset.getItemIdentificationPG().getItemIdentification()) :	 (instAsset.getUID().toString()));      if (toReg.cargoPrototypes.getPrototype(instId) == null) { 	// must register this "instance" prototype	//	// create a new cargo "instance" prototype	Prototype toProt = new Prototype();	toProt.UID = instId;	toProt.isLowFidelity = isLowFiCargo;	// parentUID is the already registered prototype!	toProt.parentUID = protId; 	toProt.assetClass = instAssetClass;	toProt.assetType = instAssetType;	toProt.alpTypeID = instAlpTypeId;	toProt.nomenclature = instNomenclature;	// register the cargo "instance" prototype	if (DEBUG)	  System.out.println (Thread.currentThread () + ".registerCargoPrototype - register Instance proto for "+ instAsset.getUID());	toReg.cargoPrototypes.addPrototype(toProt);	if (lowFiAssetPG != null)	  registerCargoCatCodes (toReg.cargoPrototypes, toProt.UID, lowFiAssetPG.getCCCDims());	else	  toReg.cargoPrototypes.addCCCEntry(getCCCDim(toProt.UID, instWidth, instHeight, instDepth, instWeight, instArea, instVolume, (GLMAsset)protAsset));      }      else if (DEBUG)	System.out.println (Thread.currentThread () + ".registerCargoPrototype - ignoring instId " + instId);      // return the instance id      return instId;    }  }