PROXY  WHOIS  RQUOTE  TEXTS  SOFT  FOREX  BBOARD
 Music  Philosophy  Code  Literature  Russian

= ROOT|Technical|Code_Examples|Java|javax|accessibility|AccessibleRelationSet.java =

page 1 of 3



/*
 * @(#)AccessibleRelationSet.java	1.15 06/04/07
 *
 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

package javax.accessibility;

import java.util.Vector;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

/**
 * Class AccessibleRelationSet determines a component's relation set.  The 
 * relation set of a component is a set of AccessibleRelation objects that 
 * describe the component's relationships with other components.
 *
 * @see AccessibleRelation
 *
 * @version     1.15 04/07/06
 * @author      Lynn Monsanto
 * @since 1.3
 */
public class AccessibleRelationSet {

    /**
     * Each entry in the Vector represents an AccessibleRelation.
     * @see #add
     * @see #addAll
     * @see #remove
     * @see #contains
     * @see #get
     * @see #size
     * @see #toArray
     * @see #clear
     */
    protected Vector<AccessibleRelation> relations = null;

    /**
     * Creates a new empty relation set.
     */
    public AccessibleRelationSet() {
        relations = null;
    }

    /**
     * Creates a new relation with the initial set of relations contained in 
     * the array of relations passed in.  Duplicate entries are ignored.
     *
     * @param relations an array of AccessibleRelation describing the 
     * relation set.
     */
    public AccessibleRelationSet(AccessibleRelation[] relations) {
        if (relations.length != 0) {
            this.relations = new Vector(relations.length);
            for (int i = 0; i < relations.length; i++) {
		add(relations[i]);
            }
        }
    }

    /**
     * Adds a new relation to the current relation set.  If the relation 
     * is already in the relation set, the target(s) of the specified
     * relation is merged with the target(s) of the existing relation.  
     * Otherwise,  the new relation is added to the relation set.
     *
     * @param relation the relation to add to the relation set
     * @return true if relation is added to the relation set; false if the 
     * relation set is unchanged
     */
    public boolean add(AccessibleRelation relation) {
        if (relations == null) {
            relations = new Vector();
        }

	// Merge the relation targets if the key exists
	AccessibleRelation existingRelation = get(relation.getKey());
	if (existingRelation == null) {
            relations.addElement(relation);
            return true;
        } else {
	    Object [] existingTarget = existingRelation.getTarget();
	    Object [] newTarget = relation.getTarget();
	    int mergedLength = existingTarget.length + newTarget.length;
	    Object [] mergedTarget = new Object[mergedLength];
	    for (int i = 0; i < existingTarget.length; i++) {
		mergedTarget[i] = existingTarget[i];
	    }
	    for (int i = existingTarget.length, j = 0; 
		 i < mergedLength; 
		 i++, j++) {
		mergedTarget[i] = newTarget[j];
	    }
	    existingRelation.setTarget(mergedTarget);
        }
	return true;
    }
=1=

= PAGE 1 = NEXT > |2|3

UP TO ROOT | UP TO DIR

Google
 


E-mail Facebook Google Digg del.icio.us BlinkList Fark Furl Ma.gnolia Netscape NewsVine Reddit Slashdot Spurl StumbleUpon Technorati YahooMyWeb LiveJournal Blogmarks TwitThis Live News2.ru BobrDobr.ru Memori.ru MoeMesto.ru

0.0168641 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)