Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**
     * Check the format of the firmware file name: 00-00-00
     *
     * @param fileVerName is the firmware version formed into file name.
     * @return true, if the firmware name conforms to the rules.
     */
    public static boolean checkFileName(String fileVerName) {
        String[] nameElementArr = fileVerName.split("\\-");
        int versionSize = 8;
        int verInfoElementCnt = 3;
        int verInfoElementSize = 2;
        int maxVerNum = 99;

        if ((fileVerName.length() == versionSize) && (nameElementArr.length == verInfoElementCnt)) {
            for (int i = 0; i < verInfoElementCnt; i++) {
                for (int j = 0; j <= maxVerNum; j++) {
                    String number = Integer.toString(j);

                    if ((j < 10) && (nameElementArr[i].equals("0" + number)) && (i == verInfoElementSize)) {
                        return true;
                    } else if (nameElementArr[i].equals(number) && (i == verInfoElementSize)) {
                        return true;
                    }
                }
            }
        }
        return false;
    }
}