148
149 public class CompoundName implements Name {
150
151 /**
152 * Implementation of this compound name.
153 * This field is initialized by the constructors and cannot be null.
154 * It should be treated as a read-only variable by subclasses.
155 */
156 protected transient NameImpl impl;
157 /**
158 * Syntax properties for this compound name.
159 * This field is initialized by the constructors and cannot be null.
160 * It should be treated as a read-only variable by subclasses.
161 * Any necessary changes to mySyntax should be made within constructors
162 * and not after the compound name has been instantiated.
163 */
164 protected transient Properties mySyntax;
165
166 /**
167 * Constructs a new compound name instance using the components
168 * specified in comps and syntax. This protected method is intended to be
169 * to be used by subclasses of CompoundName when they override
170 * methods such as clone(), getPrefix(), getSuffix().
171 *
172 * @param comps A non-null enumeration of the components to add.
173 * Each element of the enumeration is of class String.
174 * The enumeration will be consumed to extract its
175 * elements.
176 * @param syntax A non-null properties that specify the syntax of
177 * this compound name. See class description for
178 * contents of properties.
179 */
180 protected CompoundName(Enumeration<String> comps, Properties syntax) {
181 if (syntax == null) {
182 throw new NullPointerException();
183 }
184 mySyntax = syntax;
185 impl = new NameImpl(syntax, comps);
186 }
187
188 /**
348 }
349
350 /**
351 * Retrieves a component of this compound name.
352 *
353 * @param posn The 0-based index of the component to retrieve.
354 * Must be in the range [0,size()).
355 * @return The component at index posn.
356 * @exception ArrayIndexOutOfBoundsException if posn is outside the
357 * specified range.
358 */
359 public String get(int posn) {
360 return (impl.get(posn));
361 }
362
363 /**
364 * Creates a compound name whose components consist of a prefix of the
365 * components in this compound name.
366 * The result and this compound name share the same syntax.
367 * Subsequent changes to
368 * this compound name does not affect the name that is returned and
369 * vice versa.
370 *
371 * @param posn The 0-based index of the component at which to stop.
372 * Must be in the range [0,size()].
373 * @return A compound name consisting of the components at indexes in
374 * the range [0,posn).
375 * @exception ArrayIndexOutOfBoundsException
376 * If posn is outside the specified range.
377 */
378 public Name getPrefix(int posn) {
379 Enumeration<String> comps = impl.getPrefix(posn);
380 return (new CompoundName(comps, mySyntax));
381 }
382
383 /**
384 * Creates a compound name whose components consist of a suffix of the
385 * components in this compound name.
386 * The result and this compound name share the same syntax.
387 * Subsequent changes to
388 * this compound name does not affect the name that is returned.
389 *
390 * @param posn The 0-based index of the component at which to start.
391 * Must be in the range [0,size()].
392 * @return A compound name consisting of the components at indexes in
393 * the range [posn,size()). If posn is equal to
394 * size(), an empty compound name is returned.
395 * @exception ArrayIndexOutOfBoundsException
396 * If posn is outside the specified range.
397 */
398 public Name getSuffix(int posn) {
399 Enumeration<String> comps = impl.getSuffix(posn);
400 return (new CompoundName(comps, mySyntax));
401 }
402
403 /**
404 * Determines whether a compound name is a prefix of this compound name.
405 * A compound name 'n' is a prefix if it is equal to
406 * getPrefix(n.size())--in other words, this compound name
407 * starts with 'n'.
408 * If n is null or not a compound name, false is returned.
409 *<p>
410 * Implementation note: Currently the syntax properties of n
411 * are not used when doing the comparison. They might be in the future.
412 * @param n The possibly null compound name to check.
413 * @return true if n is a CompoundName and
414 * is a prefix of this compound name, false otherwise.
415 */
416 public boolean startsWith(Name n) {
417 if (n instanceof CompoundName) {
418 return (impl.startsWith(n.size(), n.getAll()));
419 } else {
420 return false;
421 }
422 }
423
424 /**
425 * Determines whether a compound name is a suffix of this compound name.
426 * A compound name 'n' is a suffix if it it is equal to
427 * getSuffix(size()-n.size())--in other words, this
428 * compound name ends with 'n'.
429 * If n is null or not a compound name, false is returned.
430 *<p>
431 * Implementation note: Currently the syntax properties of n
432 * are not used when doing the comparison. They might be in the future.
433 * @param n The possibly null compound name to check.
434 * @return true if n is a CompoundName and
435 * is a suffix of this compound name, false otherwise.
436 */
437 public boolean endsWith(Name n) {
438 if (n instanceof CompoundName) {
439 return (impl.endsWith(n.size(), n.getAll()));
440 } else {
441 return false;
442 }
443 }
444
445 /**
446 * Adds the components of a compound name -- in order -- to the end of
|
148
149 public class CompoundName implements Name {
150
151 /**
152 * Implementation of this compound name.
153 * This field is initialized by the constructors and cannot be null.
154 * It should be treated as a read-only variable by subclasses.
155 */
156 protected transient NameImpl impl;
157 /**
158 * Syntax properties for this compound name.
159 * This field is initialized by the constructors and cannot be null.
160 * It should be treated as a read-only variable by subclasses.
161 * Any necessary changes to mySyntax should be made within constructors
162 * and not after the compound name has been instantiated.
163 */
164 protected transient Properties mySyntax;
165
166 /**
167 * Constructs a new compound name instance using the components
168 * specified in comps and syntax. This protected method is intended
169 * to be used by subclasses of CompoundName when they override
170 * methods such as clone(), getPrefix(), getSuffix().
171 *
172 * @param comps A non-null enumeration of the components to add.
173 * Each element of the enumeration is of class String.
174 * The enumeration will be consumed to extract its
175 * elements.
176 * @param syntax A non-null properties that specify the syntax of
177 * this compound name. See class description for
178 * contents of properties.
179 */
180 protected CompoundName(Enumeration<String> comps, Properties syntax) {
181 if (syntax == null) {
182 throw new NullPointerException();
183 }
184 mySyntax = syntax;
185 impl = new NameImpl(syntax, comps);
186 }
187
188 /**
348 }
349
350 /**
351 * Retrieves a component of this compound name.
352 *
353 * @param posn The 0-based index of the component to retrieve.
354 * Must be in the range [0,size()).
355 * @return The component at index posn.
356 * @exception ArrayIndexOutOfBoundsException if posn is outside the
357 * specified range.
358 */
359 public String get(int posn) {
360 return (impl.get(posn));
361 }
362
363 /**
364 * Creates a compound name whose components consist of a prefix of the
365 * components in this compound name.
366 * The result and this compound name share the same syntax.
367 * Subsequent changes to
368 * this compound name do not affect the name that is returned and
369 * vice versa.
370 *
371 * @param posn The 0-based index of the component at which to stop.
372 * Must be in the range [0,size()].
373 * @return A compound name consisting of the components at indexes in
374 * the range [0,posn).
375 * @exception ArrayIndexOutOfBoundsException
376 * If posn is outside the specified range.
377 */
378 public Name getPrefix(int posn) {
379 Enumeration<String> comps = impl.getPrefix(posn);
380 return (new CompoundName(comps, mySyntax));
381 }
382
383 /**
384 * Creates a compound name whose components consist of a suffix of the
385 * components in this compound name.
386 * The result and this compound name share the same syntax.
387 * Subsequent changes to
388 * this compound name do not affect the name that is returned.
389 *
390 * @param posn The 0-based index of the component at which to start.
391 * Must be in the range [0,size()].
392 * @return A compound name consisting of the components at indexes in
393 * the range [posn,size()). If posn is equal to
394 * size(), an empty compound name is returned.
395 * @exception ArrayIndexOutOfBoundsException
396 * If posn is outside the specified range.
397 */
398 public Name getSuffix(int posn) {
399 Enumeration<String> comps = impl.getSuffix(posn);
400 return (new CompoundName(comps, mySyntax));
401 }
402
403 /**
404 * Determines whether a compound name is a prefix of this compound name.
405 * A compound name 'n' is a prefix if it is equal to
406 * getPrefix(n.size())--in other words, this compound name
407 * starts with 'n'.
408 * If n is null or not a compound name, false is returned.
409 *<p>
410 * Implementation note: Currently the syntax properties of n
411 * are not used when doing the comparison. They might be in the future.
412 * @param n The possibly null compound name to check.
413 * @return true if n is a CompoundName and
414 * is a prefix of this compound name, false otherwise.
415 */
416 public boolean startsWith(Name n) {
417 if (n instanceof CompoundName) {
418 return (impl.startsWith(n.size(), n.getAll()));
419 } else {
420 return false;
421 }
422 }
423
424 /**
425 * Determines whether a compound name is a suffix of this compound name.
426 * A compound name 'n' is a suffix if it is equal to
427 * getSuffix(size()-n.size())--in other words, this
428 * compound name ends with 'n'.
429 * If n is null or not a compound name, false is returned.
430 *<p>
431 * Implementation note: Currently the syntax properties of n
432 * are not used when doing the comparison. They might be in the future.
433 * @param n The possibly null compound name to check.
434 * @return true if n is a CompoundName and
435 * is a suffix of this compound name, false otherwise.
436 */
437 public boolean endsWith(Name n) {
438 if (n instanceof CompoundName) {
439 return (impl.endsWith(n.size(), n.getAll()));
440 } else {
441 return false;
442 }
443 }
444
445 /**
446 * Adds the components of a compound name -- in order -- to the end of
|