當前位置: 首頁>>代碼示例>>Java>>正文


Java Integer.parseInt方法代碼示例

本文整理匯總了Java中java.lang.Integer.parseInt方法的典型用法代碼示例。如果您正苦於以下問題:Java Integer.parseInt方法的具體用法?Java Integer.parseInt怎麽用?Java Integer.parseInt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.lang.Integer的用法示例。


在下文中一共展示了Integer.parseInt方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: parseIPv6

import java.lang.Integer; //導入方法依賴的package包/類
private void parseIPv6(String name) throws IOException {

        int slashNdx = name.indexOf('/');
        if (slashNdx == -1) {
            address = InetAddress.getByName(name).getAddress();
        } else {
            address = new byte[32];
            byte[] base = InetAddress.getByName
                (name.substring(0, slashNdx)).getAddress();
            System.arraycopy(base, 0, address, 0, 16);

            // append a mask corresponding to the num of prefix bits specified
            int prefixLen = Integer.parseInt(name.substring(slashNdx+1));
            if (prefixLen > 128)
                throw new IOException("IPv6Address prefix is longer than 128");

            // create new bit array initialized to zeros
            BitArray bitArray = new BitArray(MASKSIZE * 8);

            // set all most significant bits up to prefix length
            for (int i = 0; i < prefixLen; i++)
                bitArray.set(i, true);
            byte[] maskArray = bitArray.toByteArray();

            // copy mask bytes into mask portion of address
            for (int i = 0; i < MASKSIZE; i++)
                address[MASKSIZE+i] = maskArray[i];
        }
    }
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:30,代碼來源:IPAddressName.java

示例2: readBoard

import java.lang.Integer; //導入方法依賴的package包/類
public void readBoard(String in,boolean update){   
    moveSequence = "";
    redTurn = true;
    blueTurn = false;
    try{
        String[] parts;
        boolean newMode = false;
        char[] id = in.toCharArray();
        if(id[0]=='B'){
            int indexOfFirstComma = in.indexOf(",");
            int indexOfFirstSlash = in.indexOf("/");
            birth.clear();
            survive.clear();
            for(int i=1;i<indexOfFirstSlash;i++){
                birth.add(Character.getNumericValue(id[i]));
            }
            for(int i=indexOfFirstSlash+2;i<indexOfFirstComma;i++){
                survive.add(Character.getNumericValue(id[i]));
            }
            parts = in.substring(indexOfFirstComma+1).split(",");
        }else{
            parts = in.split(",");
        }
        if (parts.length < 5) {
            throw new IOException();
        }
 
        WIDTH = HEIGHT = Math.min(Math.max(Integer.parseInt(parts[0]),3),20);
        timeLimit[0]=0;
        timeLimit[1] = Integer.parseInt(parts[1]);
        timeLimit[2]=0;
        timeLimit[3]=0;
        timeBonus = Integer.parseInt(parts[2]);
        int humanNum = Integer.parseInt(parts[3]);
        stringToBoard(parts[4],update);
        /*redDepth = (int)(((humanNum/4)-1)*2);
        blueDepth = (((humanNum%4)-1)*2);
        if(redDepth<0){
            redBot = false;
        }else{
            redBot = true;
        }
        if(blueDepth<0){
            blueBot = false;
        }else{
            redBot = true;
        }*/
        int noSwapsUntil = -1;
        String[] moves = new String[parts.length-5];
        for(int i = 0; i<moves.length; i++){
            moves[i]=parts[i+5];
        } 
        int moveLimit = Integer.MAX_VALUE;
        if(screen==4){
            moveArray = moves;        
            totalMoves = moveArray.length;
            moveNumber = 0;
            saveTiles();
        }else{
            saveTiles();
            for (int t = 0; t < moves.length; t++) { // Go through all the moves.
                makeMove(moves[t]);
            } 
        }
        updateNumbers();
        updateLists();            
        boardStart = getBoard();
    }catch (Exception e) {
        JFrame frame = new JFrame("Error");
        JOptionPane.showMessageDialog(frame, "Illegal game string", "Error", 0);
    }       
}
 
