class HmsInventory {

    public boolean saveInventory( final String inventoryFile, boolean backup )
    {

        // check that inventory file to be saved is not null or blank
        if ( StringUtils.isBlank( inventoryFile ) )
        {
            logger.warn( "In saveInventory, inventory file name is either null or blank." );
            return false;
        }

        // take backup of existing file, if backup is true.
        File file = new File( inventoryFile );
        if ( backup && file.exists() )
        {
            try
            {
                String backupfile = file.getName() + ".bak." + file.lastModified();
                File b = new File( file.getParent(), backupfile );
                logger.debug( "In saveInventory, Saving backup of HMS inventory file to {}.", b.getAbsolutePath() );
                Files.copy( file.toPath(), b.toPath(), StandardCopyOption.REPLACE_EXISTING,
                            StandardCopyOption.COPY_ATTRIBUTES );
            }
            catch ( IOException ioe )
            {
                logger.warn( "In saveInventory, Error saving backup copy of file {}.", file.getAbsolutePath(), ioe );
            }
        }

        // save inventory
        try
        {
            ObjectMapper objectMapper = new ObjectMapper();
            objectMapper.enable( SerializationFeature.INDENT_OUTPUT );
            objectMapper.writeValue( file, this.nodeMap );
            logger.debug( "In saveInventory, saved inventory to file '{}'.", file.getAbsolutePath() );
            return true;
        }
        catch ( IOException e )
        {
            logger.error( "In saveInventory, error while saving inventory to file '{}'.", file.getAbsolutePath() );
            return false;
        }
    }

    private  HmsInventory();

}