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


Java Scanner.match方法代碼示例

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


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

示例1: parseYear

import java.util.Scanner; //導入方法依賴的package包/類
private int parseYear(Scanner s, int defaultYear) {
    if (s.hasNext(YEAR)) {
        s.next(YEAR);
        MatchResult mr = s.match();
        if (mr.group(1) != null) {
            return 1900;  // systemv has min
        } else if (mr.group(2) != null) {
            return YEAR_MAX_VALUE;
        } else if (mr.group(3) != null) {
            return defaultYear;
        }
        return Integer.parseInt(mr.group(4));
        /*
        if (mr.group("min") != null) {
            //return YEAR_MIN_VALUE;
            return 1900;  // systemv has min
        } else if (mr.group("max") != null) {
            return YEAR_MAX_VALUE;
        } else if (mr.group("only") != null) {
            return defaultYear;
        }
        return Integer.parseInt(mr.group("year"));
        */
    }
    throw new IllegalArgumentException("Unknown year: " + s.next());
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:27,代碼來源:TzdbZoneRulesCompiler.java

示例2: parseThreadInfo

import java.util.Scanner; //導入方法依賴的package包/類
protected ThreadStack parseThreadInfo(String threadInfo) {
    Scanner s = new Scanner(threadInfo);
    ThreadStack result = new ThreadStack();

    // parsing thread info
    s.findInLine(threadInfoPattern());
    MatchResult res = s.match();

    result.setThreadName(res.group(1));

    result.setType(res.group(3));

    result.setPriority(res.group(4));
    result.setTid(res.group(7));
    result.setNid(res.group(8));
    result.setStatus(res.group(9));

    s.close();
    return result;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:DefaultFormat.java

示例3: parseMethodInfo

import java.util.Scanner; //導入方法依賴的package包/類
protected MethodInfo parseMethodInfo(String line) {

        MethodInfo result = new MethodInfo();
        Scanner s = new Scanner(line);

        s.findInLine(methodInfoPattern());
        MatchResult rexp = s.match();
        if (rexp.group(4) != null && rexp.group(4).length() > 0) {
            // line "  at tmtools.jstack.share.utils.Utils.sleep(Utils.java:29)"
            result.setName(rexp.group(1));
            result.setCompilationUnit(rexp.group(2));
            result.setLine(rexp.group(4));

        } else {
            // line "  at java.lang.Thread.sleep(Native Method)"
            result.setName(rexp.group(1));
        }

        s.close();
        return result;
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:DefaultFormat.java

示例4: setWinCeVersion

import java.util.Scanner; //導入方法依賴的package包/類
private void setWinCeVersion(OperatingSystem model) {
    //TODO: to be refined
    String osV = model.getVersion();
    if (osV == null) {
        return;

    } else if (!model.getMajorRevision().equals("1")) {
        return;
    }

    if (osV.matches(".*(\\d+).(\\d+).(\\d+).(\\d+).*")) {
        Scanner s = new Scanner(osV);
        s.findInLine(".*(\\d+).(\\d+).(\\d+).(\\d+).*");
        MatchResult result = s.match();
        if (result.group(1).equals("4")) {
            model.setMajorRevision("5");

        } else if (result.group(1).equals("6")) {
            model.setMajorRevision("6");

            if (result.group(3).equals("7")) {
                model.setMinorRevision("1");
            }
        }
    }
}
 
開發者ID:OpenDDRmobi,項目名稱:openddr-java,代碼行數:27,代碼來源:WinCEMozillaSubBuilder.java

示例5: setProxy

import java.util.Scanner; //導入方法依賴的package包/類
/**
 * Define the proxy to use for all GA tracking requests.
 * <p>
 * Call this static method early (before creating any tracking requests).
 *
 * @param proxyAddr
 *            "addr:port" of the proxy to use; may also be given as URL
 *            ("http://addr:port/").
 */
public static void setProxy(String proxyAddr)
{
	if(proxyAddr != null)
	{
		Scanner s = new Scanner(proxyAddr);
		
		// Split into "proxyAddr:proxyPort".
		proxyAddr = null;
		int proxyPort = 8080;
		try
		{
			s.findInLine("(http://|)([^:/]+)(:|)([0-9]*)(/|)");
			MatchResult m = s.match();
			
			if(m.groupCount() >= 2)
				proxyAddr = m.group(2);
			
			if(m.groupCount() >= 4 && !(m.group(4).length() == 0))
				proxyPort = Integer.parseInt(m.group(4));
		}finally
		{
			s.close();
		}
		
		if(proxyAddr != null)
		{
			SocketAddress sa = new InetSocketAddress(proxyAddr, proxyPort);
			setProxy(new Proxy(Type.HTTP, sa));
		}
	}
}
 
開發者ID:Wurst-Imperium,項目名稱:Wurst-MC-1.12,代碼行數:41,代碼來源:JGoogleAnalyticsTracker.java

示例6: parseMonitorInfo

import java.util.Scanner; //導入方法依賴的package包/類
private MonitorInfo parseMonitorInfo(String line, String pattern) {
    Scanner s = new Scanner(line);
    s.findInLine(pattern);
    MonitorInfo mi = new MonitorInfo();
    MatchResult res = s.match();

    mi.setType(res.group(1));
    mi.setMonitorAddress(res.group(2));
    if (res.groupCount() > 2) {
        mi.setMonitorClass(res.group(3));
    }
    return mi;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:DefaultFormat.java

示例7: parseLockInfo

import java.util.Scanner; //導入方法依賴的package包/類
protected LockInfo parseLockInfo(String line) {
    LockInfo res = new LockInfo();

    Scanner s = new Scanner(line);
    s.findInLine(ownableSynchronizersPattern());

    MatchResult matchRes = s.match();
    String lock = matchRes.group(1).equals("None") ? matchRes.group(1) : matchRes.group(2);
    res.setLock(lock);

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

示例8: extractJsEmbeddings

import java.util.Scanner; //導入方法依賴的package包/類
private List<EmbeddingPosition> extractJsEmbeddings(String text, int sourceStart) {
    List<EmbeddingPosition> embeddings = new LinkedList<>();
    // beginning comment around the script
    int start = 0;
    for (; start < text.length(); start++) {
        char c = text.charAt(start);
        if (!Character.isWhitespace(c)) {
            break;
        }
    }
    if (start < text.length() && text.startsWith("<!--", start)) { //NOI18N
        int lineEnd = text.indexOf('\n', start); //NOI18N
        if (isHtmlCommentStartToSkip(text, start, lineEnd)) {
            if (start > 0) {
                embeddings.add(new EmbeddingPosition(sourceStart, start));
            }
            lineEnd++; //skip the \n
            sourceStart += lineEnd;
            text = text.substring(lineEnd);
            // need to look at the end of the text, whether there is no -->
            int end = text.length() - 1;
            while(end > -1 && Character.isWhitespace(text.charAt(end))) {
                end--;
            }
            if (end > 4) {
                int index = text.indexOf("-->", end - 4);
                if (index != -1) { //NOI18N
                    String helpText = text.substring(0, index);
                    if (helpText.lastIndexOf("<!--") <= helpText.lastIndexOf("-->")) { //NOI18N
                        text = helpText;
                    }
                }
            }
        }
    }
    // inline comments inside script
    Scanner scanner = new Scanner(text).useDelimiter("(<!--).*(-->)"); //NOI18N
    while (scanner.hasNext()) {
        scanner.next();
        MatchResult match = scanner.match();
        embeddings.add(new EmbeddingPosition(sourceStart + match.start(), match.group().length()));
    }
    return embeddings;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:45,代碼來源:JsEmbeddingProvider.java


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