001 package com.croftsoft.core.lang;
002
003 import java.io.Serializable;
004
005 import com.croftsoft.core.lang.NullArgumentException;
006
007 /*********************************************************************
008 * An immutable name-value pair where name is never null.
009 *
010 * <p>
011 * Java 1.1 compatible.
012 * </p>
013 *
014 * @version
015 * 2001-09-13
016 * @since
017 * 2001-06-07
018 * @author
019 * <a href="https://www.croftsoft.com/">David Wallace Croft</a>
020 *********************************************************************/
021
022 public final class Pair
023 implements Serializable
024 //////////////////////////////////////////////////////////////////////
025 //////////////////////////////////////////////////////////////////////
026 {
027
028 private static final long serialVersionUID = 1L;
029
030 public final String name;
031
032 public final String value;
033
034 //////////////////////////////////////////////////////////////////////
035 //////////////////////////////////////////////////////////////////////
036
037 public String getName ( ) { return name; }
038
039 public String getValue ( ) { return value; }
040
041 //////////////////////////////////////////////////////////////////////
042 //////////////////////////////////////////////////////////////////////
043
044 /*********************************************************************
045 * Converts an array of names to an array of Pairs with null values.
046 *********************************************************************/
047 public static Pair [ ] toPairs ( String [ ] names )
048 //////////////////////////////////////////////////////////////////////
049 {
050 Pair [ ] pairs = new Pair [ names.length ];
051
052 for ( int i = 0; i < names.length; i++ )
053 {
054 pairs [ i ] = new Pair ( names [ i ], null );
055 }
056
057 return pairs;
058 }
059
060 //////////////////////////////////////////////////////////////////////
061 //////////////////////////////////////////////////////////////////////
062
063 /*********************************************************************
064 * Constructor method.
065 *
066 * @param name
067 *
068 * Must not be null.
069 *
070 * @param value
071 *
072 * May be null.
073 *
074 * @throws NullArgumentException
075 *
076 * If name is null.
077 *********************************************************************/
078 public Pair (
079 String name,
080 String value )
081 //////////////////////////////////////////////////////////////////////
082 {
083 NullArgumentException.check ( this.name = name );
084
085 this.value = value;
086 }
087
088 //////////////////////////////////////////////////////////////////////
089 //////////////////////////////////////////////////////////////////////
090 }