/* MIT ICT4DLab SMS Lab framework
 * 
 * Copyright (C) 2008, Massachusetts Institute of Technology
 * 
 * ICT4DLab SMS is distributed under the terms of the Apache License version 2.0
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * original author: Luis F. G. Sarmenta ( lfgs @ mit . edu ) 
 * v0.1.0: 20080228
 * 
 * Last modified by:
 * date:
 * comment:
 */

package org.ict4dlab.sms.core;

public class SMSAppUtil {

    /**
     * Convenience function which takes an incoming message and creates a new
     * SMSMessage instance with the source and destinations reversed, which can
     * be used as the return value
     * 
     * @param msg
     *                SMSMessage to be sent
     * @return true if successful
     */
    public static SMSMessage createEmptyReturnMsg(SMSMessage incomingMsg) {
	// swap source and dest, and default to empty string to avoid null
	// pointer errors
	return new SMSMessage(incomingMsg.getDestAddr(), incomingMsg
		.getSrcAddr(), "");
    }

    /**
     * Convenience function that takes array of Strings and concatenates
     * elements from startIndex to endIndex (inclusive), delimited by a space.
     * This is useful for concatenating things like command-line arguments into
     * one string.
     * 
     * @param arr
     * @param startIndex
     * @param endIndex
     * @return
     */
    public static String concatFromStringArray(String[] arr, int startIndex,
	    int endIndex) {
	String s = "";
	for (int i = startIndex; (i < arr.length) && (i <= endIndex); i++) {
	    if (s.length() > 0) {
		s = s + " ";
	    }
	    s = s + arr[i];
	}
	return s;
    }

}
