src/share/classes/sun/tools/jstat/Arguments.java

Print this page


   1 /*
   2  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 124         try {
 125             int value = Integer.parseInt(valueString);
 126 
 127             if (unitString == null || unitString.compareTo("ms") == 0) {
 128                 return value;
 129             } else if (unitString.compareTo("s") == 0) {
 130                 return value * 1000;
 131             } else {
 132                 throw new IllegalArgumentException(
 133                         "Unknow time unit: " + unitString);
 134             }
 135         } catch (NumberFormatException e) {
 136             throw new IllegalArgumentException(
 137                     "Could not convert interval: " + s);
 138         }
 139     }
 140 
 141     public Arguments(String[] args) throws IllegalArgumentException {
 142         int argc = 0;
 143 
 144         if (args.length < 1) {
 145             throw new IllegalArgumentException("invalid argument count");

 146         }
 147 
 148         if ((args[0].compareTo("-?") == 0)
 149                 || (args[0].compareTo("-help") == 0)) {
 150             help = true;
 151             return;
 152         } else if (args[0].compareTo("-options") == 0) {
 153             options = true;
 154             return;
 155         } else if (args[0].compareTo("-list") == 0) {
 156             list = true;
 157             if (args.length > 2) {
 158               throw new IllegalArgumentException("invalid argument count");
 159             }
 160             // list can take one arg - a vmid - fall through for arg processing
 161             argc++;
 162         }
 163 
 164         for ( ; (argc < args.length) && (args[argc].startsWith("-")); argc++) {
 165             String arg = args[argc];


   1 /*
   2  * Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 124         try {
 125             int value = Integer.parseInt(valueString);
 126 
 127             if (unitString == null || unitString.compareTo("ms") == 0) {
 128                 return value;
 129             } else if (unitString.compareTo("s") == 0) {
 130                 return value * 1000;
 131             } else {
 132                 throw new IllegalArgumentException(
 133                         "Unknow time unit: " + unitString);
 134             }
 135         } catch (NumberFormatException e) {
 136             throw new IllegalArgumentException(
 137                     "Could not convert interval: " + s);
 138         }
 139     }
 140 
 141     public Arguments(String[] args) throws IllegalArgumentException {
 142         int argc = 0;
 143 
 144         if (args.length == 0) {
 145             help = true;
 146             return;
 147         }
 148 
 149         if ((args[0].compareTo("-?") == 0)
 150                 || (args[0].compareTo("-help") == 0)) {
 151             help = true;
 152             return;
 153         } else if (args[0].compareTo("-options") == 0) {
 154             options = true;
 155             return;
 156         } else if (args[0].compareTo("-list") == 0) {
 157             list = true;
 158             if (args.length > 2) {
 159               throw new IllegalArgumentException("invalid argument count");
 160             }
 161             // list can take one arg - a vmid - fall through for arg processing
 162             argc++;
 163         }
 164 
 165         for ( ; (argc < args.length) && (args[argc].startsWith("-")); argc++) {
 166             String arg = args[argc];