Changeset 1249

Show
Ignore:
Timestamp:
09/05/08 08:11:40 (4 months ago)
Author:
phoenix
Message:

Minor changes.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/dtool.descent.core/src-util/src-coreutil/melnorme/miscutil/Assert.java

    r1232 r1249  
    4343        } 
    4444 
    45         public AssertionFailedException(String detail) { 
    46             super(detail); 
     45        public AssertionFailedException(String message) { 
     46            super(message); 
     47        } 
     48         
     49        @Override 
     50        public String toString() { 
     51            String message = getLocalizedMessage(); 
     52            return "AssertionFailedException" + ((message != null) ? (": " + message) : ""); 
    4753        } 
    4854         
     
    5965        if (!expression) { 
    6066            expression = false;  // dummy statement to allow breakpoint placement 
    61             throw new AssertionFailedException("Assertion failed: " + message); //$NON-NLS-1$ 
     67            throw new AssertionFailedException(message); //$NON-NLS-1$ 
    6268        } 
    6369        return expression; 
     
    7884     */ 
    7985    public static boolean isTrue(boolean expression) { 
    80         return Assert.isTrue(expression, ""); //$NON-NLS-1$ 
     86        return Assert.isTrue(expression, null); //$NON-NLS-1$ 
    8187    } 
    8288    /** Like {@link #isTrue(boolean, String)} with empty message */ 
    8389    public static boolean assertTrue(boolean expression) { 
    84         return Assert.isTrue(expression, ""); //$NON-NLS-1$ 
     90        return Assert.isTrue(expression, null); //$NON-NLS-1$ 
    8591    } 
    8692     
     
    103109    /** Like {@link #isNotNull(Object, String)} with empty message.  */ 
    104110    public static void isNotNull(Object object) { 
    105         Assert.isTrue(!(object == null), ""); 
     111        Assert.isTrue(!(object == null), null); 
    106112    } 
    107113    /** Like {@link #isNotNull(Object, String)} with empty message.  */ 
    108114    public static void assertNotNull(Object object) { 
    109         Assert.isTrue(!(object == null), ""); 
     115        Assert.isTrue(!(object == null), null); 
    110116    } 
    111117     
     
    125131     */ 
    126132    public static AssertionFailedException fail(String msg) { 
    127         throw new AssertionFailedException("Assert fail: " + msg); 
     133        throw new AssertionFailedException(msg); 
    128134    } 
    129135    /** Causes an inconditional assertion failure, with message msg.  
     
    137143    /** Like {@link #fail(String)} with empty message. */ 
    138144    public static AssertionFailedException fail() { 
    139         throw new AssertionFailedException("Assert fail."); 
     145        throw new AssertionFailedException("fail."); 
    140146    } 
    141147    /** Like {@link #fail(String)} with empty message. */ 
  • trunk/dtool.descent.core/src-util/src-coreutil/melnorme/miscutil/MiscUtil.java

    • Property svn:mergeinfo set
    r646 r1249  
    11package melnorme.miscutil; 
    22 
    3 public class Misc { 
     3import java.io.File; 
     4import java.io.IOException; 
     5import java.io.InputStream; 
     6import java.util.ArrayList; 
     7import java.util.Arrays; 
     8 
     9public class MiscUtil { 
    410 
    511    /** Combines two hash codes to make a new one. */ 
     
    814    } 
    915 
     16    /** Runs a shell command as a Process and waits for it to terminate.  
     17     * Assumes the process does not read input.  
     18     * @return exit value of the process */ 
     19    public static int runShellCommand(String directory, String cmd, String... args) throws IOException { 
     20        ProcessBuilder procBuilder = new ProcessBuilder(); 
     21        ArrayList<String> cmdList = new ArrayList<String>(args.length+1); 
     22        cmdList.add(cmd); 
     23        cmdList.addAll(Arrays.asList(args)); 
     24        procBuilder.command(cmdList); 
     25        procBuilder.redirectErrorStream(true); 
     26        procBuilder.directory(new File(directory)); 
     27     
     28        Process process = procBuilder.start(); 
     29        InputStream inputStream = process.getInputStream(); 
     30        int ch; 
     31        while ((ch = inputStream.read()) != -1) { 
     32            //read proccess's stdout and stderr 
     33            if(false) 
     34                System.out.print((char)ch); 
     35        } 
     36         
     37        try { 
     38            return process.waitFor(); 
     39        } catch (InterruptedException e) { 
     40            throw melnorme.miscutil.ExceptionAdapter.unchecked(e); 
     41        } 
     42    } 
     43 
     44    /** 
     45     * Counts the active flags in the given bitfield 
     46     */ 
     47    public static int countActiveFlags(int bitfield, int[] flags) { 
     48        int count = 0; 
     49        for (int i = 0; i < flags.length; i++) { 
     50            if((bitfield & flags[i]) != 0) 
     51                count++; 
     52        } 
     53        return count; 
     54    } 
     55 
    1056} 
  • trunk/dtool.descent.core/src-util/src-coreutil/melnorme/miscutil/StringUtil.java

    r1232 r1249  
    108108    } 
    109109 
     110    /** Return "" if string is null, or the unmodified string otherwise. */ 
     111    public static String nullAsEmpty(String string) { 
     112        if(string == null) 
     113            return ""; 
     114        return string; 
     115    } 
     116 
    110117 
    111118}