<commit_before>/*
 * Created on Oct 24, 2003
 */
package xal.smf.proxy;

import java.util.*;

import xal.smf.AcceleratorNode;
import xal.ca.Channel;


/**
 * Access property values for a node
 * @author <NAME>
 */
abstract public class AbstractPropertyAccessor implements PropertyAccessor {
	/** Get the scale factor for the specified property */
	protected double getPropertyScale( final String propertyName ) {
		return 1.0;
	}


	/** get the map of design values keyed by property name */
	protected Map<String,Double> getDesignValueMap( final AcceleratorNode node, final List<String> propertyNames ) {
		final Map<String,Double> valueMap = new HashMap<String,Double>();
		for( final String propertyName : propertyNames	) {
			final double scale = getPropertyScale( propertyName );
			final double value = scale * node.getDesignPropertyValue( propertyName );
			valueMap.put( propertyName, value );
		}
		
		return valueMap;
	}

	
	/** get the map of live values keyed by property name */
	protected Map<String,Double> getLiveValueMap( final AcceleratorNode node, final Map<Channel,Double> channelValues, final List<String> propertyNames ) {
		final Map<String,Double> valueMap = new HashMap<String,Double>();
		for( final String propertyName : propertyNames	) {
			final Channel[] propertyChannels = node.getLivePropertyChannels( propertyName );
			final double[] propertyChannelValues = new double[propertyChannels.length];
			for ( int index = 0 ; index < propertyChannels.length ; index++ ) {
				final Channel channel = propertyChannels[index];
				propertyChannelValues[index] = channelValues.get( channel );
			}
			final double scale = getPropertyScale( propertyName );
			final double propertyValue = scale * node.getLivePropertyValue( propertyName, propertyChannelValues );
			valueMap.put( propertyName, propertyValue );
		}

		return valueMap;
	}


	/** get the channels for live property access */
	protected Collection<Channel> getLiveChannels( final AcceleratorNode node, final List<String> propertyNames ) {
		final Set<Channel> channels = new HashSet<Channel>();

		for( final String propertyName : propertyNames	) {
			final Channel[] propertyChannels = node.getLivePropertyChannels( propertyName );
			for ( final Channel channel : propertyChannels ) {
				channels.add( channel );
			}
		}

		return channels;
	}
}<commit_msg>OXAL-461 AbstractPropertyAccessor fixing (Double)null -> double, to throw proper exception, i.e. channel not found/accesible<commit_after>/*
 * Created on Oct 24, 2003
 */
package xal.smf.proxy;

import java.util.*;

import xal.smf.AcceleratorNode;
import xal.ca.Channel;


/**
 * Access property values for a node
 * @author <NAME>
 */
abstract public class AbstractPropertyAccessor implements PropertyAccessor {
	/** Get the scale factor for the specified property */
	protected double getPropertyScale( final String propertyName ) {
		return 1.0;
	}


	/** get the map of design values keyed by property name */
	protected Map<String,Double> getDesignValueMap( final AcceleratorNode node, final List<String> propertyNames ) {
		final Map<String,Double> valueMap = new HashMap<String,Double>();
		for( final String propertyName : propertyNames	) {
			final double scale = getPropertyScale( propertyName );
			final double value = scale * node.getDesignPropertyValue( propertyName );
			valueMap.put( propertyName, value );
		}
		
		return valueMap;
	}

	
	/** get the map of live values keyed by property name */
	protected Map<String,Double> getLiveValueMap( final AcceleratorNode node, final Map<Channel,Double> channelValues, final List<String> propertyNames ) {
		final Map<String,Double> valueMap = new HashMap<String,Double>();
		for( final String propertyName : propertyNames	) {
			final Channel[] propertyChannels = node.getLivePropertyChannels( propertyName );
			double[] propertyChannelValues = new double[propertyChannels.length];
			for ( int index = 0 ; index < propertyChannels.length ; index++ ) {
				final Channel channel = propertyChannels[index];
				if (!channelValues.containsKey(channel)) {
					propertyChannelValues = null;
					break;
				}
				propertyChannelValues[index] = channelValues.get( channel );
			}
			if (propertyChannelValues != null) {
				final double scale = getPropertyScale( propertyName );
				final double propertyValue = scale * node.getLivePropertyValue( propertyName, propertyChannelValues );
				valueMap.put( propertyName, propertyValue );
			}
		}

		return valueMap;
	}


	/** get the channels for live property access */
	protected Collection<Channel> getLiveChannels( final AcceleratorNode node, final List<String> propertyNames ) {
		final Set<Channel> channels = new HashSet<Channel>();

		for( final String propertyName : propertyNames	) {
			final Channel[] propertyChannels = node.getLivePropertyChannels( propertyName );
			for ( final Channel channel : propertyChannels ) {
				channels.add( channel );
			}
		}

		return channels;
	}
}
{'fraction_non_alphanumeric': 0.09513229650575641, 'fraction_numerical': 0.004241567360129267, 'mean_word_length': 4.502222222222223, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 32, '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': '6641860', 'n_tokens_mistral': 1482, 'n_tokens_neox': 1318, 'n_words': 423}