開發者ID:hanss314,項目名稱:GOLAD,代碼行數:73,代碼來源:MyWorld.java

示例3: parseIPv6

import java.lang.Integer; //導入方法依賴的package包/類
private void parseIPv6(String name) throws IOException {

        int slashNdx = name.indexOf('/');
        if (slashNdx == -1) {
            address = InetAddress.getByName(name).getAddress();
        } else {
            address = new byte[32];
            byte[] base = InetAddress.getByName
                (name.substring(0, slashNdx)).getAddress();
            System.arraycopy(base, 0, address, 0, 16);

            // append a mask corresponding to the num of prefix bits specified
            int prefixLen = Integer.parseInt(name.substring(slashNdx+1));
            if (prefixLen < 0 || prefixLen > 128) {
                throw new IOException("IPv6Address prefix length (" +
                        prefixLen + ") in out of valid range [0,128]");
            }

            // create new bit array initialized to zeros
            BitArray bitArray = new BitArray(MASKSIZE * 8);

            // set all most significant bits up to prefix length
            for (int i = 0; i < prefixLen; i++)
                bitArray.set(i, true);
            byte[] maskArray = bitArray.toByteArray();

            // copy mask bytes into mask portion of address
            for (int i = 0; i < MASKSIZE; i++)
                address[MASKSIZE+i] = maskArray[i];
        }
    }
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:32,代碼來源:IPAddressName.java

示例4: unbundle

import java.lang.Integer; //導入方法依賴的package包/類
public static TestClassBundledGCM unbundle(Bundle bundle, Gson gson) {
    return new AutoValue_TestClassBundledGCM(
            bundle,
            Byte.parseByte(bundle.getString("some_byte")),
            Boolean.parseBoolean(bundle.getString("some_boolean")),
            Short.parseShort(bundle.getString("some_short")),
            Integer.parseInt(bundle.getString("some_int")),
            Long.parseLong(bundle.getString("some_long")),
            bundle.getString("some_char").charAt(0),
            Float.parseFloat(bundle.getString("some_float")),
            Double.parseDouble(bundle.getString("some_double")),
            bundle.getString("some_string"),
            bundle.getString("some_char_sequence"),
            gson.fromJson(bundle.getString("some_parcelable"), Parcelable.class),
            gson.fromJson(bundle.getString("some_parcelable_array_list"), new com.google.common.reflect.TypeToken<java.util.ArrayList<Parcelable>>(){}.getType()),
            gson.fromJson(bundle.getString("some_parcelable_sparse_array"), new com.google.common.reflect.TypeToken<android.util.SparseArray<Parcelable>>(){}.getType()),
            gson.fromJson(bundle.getString("some_serializable"), Serializable.class),
            gson.fromJson(bundle.getString("some_integer_array_list"), new com.google.common.reflect.TypeToken<java.util.ArrayList<Integer>>(){}.getType()),
            gson.fromJson(bundle.getString("some_string_array_list"), new com.google.common.reflect.TypeToken<java.util.ArrayList<String>>(){}.getType()),
            gson.fromJson(bundle.getString("some_char_sequence_array_list"), new com.google.common.reflect.TypeToken<java.util.ArrayList<CharSequence>>(){}.getType()),
            toPrimitive(gson.fromJson(bundle.getString("some_byte_array"), Byte[].class)),
            toPrimitive(gson.fromJson(bundle.getString("some_short_array"), Short[].class)),
            toPrimitive(gson.fromJson(bundle.getString("some_char_array"), Character[].class)),
            toPrimitive(gson.fromJson(bundle.getString("some_float_array"), Float[].class)),
            gson.fromJson(bundle.getString("some_unknown_object"), new com.google.common.reflect.TypeToken<UnknownObject>(){}.getType()),
            gson.fromJson(bundle.getString("some_unknown_object_list"), new com.google.common.reflect.TypeToken<ArrayList<UnknownObject>>(){}.getType()),
            gson.fromJson(bundle.getString("test_enum"), new com.google.common.reflect.TypeToken<TestEnum>(){}.getType()));
}
 
