blob: 236cfeca7ebedcbee9095de59d74e5040f71d539 [file] [log] [blame]
/*
* Copyright (c) 2020 Kentyou.
* 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
*
* Contributors:
* Kentyou - initial API and implementation
*/
package org.eclipse.sensinact.gateway.app.basic.string;
import org.eclipse.sensinact.gateway.app.api.function.DataItf;
import org.json.JSONObject;
import org.json.JSONTokener;
import org.osgi.framework.BundleContext;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
/**
* This class implements the concatenate function
*
* @author Remi Druilhe
* @see StringFunction
*/
public class ConcatenateFunction extends StringFunction<String> {
private static final String JSON_SCHEMA = "concatenate.json";
/**
* Gets the JSON schema of the function from the plugin
*
* @param context the context of the bundle
* @return the JSON schema of the function
*/
public static JSONObject getJSONSchemaFunction(BundleContext context) {
try {
return new JSONObject(new JSONTokener(new InputStreamReader(context.getBundle().getResource("/" + JSON_SCHEMA).openStream())));
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
/**
* @see AbstractFunction#process(List)
*/
public void process(List<DataItf> datas) {
StringBuilder sb = new StringBuilder();
for (DataItf data : datas) {
sb.append(data.getValue());
}
super.update(sb.toString());
}
}