<commit_before>/*
 * (C) Copyright 2013 Kurento (http://kurento.org/)
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public License
 * (LGPL) version 2.1 which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl-2.1.html
 *
 * This library 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.
 *
 */
package com.kurento.kmf.jsonrpcconnector.internal.message;

import static com.kurento.kmf.jsonrpcconnector.JsonUtils.getGson;

import java.util.Map.Entry;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

public class MessageUtils {

	private static Logger log = LoggerFactory.getLogger(MessageUtils.class);

	public static <R> Response<R> convertResponse(
			Response<JsonElement> response, Class<R> resultClass) {

		R resultR = convertJsonTo(response.getResult(), resultClass);

		@SuppressWarnings("unchecked")
		Response<R> responseR = (Response<R>) response;

		responseR.setResult(resultR);

		return responseR;
	}

	public static <P> Request<P> convertRequest(
			Request<? extends Object> request, Class<P> paramsClass) {

		P paramsP;
		if (paramsClass.isAssignableFrom(request.getParams().getClass())) {
			paramsP = (P) request.getParams();
		} else if (request.getParams() instanceof JsonElement) {
			paramsP = convertJsonTo((JsonElement) request.getParams(),
					paramsClass);
		} else {
			throw new ClassCastException();
		}

		@SuppressWarnings("unchecked")
		Request<P> requestP = (Request<P>) request;

		requestP.setParams(paramsP);

		return requestP;
	}<commit_msg>[kmf-jsonrpcconnector-test] Fixed bug in MessageUtils<commit_after>/*
 * (C) Copyright 2013 Kurento (http://kurento.org/)
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public License
 * (LGPL) version 2.1 which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl-2.1.html
 *
 * This library 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.
 *
 */
package com.kurento.kmf.jsonrpcconnector.internal.message;

import static com.kurento.kmf.jsonrpcconnector.JsonUtils.getGson;

import java.util.Map.Entry;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

public class MessageUtils {

	private static Logger log = LoggerFactory.getLogger(MessageUtils.class);

	public static <R> Response<R> convertResponse(
			Response<JsonElement> response, Class<R> resultClass) {

		R resultR = convertJsonTo(response.getResult(), resultClass);

		@SuppressWarnings("unchecked")
		Response<R> responseR = (Response<R>) response;

		responseR.setResult(resultR);

		return responseR;
	}

	@SuppressWarnings("unchecked")
	public static <P> Request<P> convertRequest(
			Request<? extends Object> request, Class<P> paramsClass) {

		P paramsP = null;
		Object params = request.getParams();
		if (params != null) {
			if (paramsClass.isAssignableFrom(params.getClass())) {
				paramsP = (P) params;
			} else if (params instanceof JsonElement) {
				paramsP = convertJsonTo((JsonElement) request.getParams(),
						paramsClass);
			} else {
				throw new ClassCastException();
			}
		}

		@SuppressWarnings("unchecked")
		Request<P> requestP = (Request<P>) request;

		requestP.setParams(paramsP);

		return requestP;
	}
{'fraction_non_alphanumeric': 0.10605679819050012, 'fraction_numerical': 0.005026388539834129, 'mean_word_length': 4.661450924608819, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '5402282', 'n_tokens_mistral': 1268, 'n_tokens_neox': 1185, 'n_words': 344}