/** * Randomly creates a new {@link String} that can be used as a metaid, i.e., a * String that is a valid metaid and that is not yet used by any other element * within this {@link SBMLDocument}. * * @return a valid metaid that is not yet used by any other element * within this {@link SBMLDocument}. */ public String nextMetaId() { String currId; do { currId = UUID.randomUUID().toString(); if (Character.isDigit(currId.charAt(0))) { // Add an underscore at the beginning of the new metaid only if // necessary. currId = '_' + currId; } } while (containsMetaId(currId)); return currId; }
/** * Checks if the given meta identifier can be added in this * {@link SBMLDocument} * 's {@link #mappingFromMetaId2SBase}. * * @param metaId * the identifier whose value is to be checked. * @throws IllegalArgumentException * if a metaid to add is already present in the list of * registered metaids. */ private void checkMetaId(String metaId) { if (containsMetaId(metaId)) { logger.error(MessageFormat.format( "An element with the metaid \"{0}\" is already present in the SBML document. The new element will not get added to it.", metaId)); throw new IllegalArgumentException(MessageFormat.format( "Cannot set duplicate meta identifier \"{0}\".", metaId)); } }