<commit_before>package org.cytoscape.model.internal;

/*
 * #%L
 * Cytoscape Model Impl (model-impl)
 * $Id:$
 * $HeadURL:$
 * %%
 * Copyright (C) 2010 - 2013 The Cytoscape Consortium
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as 
 * published by the Free Software Foundation, either version 2.1 of the 
 * License, or (at your option) any later version.
 * 
 * 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 General Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public 
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/lgpl-2.1.html>.
 * #L%
 */


import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;

import org.cytoscape.equations.Equation;
import org.cytoscape.equations.IdentDescriptor;
import org.cytoscape.equations.Interpreter;
import org.cytoscape.model.internal.tsort.TopoGraphNode;
import org.cytoscape.model.internal.tsort.TopologicalSort;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


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

	private EqnSupport() { } // Don't ever create an instance of this class!

	static boolean scalarEquationIsCompatible(final Object equationCandidate,
						  final Class targetType)
	{
		if (!(equationCandidate instanceof Equation))
			return false;

		final Equation equation = (Equation)equationCandidate;
		final Class<?> eqnReturnType = equation.getType();

		if (targetType == Double.class || targetType == Boolean.class
		    || targetType == Integer.class || targetType == Long.class)
			return eqnReturnType == Double.class || eqnReturnType == Boolean.class
			       || eqnReturnType == Integer.class || eqnReturnType == Long.class;
		else if (targetType == String.class)
			return true; // Everything can be turned into a String!
		else
			return false;
	}

	static boolean listEquationIsCompatible(final Equation equation, final Class listElementType)
	{
		// TODO: We no longer support strongly typed lists so this always
		// returns true.  If we ever re-introduce strongly typed lists, we
		// should modify this to do the appropriate checks.
		return true;
	}

	static Object convertEqnResultToColumnType(final Class<?> columnType, final Object result) {
		final Class<?> resultType = result.getClass();
		if (resultType == columnType)
			return result;<commit_msg>Revert "Refs #2514 - resolves issue with Integer equations causing NPE"<commit_after>package org.cytoscape.model.internal;

/*
 * #%L
 * Cytoscape Model Impl (model-impl)
 * $Id:$
 * $HeadURL:$
 * %%
 * Copyright (C) 2010 - 2013 The Cytoscape Consortium
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as 
 * published by the Free Software Foundation, either version 2.1 of the 
 * License, or (at your option) any later version.
 * 
 * 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 General Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public 
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/lgpl-2.1.html>.
 * #L%
 */


import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;

import org.cytoscape.equations.Equation;
import org.cytoscape.equations.IdentDescriptor;
import org.cytoscape.equations.Interpreter;
import org.cytoscape.model.internal.tsort.TopoGraphNode;
import org.cytoscape.model.internal.tsort.TopologicalSort;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


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

	private EqnSupport() { } // Don't ever create an instance of this class!

	static boolean scalarEquationIsCompatible(final Object equationCandidate,
						  final Class targetType)
	{
		if (!(equationCandidate instanceof Equation))
			return false;

		final Equation equation = (Equation)equationCandidate;
		final Class<?> eqnReturnType = equation.getType();

		if (targetType == Double.class || targetType == Boolean.class
		    || targetType == Integer.class || targetType == Long.class)
			return eqnReturnType == Double.class || eqnReturnType == Long.class
			       || eqnReturnType == Boolean.class;
		else if (targetType == String.class)
			return true; // Everything can be turned into a String!
		else
			return false;
	}

	static boolean listEquationIsCompatible(final Equation equation, final Class listElementType)
	{
		// TODO: We no longer support strongly typed lists so this always
		// returns true.  If we ever re-introduce strongly typed lists, we
		// should modify this to do the appropriate checks.
		return true;
	}

	static Object convertEqnResultToColumnType(final Class<?> columnType, final Object result) {
		final Class<?> resultType = result.getClass();
		if (resultType == columnType)
			return result;
{'fraction_non_alphanumeric': 0.09148321905449296, 'fraction_numerical': 0.00577408877661494, 'mean_word_length': 4.146703806870938, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '1920734', 'n_tokens_mistral': 1689, 'n_tokens_neox': 1541, 'n_words': 560}