<commit_before>/*
 * =============================================================================
 * 
 *   Copyright (c) 2011-2012, The THYMELEAF team (http://www.thymeleaf.org)
 * 
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 * 
 * =============================================================================
 */
package org.thymeleaf.context;

import java.util.HashMap;
import java.util.Map;

import ognl.MapPropertyAccessor;
import ognl.OgnlException;
import ognl.OgnlRuntime;

/**
 * <p>
 *   Special implementation of the {@link Map} interface that
 *   will be used for containing context variables in {@link IContext} 
 *   implementations.
 * </p>
 * <p>
 *   Constructors in this class mimic those in {@link HashMap} and
 *   have the same meaning.
 * </p>
 * 
 * @author <NAME>
 * 
 * @since 1.0
 *
 */
public class VariablesMap<K,V> extends HashMap<K,V> {

    private static final long serialVersionUID = 6785956724279950873L;
    
    

    public VariablesMap() {
        super();
    }

    public VariablesMap(final int initialCapacity, final float loadFactor) {
        super(initialCapacity, loadFactor);
    }

    public VariablesMap(final int initialCapacity) {
        super(initialCapacity);
    }

    public VariablesMap(final Map<? extends K, ? extends V> m) {
        super(m);
    }

    static {
    	OgnlRuntime.setPropertyAccessor(VariablesMap.class, new VariablesMapPropertyAccessor());
    }
    
    /**
     * Extension of {@code MapPropertyAccessor} that handles getting of size property. When there is entry with 
     * key "size" it is returned instead of size property from {@code VariablesMap}. Otherwise this property 
     * accessor works exactly same like {@code MapPropertyAccessor}.
     * 
     * @author <NAME>
     * 
     * @see MapPropertyAccessor
     * 
     * @since 2.0
     */
    private static class VariablesMapPropertyAccessor extends MapPropertyAccessor {
    	private static final String RESERVED_SIZE_PROPERTY_NAME = "size";
    	
    	VariablesMapPropertyAccessor () {
    		super();
    	}
    	
    	@Override
    	@SuppressWarnings("rawtypes") 
		public Object getProperty(Map context, Object target, Object name) throws OgnlException {
    		if (!RESERVED_SIZE_PROPERTY_NAME.equals(name)) {
    			return super.getProperty(context, target, name);
    		}
    		
    		if (!(target instanceof VariablesMap)) {
    			throw new IllegalStateException("Wrong target type. This property accessor is only usable for VariableMap class.");
    		}
    		
            Map map = (Map) target;
            Object result = map.get(RESERVED_SIZE_PROPERTY_NAME);
            if (result == null) {
            	result = Integer.valueOf(map.size());
            }
            return result;
    	}
    }
    
}
<commit_msg>Minor indentation bugfixing<commit_after>/*
 * =============================================================================
 * 
 *   Copyright (c) 2011-2012, The THYMELEAF team (http://www.thymeleaf.org)
 * 
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 * 
 * =============================================================================
 */
package org.thymeleaf.context;

import java.util.HashMap;
import java.util.Map;

import ognl.MapPropertyAccessor;
import ognl.OgnlException;
import ognl.OgnlRuntime;

/**
 * <p>
 *   Special implementation of the {@link Map} interface that
 *   will be used for containing context variables in {@link IContext} 
 *   implementations.
 * </p>
 * <p>
 *   Constructors in this class mimic those in {@link HashMap} and
 *   have the same meaning.
 * </p>
 * 
 * @author <NAME>;ndez
 * @author <NAME>
 * 
 * @since 1.0
 *
 */
public class VariablesMap<K,V> extends HashMap<K,V> {

    private static final long serialVersionUID = 6785956724279950873L;
    
    

    public VariablesMap() {
        super();
    }

    public VariablesMap(final int initialCapacity, final float loadFactor) {
        super(initialCapacity, loadFactor);
    }

    public VariablesMap(final int initialCapacity) {
        super(initialCapacity);
    }

    public VariablesMap(final Map<? extends K, ? extends V> m) {
        super(m);
    }

    static {
    	OgnlRuntime.setPropertyAccessor(VariablesMap.class, new VariablesMapPropertyAccessor());
    }
    
    /**
     * Extension of {@code MapPropertyAccessor} that handles getting of size
     * property. When there is entry with key "size" it is returned instead of
     * size property from {@code VariablesMap}. Otherwise this property accessor
     * works exactly same like {@code MapPropertyAccessor}.
     * 
     * @author <NAME>
     * 
     * @see MapPropertyAccessor
     * 
     * @since 2.0
     */
    private static class VariablesMapPropertyAccessor extends MapPropertyAccessor {
        
        private static final String RESERVED_SIZE_PROPERTY_NAME = "size";

        VariablesMapPropertyAccessor() {
            super();
        }

        @Override
        @SuppressWarnings("rawtypes")
        public Object getProperty(Map context, Object target, Object name) throws OgnlException {
            
            if (!RESERVED_SIZE_PROPERTY_NAME.equals(name)) {
                return super.getProperty(context, target, name);
            }

            if (!(target instanceof VariablesMap)) {
                throw new IllegalStateException(
                        "Wrong target type. This property accessor is only usable for VariableMap class.");
            }

            Map map = (Map) target;
            Object result = map.get(RESERVED_SIZE_PROPERTY_NAME);
            if (result == null) {
                result = Integer.valueOf(map.size());
            }
            return result;
            
        }
        
    }
    
}

{'fraction_non_alphanumeric': 0.13038348082595871, 'fraction_numerical': 0.01032448377581121, 'mean_word_length': 2.727872457394173, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '5391408', 'n_tokens_mistral': 1898, 'n_tokens_neox': 1786, 'n_words': 579}