alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 * 
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 * 
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.modules.vcscore.commands;

import java.util.*;
import java.beans.*;

import org.openide.NotifyDescriptor;

/**
 * This class contains static methods for getting and setting command properties.
 *
 * @author  Martin Entlicher
 */
public class VcsCommandIO extends Object {

    public static HashMap defaultPropertyValues = null;
    
    /** Creates new VcsCommandIO */
    public VcsCommandIO() {
    }
    
    private static void initDefaultPropertyValues() {
        defaultPropertyValues = new HashMap();
        defaultPropertyValues.put(VcsCommand.PROPERTY_CONCURRENT_EXECUTION, new Integer(VcsCommand.EXEC_CONCURRENT_ALL));
        defaultPropertyValues.put(VcsCommand.PROPERTY_ON_FILE, Boolean.TRUE);
        defaultPropertyValues.put(VcsCommand.PROPERTY_ON_DIR, Boolean.TRUE);
        defaultPropertyValues.put(VcsCommand.PROPERTY_ON_ROOT, Boolean.TRUE);
        defaultPropertyValues.put(VcsCommand.PROPERTY_REFRESH_CURRENT_FOLDER, Boolean.FALSE);
        defaultPropertyValues.put(VcsCommand.PROPERTY_REFRESH_PARENT_FOLDER, Boolean.FALSE);
        defaultPropertyValues.put(VcsCommand.PROPERTY_REFRESH_ON_FAIL, new Integer(0));
        defaultPropertyValues.put(VcsCommand.PROPERTY_DISPLAY_PLAIN_OUTPUT, Boolean.FALSE);
        defaultPropertyValues.put(VcsCommand.PROPERTY_PROCESS_ALL_FILES, Boolean.FALSE);
        defaultPropertyValues.put(VcsCommand.PROPERTY_RUN_ON_MULTIPLE_FILES, Boolean.FALSE);
        defaultPropertyValues.put(VcsCommand.PROPERTY_RUN_ON_MULTIPLE_FILES_IN_FOLDER, Boolean.FALSE);
        defaultPropertyValues.put(VcsCommand.PROPERTY_NEEDS_HIERARCHICAL_ORDER, Boolean.FALSE);
        defaultPropertyValues.put(VcsCommand.PROPERTY_CHECK_FOR_MODIFICATIONS, Boolean.FALSE);
        defaultPropertyValues.put(VcsCommand.PROPERTY_IGNORE_FAIL, Boolean.FALSE);
        defaultPropertyValues.put(VcsCommand.PROPERTY_NUM_REVISIONS, new Integer(0));
        defaultPropertyValues.put(VcsCommand.PROPERTY_CHANGING_NUM_REVISIONS, Boolean.FALSE);
        defaultPropertyValues.put(VcsCommand.PROPERTY_CHANGING_REVISION, Boolean.FALSE);
        defaultPropertyValues.put(VcsCommand.PROPERTY_DISTINGUISH_BINARY_FILES, Boolean.FALSE);
        defaultPropertyValues.put(VcsCommand.PROPERTY_SUPPORTS_ADVANCED_MODE, Boolean.FALSE);
        defaultPropertyValues.put(VcsCommand.PROPERTY_HIDDEN, Boolean.FALSE);
    }
    
    /**
     * Get the default value of a command property. When the property is not defined,
     * this value determines the default behavior.
     * @param propertyName the property name to get the default value for
     * @return the default value of the property
     */
    public static Object getDefaultPropertyValue(String propertyName) {
        if (defaultPropertyValues == null) {
            initDefaultPropertyValues();
        }
        return defaultPropertyValues.get(propertyName);
    }
    
    /**
     * Get the boolean value of the command property.
     * @param command the command to get the property of
     * @param propertyName the name of the property
     * @return the boolean value of the command property or false when the property does not exist.
     */
    public static boolean getBooleanProperty(VcsCommand command, String propertyName) {
        Object value = command.getProperty(propertyName);
        if (value instanceof Boolean) {
            return ((Boolean) value).booleanValue();
        } else {
            return false;
        }
    }
    
    /**
     * Get the boolean value of the command property.
     * @param command the command to get the property of
     * @param propertyName the name of the property
     * @return the boolean value of the command property or true when the property does not exist.
     */
    public static boolean getBooleanPropertyAssumeTrue(VcsCommand command, String propertyName) {
        Object value = command.getProperty(propertyName);
        if (value instanceof Boolean) {
            return ((Boolean) value).booleanValue();
        } else {
            return true;
        }
    }
    
    /**
     * Get the boolean value of the command property, or its default value when
     * the property is not defined.
     * @param command the command to get the property of
     * @param propertyName the name of the property
     * @return the boolean value of the command property or default value when the property
     * does not exist or false, when the default value is not defined for this property.
     */
    public static boolean getBooleanPropertyAssumeDefault(VcsCommand command, String propertyName) {
        Object value = command.getProperty(propertyName);
        if (value == null) value = getDefaultPropertyValue(propertyName);
        if (value instanceof Boolean) {
            return ((Boolean) value).booleanValue();
        } else {
            return false;
        }
    }
    
    /**
     * Get the int value of the command property.
     * @return the int value of the command property or 0 when the property does not exist.
     */
    public static int getIntegerPropertyAssumeZero(VcsCommand command, String propertyName) {
        Object value = command.getProperty(propertyName);
        if (value instanceof Integer) {
            return ((Integer) value).intValue();
        } else {
            return 0;
        }
    }
    
    /**
     * Get the int value of the command property.
     * @return the int value of the command property or -1 when the property does not exist.
     */
    public static int getIntegerPropertyAssumeNegative(VcsCommand command, String propertyName) {
        Object value = command.getProperty(propertyName);
        if (value instanceof Integer) {
            return ((Integer) value).intValue();
        } else {
            return -1;
        }
    }
    

}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.