package com.ese.ils.beta.util;
import java.text.DecimalFormat;
/**
* Hilfsklasse fuer String Operationen
* @author julien hofer
*
*/
public class DeComposer {
/**
* trennt einen uebergebenen String Parameter <code>toDecompose</code>
* Der String muss ein $ zeichen als Delimiter haben
* @param toDecompose
* @return idArray
*/
public static int[] stringToIntDecomposing(String toDecompose) {
String[] splittetIds = toDecompose.split("\\$", 2);
int[] idArray = new int[2];
idArray[0] = Integer.parseInt(splittetIds[0]);
idArray[1] = Integer.parseInt(splittetIds[1]);
return idArray;
}
public static long[] stringToLongDecomposing(String toDecompose) {
String[] splittetIds = toDecompose.split("\\$", 2);
long[] idArray = new long[2];
idArray[0] = Long.valueOf(splittetIds[0]);
idArray[1] = Long.valueOf(splittetIds[1]);
return idArray;
}
/**
* erzeugt einen String mit zwei Integer Werten. Die Werte werden
* konkateniert und durch ein $ Zeichen getrennt. Ebenfalls werden die
* Werte mit Nullen aufgefuellt
*
* @param ModulId
* @param SlideId
* @return
*/
public static String longToStringComposer(long moduleId, long slideId) {
String strModulSlideId = null;
DecimalFormat df = new DecimalFormat("00000");
strModulSlideId = df.format(moduleId) + "$" + df.format(slideId);
return strModulSlideId;
}
public static String longToFilename(long slideId) {
String strSlideId = null;
DecimalFormat df = new DecimalFormat("00000");
strSlideId = df.format(slideId);
System.out.println(strSlideId);
return strSlideId;
}
public static String longToPrimaryKey(long moduleId, long slideId) {
String strPrimaryKey = null;
DecimalFormat df = new DecimalFormat("00000");
strPrimaryKey = df.format(moduleId) + df.format(slideId);
System.out.println(strPrimaryKey);
return strPrimaryKey;
}
public static String slideIdToModuleId(String string){
return string.substring(0,3);
}
public static String slideIdToSlideNr(String string){
return string.substring(5);
}
}