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

com.github.easypack.platform.Platform Maven / Gradle / Ivy

The newest version!
package com.github.easypack.platform;

import java.util.Collection;
import java.util.LinkedList;

/**
 * Models the project targeted platform (operating system).
 * 
 * @author agusmunioz
 * 
 */
public enum Platform {

	WINDOWS {

		@Override
		public  T behave(PlatformBehavioural behavioural) {
			return behavioural.windows();

		}
	},
	LINUX {
		@Override
		public  T behave(PlatformBehavioural behavioural) {
			return behavioural.linux();

		}
	};

	/**
	 * Triggers a behavior based on the specific platform.
	 * 
	 * @param behavioural
	 *            the one interested in behaving based on the platform.
	 * 
	 * @return the result of behaving based on the platform.
	 */
	public abstract  T behave(PlatformBehavioural behavioural);

	/**
	 * Gets a list of {@link Platform} using a comma separated string.
	 * 
	 * @param platforms
	 *            a comma separated list of platforms.
	 * 
	 * @return the list of {@link Platform}.
	 * 
	 * @throws IllegalArgumentException
	 *             if a not supported platform name is provided.
	 */
	public static Collection fromString(String platforms) {

		Collection mapped = new LinkedList();

		String[] selected = platforms.split(",");

		for (String platform : selected) {

			try {

				mapped.add(Platform.valueOf(platform.trim().toUpperCase()));

			} catch (IllegalArgumentException e) {

				throw new IllegalArgumentException("Unsupported platform: "
						+ platform + ". Supported: linux, windows");
			}

		}

		return mapped;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy