Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2009 Future Invent Informationsmanagement GmbH. All rights reserved. <http://www.fuin.org/> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see <http://www.gnu.org/licenses/>.
 
 package org.fuin.units4j.dependency;
 
 import java.util.List;

Package dependency rules. Caution: A package cannot be in both lists!
 
 public final class Dependencies {
 
     private final List<DependsOnalwaysAllowed;
 
     private final List<NotDependsOnalwaysForbidden;
 
     private final List<Package<DependsOn>> allowed;
 
     private final List<Package<NotDependsOn>> forbidden;

    
Default constructor.
 
     public Dependencies() {
         super();
         this. = new ArrayList<DependsOn>();
         this. = new ArrayList<NotDependsOn>();
         this. = new ArrayList<Package<DependsOn>>();
         this. = new ArrayList<Package<NotDependsOn>>();
     }

    
Returns a list of packages like "java.lang" that are always Ok to depend on.

Returns:
List of packages.
 
     public final List<DependsOngetAlwaysAllowed() {
         if ( == null) {
             // This can only happen with serialization
             return Collections.emptyList();
         }
         return ;
     }

    
Returns a list of packages that are always forbidden to depend on.

Returns:
List of packages.
 
     public final List<NotDependsOngetAlwaysForbidden() {
         if ( == null) {
             // This can only happen with serialization
             return Collections.emptyList();
         }
         return ;
     }

    
Checks if the package is always OK.

Parameters:
packageName Name of the package to check.
Returns:
If the package is always allowed true else false.
 
     public final boolean isAlwaysAllowed(final String packageName) {
         if (packageName.equals("java.lang")) {
             return true;
         }
         return Utils.findAllowedByName(getAlwaysAllowed(), packageName) != null;
     }

    
Checks if the package is always forbidden.

Parameters:
packageName Name of the package to check.
Returns:
If the package is always forbidden true else false.
 
    public final boolean isAlwaysForbidden(final String packageName) {
        return Utils.findForbiddenByName(getAlwaysForbidden(), packageName) != null;
    }

    
Returns the list of allowed package dependencies.

Returns:
List of explicit allowed dependencies - All other dependencies are considered to be an error.
    public final List<Package<DependsOn>> getAllowed() {
        if ( == null) {
            // This can only happen with serialization
            return Collections.emptyList();
        }
        return ;
    }

    
Returns the list of forbidden package dependencies.

Returns:
List of explicit forbidden dependencies - All other dependencies are considered to be valid.
    public final List<Package<NotDependsOn>> getForbidden() {
        if ( == null) {
            // This can only happen with serialization
            return Collections.emptyList();
        }
        return ;
    }

    
Checks if the definition is valid - Especially if no package is in both lists.

Throws:
InvalidDependenciesDefinitionException This instance is invalid.
    public final void validate() throws InvalidDependenciesDefinitionException {
        int errorCount = 0;
        final StringBuffer sb = new StringBuffer(
                "Duplicate package entries in 'allowed' and 'forbidden': ");
        final List<Package<NotDependsOn>> list = getForbidden();
        for (int i = 0; i < list.size(); i++) {
            final String name = list.get(i).getName();
            final Package<DependsOndep = new Package<DependsOn>(name);
            if (getAllowed().indexOf(dep) > -1) {
                if (errorCount > 0) {
                    sb.append(", ");
                }
                sb.append(name);
                errorCount++;
            }
        }
        if (errorCount > 0) {
            throw new InvalidDependenciesDefinitionException(thissb.toString());
        }
    }

    
Find an entry in the allowed list by package name.

Parameters:
packageName Name to find.
Returns:
Package or null if no entry with the given name was found.
    public final Package<DependsOnfindAllowedByName(final String packageName) {
        final List<Package<DependsOn>> list = getAllowed();
        for (final Package<DependsOnpkg : list) {
            if (pkg.getName().equals(packageName)) {
                return pkg;
            }
        }
        return null;
    }

    
Find an entry in the forbidden list by package name.

Parameters:
packageName Name to find.
Returns:
Package or null if no entry with the given name was found.
    public final Package<NotDependsOnfindForbiddenByName(final String packageName) {
        final List<Package<NotDependsOn>> list = getForbidden();
        for (final Package<NotDependsOnpkg : list) {
            if (pkg.getName().equals(packageName)) {
                return pkg;
            }
        }
        return null;
    }
New to GrepCode? Check out our FAQ X