<commit_before>/**
 * Copyright (c) 2010-2013, openHAB.org and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package org.openhab.binding.iec6205621meter.internal;

import java.util.Dictionary;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang.StringUtils;
import org.openhab.binding.iec6205621meter.Iec6205621MeterBindingProvider;
import org.openhab.core.binding.AbstractActiveBinding;
import org.openhab.core.items.Item;
import org.openhab.core.library.items.NumberItem;
import org.openhab.core.library.items.StringItem;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.StringType;
import org.openhab.core.types.Command;
import org.openhab.core.types.State;
import org.openmuc.j62056.DataSet;
import org.osgi.service.cm.ConfigurationException;
import org.osgi.service.cm.ManagedService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * iec 62056-21 meter binding implementation
 * 
 * @author <NAME>
 * @author <NAME>
 * @since 1.5.0
 */
public class Iec6205621MeterBinding extends
		AbstractActiveBinding<Iec6205621MeterBindingProvider> implements
		ManagedService {

	private static final Logger logger = LoggerFactory
			.getLogger(Iec6205621MeterBinding.class);

	// regEx to validate a meter config
	// <code>'^(.*?)\\.(serialPort|baudRateChangeDelay|echoHandling)$'</code>
	private final Pattern METER_CONFIG_PATTERN = Pattern
			.compile("^(.*?)\\.(serialPort|baudRateChangeDelay|echoHandling)$");

	private static final long DEFAULT_REFRESH_INTERVAL = 60000;

	/**
	 * the refresh interval which is used to poll values from the IEC 62056-21 Meter
	 * server (optional, defaults to 10 minutes)
	 */
	private long refreshInterval = DEFAULT_REFRESH_INTERVAL;

	// configured meter devices - keyed by meter device name
	private final Map<String, Meter> meterDeviceConfigurtions = new HashMap<String, Meter>();

	public Iec6205621MeterBinding() {
	}

	public void activate() {

	}

	public void deactivate() {
		meterDeviceConfigurtions.clear();
	}

	/**
	 * @{inheritDoc
	 */
	@Override
	protected long getRefreshInterval() {
		return refreshInterval;
	}

	/**
	 * @{inheritDoc
	 */
	@Override
	protected String getName() {
		return "iec6205621meter Refresh Service";
	}

	private final Meter createIec6205621MeterConfig(String name,
			MeterConfig config) {

		Meter reader = null;
		reader = new Meter(name, config);
		return reader;
	}

	/**
	 * @{inheritDoc
	 */
	@Override
	protected void execute() {
		// the frequently executed code (polling) goes here ...
		Map<String, Map<String, DataSet>> cache = new HashMap<>();
		for (Iec6205621MeterBindingProvider provider : providers) {

			for (String itemName : provider.getItemNames()) {
				for (Entry<String, Meter> entry : meterDeviceConfigurtions.entrySet()) {
					Meter reader = entry.getValue();
					String meterName = provider.getMeterName(itemName);<commit_msg>Iec6205621MeterBinding: Avoid diamond operator because of source level 1.6<commit_after>/**
 * Copyright (c) 2010-2013, openHAB.org and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package org.openhab.binding.iec6205621meter.internal;

import java.util.Dictionary;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang.StringUtils;
import org.openhab.binding.iec6205621meter.Iec6205621MeterBindingProvider;
import org.openhab.core.binding.AbstractActiveBinding;
import org.openhab.core.items.Item;
import org.openhab.core.library.items.NumberItem;
import org.openhab.core.library.items.StringItem;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.StringType;
import org.openhab.core.types.Command;
import org.openhab.core.types.State;
import org.openmuc.j62056.DataSet;
import org.osgi.service.cm.ConfigurationException;
import org.osgi.service.cm.ManagedService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * iec 62056-21 meter binding implementation
 * 
 * @author <NAME>
 * @author <NAME>
 * @since 1.5.0
 */
public class Iec6205621MeterBinding extends
		AbstractActiveBinding<Iec6205621MeterBindingProvider> implements
		ManagedService {

	private static final Logger logger = LoggerFactory
			.getLogger(Iec6205621MeterBinding.class);

	// regEx to validate a meter config
	// <code>'^(.*?)\\.(serialPort|baudRateChangeDelay|echoHandling)$'</code>
	private final Pattern METER_CONFIG_PATTERN = Pattern
			.compile("^(.*?)\\.(serialPort|baudRateChangeDelay|echoHandling)$");

	private static final long DEFAULT_REFRESH_INTERVAL = 60000;

	/**
	 * the refresh interval which is used to poll values from the IEC 62056-21 Meter
	 * server (optional, defaults to 10 minutes)
	 */
	private long refreshInterval = DEFAULT_REFRESH_INTERVAL;

	// configured meter devices - keyed by meter device name
	private final Map<String, Meter> meterDeviceConfigurtions = new HashMap<String, Meter>();

	public Iec6205621MeterBinding() {
	}

	public void activate() {

	}

	public void deactivate() {
		meterDeviceConfigurtions.clear();
	}

	/**
	 * @{inheritDoc
	 */
	@Override
	protected long getRefreshInterval() {
		return refreshInterval;
	}

	/**
	 * @{inheritDoc
	 */
	@Override
	protected String getName() {
		return "iec6205621meter Refresh Service";
	}

	private final Meter createIec6205621MeterConfig(String name,
			MeterConfig config) {

		Meter reader = null;
		reader = new Meter(name, config);
		return reader;
	}

	/**
	 * @{inheritDoc
	 */
	@Override
	protected void execute() {
		// the frequently executed code (polling) goes here ...
		Map<String, Map<String, DataSet>> cache = new HashMap<String, Map<String,DataSet>>();
		for (Iec6205621MeterBindingProvider provider : providers) {

			for (String itemName : provider.getItemNames()) {
				for (Entry<String, Meter> entry : meterDeviceConfigurtions.entrySet()) {
					Meter reader = entry.getValue();
					String meterName = provider.getMeterName(itemName);
{'fraction_non_alphanumeric': 0.11004784688995216, 'fraction_numerical': 0.03513755980861244, 'mean_word_length': 4.721984602224123, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '426265', 'n_tokens_mistral': 2305, 'n_tokens_neox': 2050, 'n_words': 506}