<commit_before>package de.lmu.ifi.dbs.elki.visualization.css;

import java.util.HashMap;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;

import de.lmu.ifi.dbs.elki.visualization.svg.SVGUtil;


/**
 * Manager class to track CSS classes used in a particular SVG document.
 * 
 * @author <NAME>
 */
public class CSSClassManager extends HashMap<String, CSSClass> {
  /**
   * Serial version.
   */
  private static final long serialVersionUID = 8807736974456191901L;

  /**
   * Add a single class to the map.
   * 
   * @param clss
   * @return existing (old) class
   * @throws CSSNamingConflict when a class of the same name but different owner object exists.
   */
  public CSSClass addClass(CSSClass clss) throws CSSNamingConflict {
    CSSClass existing = super.get(clss.getName());
    if (existing != null && existing.getOwner() != null && existing.getOwner() != clss.getOwner()) {
      throw new CSSNamingConflict("CSS class naming conflict between "+clss.getOwner().toString()+" and "+existing.getOwner().toString());
    }
    return super.put(clss.getName(), clss);
  }
  
  /**
   * Check if a name is already used in the classes.
   * 
   * @param name
   * @return true if the class name is already used.
   */
  public boolean contains(String name) {
    return containsKey(name);
  }

  /**
   * Serialize managed CSS classes to rule file.
   * 
   * @param buf String buffer
   */
  public void serialize(StringBuffer buf) {
    for (CSSClass clss : values()) {
      clss.appendCSSDefinition(buf);
    }
  }
  <commit_msg>Add support for merging CSS classes from another CSS Class Manager.<commit_after>package de.lmu.ifi.dbs.elki.visualization.css;

import java.util.Collection;
import java.util.HashMap;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;

import de.lmu.ifi.dbs.elki.visualization.svg.SVGUtil;


/**
 * Manager class to track CSS classes used in a particular SVG document.
 * 
 * @author <NAME>
 */
public class CSSClassManager {
  /**
   * Store the contained CSS classes.
   */
  private HashMap<String, CSSClass> store = new HashMap<String, CSSClass>();
  
  /**
   * Serial version.
   */
  private static final long serialVersionUID = 8807736974456191901L;

  /**
   * Add a single class to the map.
   * 
   * @param clss
   * @return existing (old) class
   * @throws CSSNamingConflict when a class of the same name but different owner object exists.
   */
  public CSSClass addClass(CSSClass clss) throws CSSNamingConflict {
    CSSClass existing = store.get(clss.getName());
    if (existing != null && existing.getOwner() != null && existing.getOwner() != clss.getOwner()) {
      throw new CSSNamingConflict("CSS class naming conflict between "+clss.getOwner().toString()+" and "+existing.getOwner().toString());
    }
    return store.put(clss.getName(), clss);
  }
  
  /**
   * Check if a name is already used in the classes.
   * 
   * @param name
   * @return true if the class name is already used.
   */
  public boolean contains(String name) {
    return store.containsKey(name);
  }

  /**
   * Serialize managed CSS classes to rule file.
   * 
   * @param buf String buffer
   */
  public void serialize(StringBuffer buf) {
    for (CSSClass clss : store.values()) {
      clss.appendCSSDefinition(buf);
    }
  }
  
  /**
   * Get all CSS classes in this manager.
   * 
   * @return CSS classes.
   */
  public Collection<CSSClass> getClasses() {
    return store.values();
  }
  
  /**
   * Check compatibility
   */
  public boolean testMergeable(CSSClassManager other) {
    for (CSSClass clss : other.getClasses()) {
      CSSClass existing = store.get(clss.getName());
      // Check for a naming conflict.
      if (existing != null && existing.getOwner() != null && clss.getOwner() != null && existing.getOwner() != clss.getOwner()) {
        return false;
      }
    }
    return true;
  }
  
  /**
   * Merge CSS classes, for example to merge two plots.
   * 
   * @throws CSSNamingConflict If there is a naming conflict.
   */
  public boolean mergeCSSFrom(CSSClassManager other) throws CSSNamingConflict {
    for (CSSClass clss : other.getClasses()) {
      this.addClass(clss);
    }
    return true;
  }
  
{'fraction_non_alphanumeric': 0.11802120141342756, 'fraction_numerical': 0.010365135453474675, 'mean_word_length': 3.024644549763033, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3314490', 'n_tokens_mistral': 1359, 'n_tokens_neox': 1304, 'n_words': 383}