[Adapdev-commits] Adapdev/src/Adapdev.NVelocity/Commons/Collections CollectionsUtil.cs,1.2,1.3 Exten
Status: Beta
Brought to you by:
intesar66
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.NVelocity/Commons/Collections In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22005/src/Adapdev.NVelocity/Commons/Collections Added Files: CollectionsUtil.cs ExtendedProperties.cs PropertiesReader.cs PropertiesTokenizer.cs StringTokenizer.cs Log Message: --- NEW FILE: StringTokenizer.cs --- namespace Commons.Collections { using System; using System.Collections; public class StringTokenizer { private ArrayList elements; private string source; //The tokenizer uses the default delimiter set: the space character, the tab character, the newline character, and the carriage-return character private string delimiters = " \t\n\r"; public StringTokenizer(string source) { this.elements = new ArrayList(); this.elements.AddRange(source.Split(this.delimiters.ToCharArray())); this.RemoveEmptyStrings(); this.source = source; } public StringTokenizer(string source, string delimiters) { this.elements = new ArrayList(); this.delimiters = delimiters; this.elements.AddRange(source.Split(this.delimiters.ToCharArray())); this.RemoveEmptyStrings(); this.source = source; } public int Count { get { return (this.elements.Count); } } public bool HasMoreTokens() { return (this.elements.Count > 0); } public string NextToken() { string result; if (source == "") { throw new Exception(); } else { this.elements = new ArrayList(); this.elements.AddRange(this.source.Split(delimiters.ToCharArray())); RemoveEmptyStrings(); result = (string) this.elements[0]; this.elements.RemoveAt(0); this.source = this.source.Replace(result, ""); this.source = this.source.TrimStart(this.delimiters.ToCharArray()); return result; } } public string NextToken(string delimiters) { this.delimiters = delimiters; return NextToken(); } private void RemoveEmptyStrings() { //VJ++ does not treat empty strings as tokens for (int index = 0; index < this.elements.Count; index++) if ((string) this.elements[index] == "") { this.elements.RemoveAt(index); index--; } } } } --- NEW FILE: PropertiesTokenizer.cs --- namespace Commons.Collections { using System; using System.Text; /// <summary> This class divides into tokens a property value. Token /// separator is "," but commas into the property value are escaped /// using the backslash in front. /// </summary> internal class PropertiesTokenizer : StringTokenizer { /// <summary> The property delimiter used while parsing (a comma). /// </summary> internal const String DELIMITER = ","; /// <summary> Constructor. /// </summary> /// <param name="string">A String. /// </param> public PropertiesTokenizer(String string_Renamed) : base(string_Renamed, DELIMITER) { } /// <summary> Check whether the object has more tokens. /// </summary> /// <returns>True if the object has more tokens. /// </returns> //UPGRADE_TODO: The equivalent of method java.util.StringTokenizer.hasMoreTokens is not an override method. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca5065"' public bool HasMoreTokens() { return base.HasMoreTokens(); } /// <summary> Get next token. /// </summary> /// <returns>A String. /// </returns> //UPGRADE_TODO: The equivalent of method java.util.StringTokenizer.nextToken is not an override method. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca5065"' public String NextToken() { StringBuilder buffer = new StringBuilder(); while (HasMoreTokens()) { String token = base.NextToken(); if (token.EndsWith("\\")) { buffer.Append(token.Substring(0, (token.Length - 1) - (0))); buffer.Append(DELIMITER); } else { buffer.Append(token); break; } } return buffer.ToString().Trim(); } } } --- NEW FILE: CollectionsUtil.cs --- namespace Commons.Collections { using System; using System.Collections; /// <summary> /// Static utility methods for collections /// </summary> public class CollectionsUtil { public static Object PutElement(Hashtable hashTable, Object key, Object newValue) { Object element = hashTable[key]; hashTable[key] = newValue; return element; } } } --- NEW FILE: ExtendedProperties.cs --- namespace Commons.Collections { using System; using System.Collections; using System.IO; using System.Text; /// <summary> This class extends normal Java properties by adding the possibility /// to use the same key many times concatenating the value strings /// instead of overwriting them. /// /// <p>The Extended Properties syntax is explained here: /// /// <ul> /// <li> /// Each property has the syntax <code>key = value</code> /// </li> /// <li> /// The <i>key</i> may use any character but the equal sign '='. [...1664 lines suppressed...] /// </param> /// <returns>ExtendedProperties configuration created from the /// properties object. /// /// </returns> public static ExtendedProperties ConvertProperties(ExtendedProperties p) { ExtendedProperties c = new ExtendedProperties(); for (IEnumerator e = (IEnumerator) p.Keys; e.MoveNext(); ) { String key = (String) e.Current; String value = p.GetProperty(key).ToString(); c.SetProperty(key, value); } return c; } } } --- NEW FILE: PropertiesReader.cs --- namespace Commons.Collections { using System; using System.IO; using System.Text; /// <summary> This class is used to read properties lines. These lines do /// not terminate with new-line chars but rather when there is no /// backslash sign a the end of the line. This is used to /// concatenate multiple lines for readability. /// </summary> internal class PropertiesReader : StreamReader { /// <summary> Constructor. /// * /// </summary> /// <param name="reader">A Reader. /// /// </param> public PropertiesReader(StreamReader reader) : base(reader.BaseStream) { } /// <summary> Read a property. /// * /// </summary> /// <returns>A String. /// </returns> /// <exception cref="">IOException. /// /// </exception> public virtual String ReadProperty() { StringBuilder buffer = new StringBuilder(); try { while (true) { String line = ReadLine().Trim(); if ((line.Length != 0) && (line[0] != '#')) { if (line.EndsWith("\\")) { line = line.Substring(0, (line.Length - 1) - (0)); buffer.Append(line); } else { buffer.Append(line); break; } } } } catch (NullReferenceException e) { return null; } return buffer.ToString(); } } } |