Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * This file is part of the DiffX library.
  *
  * For licensing information please see the file license.txt included in the release.
  * A copy of this licence can also be found at
  *   http://www.opensource.org/licenses/artistic-license-2.0.php
  */
 package com.topologi.diffx.sequence;
 
Provides a mapping of namespace URIs to prefixes.

This class can be used to reconstruct the qualified element or attribute names.

Note that for each namespace URI there can only be one prefix.

Author(s):
Christophe Lauret
Version:
12 May 2010
Since:
0.7
public final class PrefixMapping {

  
Maps namespace URIs to prefixes.
  private final Map<StringStringmappings = new HashMap<StringString>();

  
Add the specified mapping if the namespace URI has not been mapped before.

This method will ensure that the mapping is actually unique, that is that the namespace URI correspond to one and only one prefix and that the prefix only corresponds to one and only one namespace URI.

Parameters:
uri The namespace URI to map.
prefix The prefix to use.
Throws:
java.lang.NullPointerException if the URI or prefix is null
  public void add(String uriString prefixthrows NullPointerException {
    if (!this..containsKey(uri)) {
      int count = 0;
      String actualPrefix = prefix;
      while (this..containsValue(actualPrefix)) {
        actualPrefix = prefix + count++;
      }
      this..put(uriactualPrefix);
    }
  }

  
Returns an enumeration of the namespace URIs used in this mapping.

Returns:
An enumeration of the namespace URIs used in this mapping.
  public Enumeration<StringgetURIs() {
    return Collections.enumeration(this..keySet());
  }

  
Returns the prefix corresponding to the given namespace URI.

Parameters:
uri The namespace URI to map.
Returns:
The corresponding prefix.
  public String getPrefix(String uri) {
    return uri == null"" : this..get(uri);
  }
New to GrepCode? Check out our FAQ X