public static CompositeId fromString(String idString) { ArrayList<String> parts= new ArrayList<String>(); int commaIndex= idString.indexOf(','); while (commaIndex > 0) { int length= Integer.valueOf(idString.substring(0, commaIndex)).intValue(); String part= idString.substring(commaIndex+1, commaIndex+1+length); parts.add(part); idString= idString.substring(commaIndex+1+length); commaIndex= idString.indexOf(','); } String[] result= parts.toArray(new String[parts.size()]); return new CompositeId(result); }
/** * Return the VM corresponding to the specified composite Id. The id uniquely * identifies a VM across all VM types. * * @param idString the composite id that specifies an instance of IVMInstall * @return the VM corresponding to the specified composite Id. * * @since 2.1 */ public static IVMInstall getVMFromCompositeId(String idString) { if (idString == null || idString.length() == 0) { return null; } CompositeId id= CompositeId.fromString(idString); if (id.getPartCount() == 2) { IVMInstallType vmType= getVMInstallType(id.get(0)); if (vmType != null) { return vmType.findVMInstall(id.get(1)); } } return null; }
/** * Returns a String that uniquely identifies the specified VM across all VM types. * * @param vm the instance of IVMInstallType to be identified * @return the unique identifier for the specified VM * * @since 2.1 */ public static String getCompositeIdFromVM(IVMInstall vm) { if (vm == null) { return null; } IVMInstallType vmType = vm.getVMInstallType(); String typeID = vmType.getId(); CompositeId id = new CompositeId(new String[] { typeID, vm.getId() }); return id.toString(); }
/** * Returns a String that uniquely identifies the specified VM across all VM types. * * @param vm the instance of IVMInstallType to be identified * @return the unique identifier for the specified VM * * @since 2.1 */ public static String getCompositeIdFromVM(IVMInstall vm) { if (vm == null) { return null; } IVMInstallType vmType = vm.getVMInstallType(); String typeID = vmType.getId(); CompositeId id = new CompositeId(new String[] { typeID, vm.getId() }); return id.toString(); }
/** * Return the VM corresponding to the specified composite Id. The id uniquely * identifies a VM across all VM types. * * @param idString the composite id that specifies an instance of IVMInstall * @return the VM corresponding to the specified composite Id. * * @since 2.1 */ public static IVMInstall getVMFromCompositeId(String idString) { if (idString == null || idString.length() == 0) { return null; } CompositeId id= CompositeId.fromString(idString); if (id.getPartCount() == 2) { IVMInstallType vmType= getVMInstallType(id.get(0)); if (vmType != null) { return vmType.findVMInstall(id.get(1)); } } return null; }
public static CompositeId fromString(String idString) { ArrayList<String> parts= new ArrayList<>(); int commaIndex= idString.indexOf(','); while (commaIndex > 0) { int length= Integer.valueOf(idString.substring(0, commaIndex)).intValue(); String part= idString.substring(commaIndex+1, commaIndex+1+length); parts.add(part); idString= idString.substring(commaIndex+1+length); commaIndex= idString.indexOf(','); } String[] result= parts.toArray(new String[parts.size()]); return new CompositeId(result); }