開發者ID:uber,項目名稱:auto-value-bundle,代碼行數:29,代碼來源:AutoValue_TestClassBundledGCM.java

示例5: main

import java.lang.Integer; //導入方法依賴的package包/類
public static void main( String [] args ) {

		//msgfParameters = args[0]

		File paramsFile = new File(args[0]);
		readFile(paramsFile);

		String [] parameters = MSGFBatFile.toString().replaceAll("\"", "").split(" \r\n");

   
		//outputDir = parameters[0]
		//fastaFile = parameters[1]
		//ppm = parameters[2]
		//enzyme = parameters[3]
		//modsFileLocation = parameters[4]
		//MsgfplusJarDir = parameters[5]
		//threadsToUse = parameters[6]
		//ntt = parameters[7]
		//ti = parameters[8]
	
		File outputDir = new File(parameters[0]);
		File[] files = outputDir.listFiles();
		int threadsToUse = Integer.parseInt(parameters[6]);
		String msgfplusJarDir = parameters[5];

		MSGFBatFile.delete(0, MSGFBatFile.length());
		
		for( File file : files ) {

			if( !file.isDirectory() && ( file.getAbsolutePath().endsWith("Q1.mzXML") || file.getAbsolutePath().endsWith("Q2.mzXML") || file.getAbsolutePath().endsWith("Q3.mzXML") ) ) {
				//tandemBatFile.append( "java -d64 -Xmx10000M -jar C:\\MSGFplus.20140716\\msgfplus.jar" );
				MSGFBatFile.append( "java -d64 -Xmx60000M -jar " );
				MSGFBatFile.append(msgfplusJarDir);
				MSGFBatFile.append( " -s " + file.getAbsolutePath() );
				MSGFBatFile.append( " -d " + parameters[1] );
				MSGFBatFile.append( " -o " + parameters[0] + "\\" + file.getName().replace(".mzXML", "_MSGF.mzid") );
				MSGFBatFile.append( " -thread " + 1 );
				MSGFBatFile.append( " -t " + parameters[2] );
				MSGFBatFile.append( " -tda 1 -ti "+ parameters[8]+ " -inst 2 -m 3");
				MSGFBatFile.append( " -e " + parameters[3] );
				MSGFBatFile.append( " -ntt " + parameters[7] );
				MSGFBatFile.append( " -mod " + parameters[4] );		
				MSGFBatFile.append( "\r\n" );
			}			
		}
		
		writeToFile(outputDir);

	}
 
開發者ID:jgmeyerucsd,項目名稱:PIQEDia,代碼行數:50,代碼來源:CreateMsgfBat.java

示例6: setPropertiesFromAttributes

import java.lang.Integer; //導入方法依賴的package包/類
/**
 * Update any cached values that come from attributes.
 */
