All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.scudata.expression.mfn.string.StrProperties Maven / Gradle / Ivy

Go to download

SPL(Structured Process Language) A programming language specially for structured data computing.

There is a newer version: 20241126
Show newest version
package com.scudata.expression.mfn.string;

import java.util.Iterator;
import java.util.Properties;
import java.util.Set;
import java.util.StringTokenizer;

class StrProperties extends Properties{
	private static final long serialVersionUID = 1L;
	String connector = "=";
	String seperator = " ";
	
	public StrProperties() {
	}
	
	public void setConnector(String c) {
		connector = c;
	}
	
	public void setSeperator(String s) {
		seperator = s;
	}
	
    public synchronized void load(String str) {
    	if (seperator!=" ") {
    		if(str.indexOf(",")>0) {
    			seperator=",";
    		} else {
    			seperator=";";
    		}
    	}
    	
    	StringTokenizer st = new StringTokenizer(str, seperator );
    	while (st.hasMoreTokens()) {
    		String tmp = st.nextToken().trim();
    		StringTokenizer seg = new StringTokenizer( tmp, connector );
    		String key = seg.nextToken().trim();
    		String val = "";
    		if(seg.hasMoreElements() ) val = seg.nextToken().trim();
    		put(key, val);
    	}
    }
	
    public String getString() {
    	StringBuffer sb = new StringBuffer();
    	Set keys = stringPropertyNames();
    	Iterator it = keys.iterator();
    	while (it.hasNext()) {
    		if (sb.length()>0) {
    			sb.append(seperator);
    		}
    		
    		String key = it.next();
    		String val = getProperty(key);
    		sb.append(key);
    		sb.append(connector);
    		sb.append(val);
    	}
    	
    	return sb.toString();
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy