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

com.ircclouds.irc.api.domain.IRCServerOptions Maven / Gradle / Ivy

There is a newer version: 1.0-0014
Show newest version
package com.ircclouds.irc.api.domain;

import java.util.*;

public class IRCServerOptions
{
	/*
	 * Immutable class.
	 */
	
	private static final String CHAN_TYPES_STR = "CHANTYPES";
	private static final String PREFIX_STR = "PREFIX";
	private static final String CHAN_MODES_STR = "CHANMODES";
	
	private final Set CHAN_TYPES = new LinkedHashSet();
	
	private Set TYPE_A = new HashSet();
	private Set TYPE_B = new HashSet();
	private Set TYPE_C = new HashSet();
	private Set TYPE_D = new HashSet();
	private ChannelModes CHAN_MODES = new ChannelModes(TYPE_A, TYPE_B, TYPE_C, TYPE_D);
	
	private Set USER_STATUSES = new HashSet();
	private IRCUserStatuses USER_CHAN_STATUSES = new IRCUserStatuses(USER_STATUSES);
		
	private Properties properties;
	
	public IRCServerOptions(Properties aProperties)
	{	
		properties = aProperties;
		
		loadChannelTypes();
		loadUserStatuses();
		loadChannelModes();
	}
	
	public String getKey(String aKey)
	{
		return properties.getProperty(aKey);
	}

	public Set getChanTypes()
	{
		return Collections.unmodifiableSet(CHAN_TYPES);
	}

	public IRCUserStatuses getUserChanStatuses()
	{
		return USER_CHAN_STATUSES;
	}

	public ChannelModes getChannelModes()
	{
		return CHAN_MODES;
	}

	public String toString()
	{
		return properties.toString();
	}	

	private void loadChannelModes()
	{
		String _chanModes = (String) properties.get(CHAN_MODES_STR);
		if (_chanModes != null)
		{
			String _classes[] = _chanModes.split(",");
			TYPE_A.addAll(getModes(_classes[0]));
			TYPE_B.addAll(getModes(_classes[1]));
			TYPE_C.addAll(getModes(_classes[2]));
			TYPE_D.addAll(getModes(_classes[3]));
		}
	}
	
	private void loadUserStatuses()
	{
		String _prefixes = (String) properties.get(PREFIX_STR);
		if (_prefixes != null)
		{
			int _1stBrkt = _prefixes.indexOf('(');
			int _2ndBrkt = _prefixes.indexOf(')');
			int _sub = _2ndBrkt - _1stBrkt;

			for (int _i = _1stBrkt + 1; _i < _2ndBrkt; _i++)
			{
				USER_STATUSES.add(new IRCUserStatus(_prefixes.charAt(_i), _prefixes.charAt(_i + _sub), _i));
			}
		}
	}
	
	private void loadChannelTypes()
	{
		String _cTypes = (String) properties.get(CHAN_TYPES_STR);
		if (_cTypes != null)
		{
			for (int _i = 0; _i < _cTypes.length(); _i++)
			{
				CHAN_TYPES.add(new Character(_cTypes.charAt(_i)));
			}
		}
	}
	
	private Set getModes(String aModes)
	{
		Set _chars = new HashSet();
		for (int _i = 0; _i < aModes.length(); _i++)
		{
			_chars.add(aModes.charAt(_i));
		}
		return _chars;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy