<commit_before>/**
 * Copyright (C) 2013 - present by OpenGamma Inc. and the OpenGamma group of companies
 *
 * Please see distribution for license.
 */
package com.opengamma.sesame.graph;

import java.util.Collections;
import java.util.List;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.opengamma.util.ArgumentChecker;

/**
 * TODO this badly needs a test, it was quietly broken
 */
public class CompositeNodeDecorator implements NodeDecorator {

  private final List<NodeDecorator> _decorators;

  public CompositeNodeDecorator(List<NodeDecorator> decorators) {
    this(decorators.toArray(new NodeDecorator[decorators.size()]));
  }

  public CompositeNodeDecorator(NodeDecorator... decorators) {
    // reverse the decorators so the first decorator is the first one presented with the argument
    // it's arguable which way round is least surprising. this makes most sense to me
    List<NodeDecorator> reversed = Lists.newArrayList(ArgumentChecker.notNull(decorators, "decorators"));
    Collections.reverse(reversed);
    _decorators = ImmutableList.copyOf(reversed);
  }

  @Override
  public Node decorateNode(Node node) {
    Node wrappedNode = node;
    for (NodeDecorator decorator : _decorators) {
      wrappedNode = decorator.decorateNode(wrappedNode);
    }
    return wrappedNode;
  }<commit_msg>SSM-76 - Clean up caches when closing a view<commit_after>/**
 * Copyright (C) 2013 - present by OpenGamma Inc. and the OpenGamma group of companies
 *
 * Please see distribution for license.
 */
package com.opengamma.sesame.graph;

import java.util.Collections;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.opengamma.util.ArgumentChecker;

/**
 * TODO this badly needs a test, it was quietly broken
 */
public class CompositeNodeDecorator implements NodeDecorator, AutoCloseable {

  private static final Logger s_logger = LoggerFactory.getLogger(CompositeNodeDecorator.class);

  private final List<NodeDecorator> _decorators;

  public CompositeNodeDecorator(List<NodeDecorator> decorators) {
    this(decorators.toArray(new NodeDecorator[decorators.size()]));
  }

  public CompositeNodeDecorator(NodeDecorator... decorators) {
    // reverse the decorators so the first decorator is the first one presented with the argument
    // it's arguable which way round is least surprising. this makes most sense to me
    List<NodeDecorator> reversed = Lists.newArrayList(ArgumentChecker.notNull(decorators, "decorators"));
    Collections.reverse(reversed);
    _decorators = ImmutableList.copyOf(reversed);
  }

  @Override
  public Node decorateNode(Node node) {
    Node wrappedNode = node;
    for (NodeDecorator decorator : _decorators) {
      wrappedNode = decorator.decorateNode(wrappedNode);
    }
    return wrappedNode;
  }

  @Override
  public void close() {
    for (NodeDecorator decorator : _decorators) {
      if (decorator instanceof AutoCloseable) {
        try {
          ((AutoCloseable) decorator).close();
        } catch (Exception e) {
          s_logger.warn("Exception closing decorator", e);
        }
      }
    }
  }
{'fraction_non_alphanumeric': 0.0897908979089791, 'fraction_numerical': 0.0036900369003690036, 'mean_word_length': 4.1228346456692915, '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': '4556134', 'n_tokens_mistral': 968, 'n_tokens_neox': 943, 'n_words': 260}