protected void setPropertiesFromAttributes() {
    StyleSheet sheet = ((HTMLDocument)getDocument()).getStyleSheet();
    AttributeSet eAttr = getElement().getAttributes();
    attr = sheet.getViewAttributes(this);

    alignment = StyleConstants.ALIGN_CENTER;
    size = 0;
    noshade = null;
    widthValue = null;

    if (attr != null) {
        // getAlignment() returns ALIGN_LEFT by default, and HR should
        // use ALIGN_CENTER by default, so we check if the alignment
        // attribute is actually defined
        if (attr.getAttribute(StyleConstants.Alignment) != null) {
            alignment = StyleConstants.getAlignment(attr);
        }

        noshade = (String)eAttr.getAttribute(HTML.Attribute.NOSHADE);
        Object value = eAttr.getAttribute(HTML.Attribute.SIZE);
        if (value != null && (value instanceof String)) {
            try {
                size = Integer.parseInt((String)value);
            } catch (NumberFormatException e) {
                size = 1;
            }
        }
        value = attr.getAttribute(CSS.Attribute.WIDTH);
        if (value != null && (value instanceof CSS.LengthValue)) {
            widthValue = (CSS.LengthValue)value;
        }
        topMargin = getLength(CSS.Attribute.MARGIN_TOP, attr);
        bottomMargin = getLength(CSS.Attribute.MARGIN_BOTTOM, attr);
        leftMargin = getLength(CSS.Attribute.MARGIN_LEFT, attr);
        rightMargin = getLength(CSS.Attribute.MARGIN_RIGHT, attr);
    }
    else {
        topMargin = bottomMargin = leftMargin = rightMargin = 0;
    }
    size = Math.max(2, size);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:45,代碼來源:HRuleView.java

示例7: getInt

import java.lang.Integer; //導入方法依賴的package包/類
/**
 * Implements the <tt>getInt</tt> method as per the specification in
 * {@link Preferences#getInt(String,int)}.
 *
 * <p>This implementation invokes {@link #get(String,String) <tt>get(key,
 * null)</tt>}.  If the return value is non-null, the implementation
 * attempts to translate it to an <tt>int</tt> with
 * {@link Integer#parseInt(String)}.  If the attempt succeeds, the return
 * value is returned by this method.  Otherwise, <tt>def</tt> is returned.
 *
 * @param key key whose associated value is to be returned as an int.
 * @param def the value to be returned in the event that this
 *        preference node has no value associated with <tt>key</tt>
 *        or the associated value cannot be interpreted as an int.
 * @return the int value represented by the string associated with
 *         <tt>key</tt> in this preference node, or <tt>def</tt> if the
 *         associated value does not exist or cannot be interpreted as
 *         an int.
 * @throws IllegalStateException if this node (or an ancestor) has been
 *         removed with the {@link #removeNode()} method.
 * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>.
 */
public int getInt(String key, int def) {
    int result = def;
    try {
        String value = get(key, null);
        if (value != null)
            result = Integer.parseInt(value);
    } catch (NumberFormatException e) {
        // Ignoring exception causes specified default to be returned
    }

    return result;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:35,代碼來源:AbstractPreferences.java

示例8: getInt

import java.lang.Integer; //導入方法依賴的package包/類
/**
 * Implements the {@code getInt} method as per the specification in
 * {@link Preferences#getInt(String,int)}.
 *
 * <p>This implementation invokes {@link #get(String,String) get(key,
 * null)}.  If the return value is non-null, the implementation
 * attempts to translate it to an {@code int} with
 * {@link Integer#parseInt(String)}.  If the attempt succeeds, the return
 * value is returned by this method.  Otherwise, {@code def} is returned.
 *
 * @param key key whose associated value is to be returned as an int.
 * @param def the value to be returned in the event that this
 *        preference node has no value associated with {@code key}
 *        or the associated value cannot be interpreted as an int.
 * @return the int value represented by the string associated with
 *         {@code key} in this preference node, or {@code def} if the
 *         associated value does not exist or cannot be interpreted as
 *         an int.
 * @throws IllegalStateException if this node (or an ancestor) has been
 *         removed with the {@link #removeNode()} method.
 * @throws NullPointerException if {@code key} is {@code null}.
 * @throws IllegalArgumentException if key contains the null control
 *         character, code point U+0000.
 */
public int getInt(String key, int def) {
    int result = def;
    try {
        String value = get(key, null);
        if (value != null)
            result = Integer.parseInt(value);
    } catch (NumberFormatException e) {
        // Ignoring exception causes specified default to be returned
    }

    return result;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:37,代碼來源:AbstractPreferences.java


注:本文中的java.lang.Integer.parseInt方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。