Java tutorial
/* * Copyright 2012 AMG.lab, a Bull Group Company * * 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. */ package org.xlcloud.console.images.utils; import java.util.LinkedList; import java.util.List; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.Transformer; import org.apache.commons.lang.StringUtils; import org.xlcloud.service.Image.Properties; import org.xlcloud.service.Image.Properties.Property; /** * TODO Documentation * * @author Andrzej Stasiak, AMG.net */ public class PropertyStringConverter { public static Properties parseProperties(String propertiesString) { try { Properties result = new Properties(); if (StringUtils.isBlank(propertiesString)) { return result; } String[] properties = propertiesString.split(","); for (String property : properties) { String[] propParts = property.split("="); result.getProperty().add(new Property(propParts[0], propParts[1])); } return result; } catch (IndexOutOfBoundsException e) { throw new IllegalArgumentException(); } } public static String stringifyProperties(Properties properties) { if (properties == null) { return ""; } List<String> props = new LinkedList<String>(); CollectionUtils.collect(properties.getProperty(), new Transformer() { public String transform(Object input) { Property property = (Property) input; return property.getName() + "=" + property.getValue(); } }, props); return StringUtils.join(props, ","); } }