<commit_before>/*
 * This program is free software; you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software
 * Foundation.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this
 * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
 * or from the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * Copyright (c) 2005-2011 Pentaho Corporation.  All rights reserved.
 */

package org.pentaho.reporting.engine.classic.core.function.sys;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.pentaho.reporting.engine.classic.core.AttributeNames;
import org.pentaho.reporting.engine.classic.core.InvalidReportStateException;
import org.pentaho.reporting.engine.classic.core.ReportDefinition;
import org.pentaho.reporting.engine.classic.core.ReportElement;
import org.pentaho.reporting.engine.classic.core.event.ReportEvent;
import org.pentaho.reporting.engine.classic.core.function.AbstractElementFormatFunction;
import org.pentaho.reporting.engine.classic.core.function.FunctionUtilities;
import org.pentaho.reporting.engine.classic.core.function.ProcessingContext;
import org.pentaho.reporting.engine.classic.core.function.StructureFunction;
import org.pentaho.reporting.engine.classic.core.layout.style.DefaultStyleCache;
import org.pentaho.reporting.engine.classic.core.layout.style.StyleCache;
import org.pentaho.reporting.engine.classic.core.style.ResolverStyleSheet;
import org.pentaho.reporting.engine.classic.core.style.css.CSSStyleResolver;
import org.pentaho.reporting.engine.classic.core.style.resolver.StyleResolver;
import org.pentaho.reporting.engine.classic.core.util.DoubleKeyedCounter;
import org.pentaho.reporting.libraries.resourceloader.ResourceKey;
import org.pentaho.reporting.libraries.resourceloader.ResourceManager;

public class StyleResolvingEvaluator extends AbstractElementFormatFunction implements StructureFunction
{
  private static class StyleResolverCacheEntry implements Serializable
  {
    private long elementChangeTracker;
    private long styleChangeHash;
    private long styleModificationCount;

    private StyleResolverCacheEntry(final long elementChangeTracker,
                                    final long styleChangeHash,
                                    final long styleModificationCount)
    {
      this.elementChangeTracker = elementChangeTracker;
      this.styleChangeHash = styleChangeHash;
      this.styleModificationCount = styleModificationCount;
    }

    public StyleResolverCacheEntry(final StyleResolverCacheEntry parentEntry, final ReportElement e)
    {
      if (parentEntry == null)
      {
        this.elementChangeTracker = e.getChangeTracker();
        this.styleChangeHash = e.getStyle().getChangeTrackerHash();
        this.styleModificationCount = e.getStyle().getModificationCount();
      }
      else
      {
        this.elementChangeTracker = parentEntry.getElementChangeTracker() * 31 + e.getChangeTracker();
        this.styleChangeHash = parentEntry.getStyleChangeHash() * 31 + e.getStyle().getChangeTrackerHash();
        this.elementChangeTracker = parentEntry.getStyleModificationCount() * 31 + e.getStyle().getModificationCount();
      }
    }<commit_msg>PRD-4071: Golden sample report PRD-2087.prpt crashed the layouting hard due to a perfect storm of large roll-backs in the layouting, a style-expression hiding a group-header and the widow/orphans relying on that group-header for their constraints.<commit_after>/*
 * This program is free software; you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software
 * Foundation.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this
 * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
 * or from the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * Copyright (c) 2005-2011 Pentaho Corporation.  All rights reserved.
 */

package org.pentaho.reporting.engine.classic.core.function.sys;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.pentaho.reporting.engine.classic.core.AttributeNames;
import org.pentaho.reporting.engine.classic.core.InvalidReportStateException;
import org.pentaho.reporting.engine.classic.core.ReportDefinition;
import org.pentaho.reporting.engine.classic.core.ReportElement;
import org.pentaho.reporting.engine.classic.core.event.ReportEvent;
import org.pentaho.reporting.engine.classic.core.function.AbstractElementFormatFunction;
import org.pentaho.reporting.engine.classic.core.function.FunctionUtilities;
import org.pentaho.reporting.engine.classic.core.function.ProcessingContext;
import org.pentaho.reporting.engine.classic.core.function.StructureFunction;
import org.pentaho.reporting.engine.classic.core.layout.style.DefaultStyleCache;
import org.pentaho.reporting.engine.classic.core.layout.style.StyleCache;
import org.pentaho.reporting.engine.classic.core.style.ResolverStyleSheet;
import org.pentaho.reporting.engine.classic.core.style.css.CSSStyleResolver;
import org.pentaho.reporting.engine.classic.core.style.resolver.StyleResolver;
import org.pentaho.reporting.engine.classic.core.util.DoubleKeyedCounter;
import org.pentaho.reporting.libraries.resourceloader.ResourceKey;
import org.pentaho.reporting.libraries.resourceloader.ResourceManager;

public class StyleResolvingEvaluator extends AbstractElementFormatFunction implements StructureFunction
{
  private static class StyleResolverCacheEntry implements Serializable
  {
    private long elementChangeTracker;
    private long styleChangeHash;
    private long styleModificationCount;

    private StyleResolverCacheEntry(final long elementChangeTracker,
                                    final long styleChangeHash,
                                    final long styleModificationCount)
    {
      this.elementChangeTracker = elementChangeTracker;
      this.styleChangeHash = styleChangeHash;
      this.styleModificationCount = styleModificationCount;
    }

    public StyleResolverCacheEntry(final StyleResolverCacheEntry parentEntry, final ReportElement e)
    {
      if (parentEntry == null)
      {
        this.elementChangeTracker = e.getChangeTracker();
        this.styleChangeHash = e.getStyle().getChangeTrackerHash();
        this.styleModificationCount = e.getStyle().getModificationCount();
      }
      else
      {
        this.elementChangeTracker = parentEntry.getElementChangeTracker() * 31 + e.getChangeTracker();
        this.styleChangeHash = parentEntry.getStyleChangeHash() * 31 + e.getStyle().getChangeTrackerHash();
        this.styleModificationCount = parentEntry.getStyleModificationCount() * 31 + e.getStyle().getModificationCount();
      }
    }
{'fraction_non_alphanumeric': 0.08191434468524252, 'fraction_numerical': 0.008513931888544891, 'mean_word_length': 4.429271708683474, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7397198', 'n_tokens_mistral': 2106, 'n_tokens_neox': 2008, 'n_words': 502}