/** * Creates a new preference. * @param type the type of value this preference uses * @param path a unique path for this preference, all paths starting with * "dock" are reserved for this framework */ public DefaultPreference( Path type, Path path ){ if( type == null ) throw new IllegalArgumentException( "type must not be null" ); if( path == null ) throw new IllegalArgumentException( "path must not be null" ); if( path.getSegmentCount() == 0 ) throw new IllegalArgumentException( "the root path is not a valid path for a preference" ); this.type = type; this.path = path; }
/** * Adds a new factory to this storage, the factory will be responsible to * write or read some kind of preferences. If there is already a factory * for <code>type</code>, then the old factory will be replaced by * <code>factory</code> * @param type the type of values <code>factory</code> handles, this path * is most times just the name of some class. Node: there is a set of * standard paths defined in {@link Path} * @param factory the new factory */ public void addFactory( Path type, PreferenceFactory<?> factory ){ if( type == null ) throw new IllegalArgumentException( "type must not be null" ); if( factory == null ) throw new IllegalArgumentException( "factory must not be null" ); if( type.getSegmentCount() == 0 ) throw new IllegalArgumentException( "the root path is not a valid path for this metho" ); factories.put( type, factory ); }
/** * Tells whether the first segments of this {@link Path} matches * the segments of <code>path</code>. * @param path some other path * @return <code>true</code> if this path is either equal to <code>path</code> or * if this path starts with <code>path</code> */ public boolean startsWith( Path path ){ if( path.getSegmentCount() > getSegmentCount() ){ return false; } for( int i = 0, n = path.getSegmentCount(); i<n; i++ ){ if( !path.getSegment( i ).equals( getSegment( i ) )){ return false; } } return true; }
private Node getNode( Path path, boolean create, int segment ){ if( path.getSegmentCount() == segment ) return this; if( children == null ){ children = new ArrayList<Node>(); } String name = path.getSegment( segment ); for( Node child : children ){ if( name.equals( child.getName() )){ return child.getNode( path, create, segment+1 ); } } if( !create ) return null; Node result = new Node( name ); children.add( result ); return result.getNode( path, create, segment+1 ); } }
public TreeNode getNode( Path path, int segment ){ if( segment == path.getSegmentCount() ) return this; if( children == null ){ children = new ArrayList<TreeNode>(); } String check = path.getSegment( segment ); for( TreeNode child : children ){ if( check.equals( child.getPath().getLastSegment() )){ return child.getNode( path, segment+1 ); } } TreeNode child = new TreeNode( this, path.subPath( 0, segment+1 ) ); children.add( child ); fireNodeAdded( this, child ); return child.getNode( path, segment+1 ); }
public void delete( Path path, int segment ){ if( segment == path.getSegmentCount() ){ delete( false ); } else if( children != null ){ String check = path.getSegment( segment ); for( TreeNode child : children ){ if( check.equals( child.getPath().getLastSegment() )){ child.delete( path, segment+1 ); break; } } } }
public boolean isValidPlaceholder( Path placeholder ){ if( placeholder.getSegmentCount() != 3 ){ return true;
public boolean isValidPlaceholder( Path placeholder ){ if( placeholder.getSegmentCount() != 3 ){ return false;