打開后發(fā)現(xiàn)這個(gè)申請過程有點(diǎn)意思,要先寫一段java代碼完成題目。
這個(gè)題目的大概意思是:一個(gè)String類型數(shù)組,填充的內(nèi)容是一組映射關(guān)系,一個(gè)String作為校驗(yàn)String數(shù)組的依據(jù)(英文太爛不知道對不對)。
它給了一個(gè)例子
Example input:
String[] config: { "/", "MainServlet", "/nav", "NavigationServlet" }
String requestUri: "/nav/test"
Correct result: "NavigationServlet"
In this example, the configuration contains a mapping of "/" to "MainServlet" and "/nav" to "NavigationServlet". In the case of an incoming URI "/nav/test.nav", "NavigationServlet" is the correct choice because its pattern is longer than that of "MainServlet".
這段話的意思是"/", "MainServlet"是映射關(guān)系,"/nav", "NavigationServlet"同上,那么requestUri: "/nav/test",則是對"/", "/nav"的評判。當(dāng)滿足條件后選擇較長的字符串作為結(jié)果返回。
咋一看這題目意思挺明確的,不就是輸出長的字符串嗎?Coding

















結(jié)果一貼上就提示error,問題出在了哪里?原來是沒有看完題目。
As the principal engineer of an HTTP web server, you are responsible for implementing the request processing subsystem of the server.
An incoming request for a specific resource, identified by an URI, must be dispatched to the appropriate handler according to the server configuration which maps URIs to request handlers. 'HandlerFactory.getHandler' must be implemented:
public class HandlerFactory
{
public String getHandler(String[] config, String requestUri)
{
}
}
The string array 'config' contains URI patterns and handler names. Two consecutive values form a key-value pair comprised of URI pattern and handler. 'requestUri' represents an incoming request, the URI to match against the configured handlers. 'getHandler' must return the correct handler for a given URI as a string value.
An URI pattern never contains wildcards and represents the start of an URI string, a prefix. Matching must be implemented accordingly. The handler with the longest matching URI pattern wins if more than one pattern matches. If no handler can be found, "UlFuW0" must be returned.
關(guān)鍵是這一段交代了這個(gè)方法的意圖,條件是這樣的一個(gè)順序,String數(shù)組中充當(dāng)key值與requestUri的關(guān)系是,key作為前綴給requestUri校驗(yàn)的。只有當(dāng)校驗(yàn)通過時(shí),value才能作為結(jié)果返回,當(dāng)多個(gè)key值通過校驗(yàn)后,返回length最大的value。
于是加了個(gè)條件。Line:9

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

當(dāng)然這個(gè)是最初級的代碼,如果考慮的更加細(xì)致一點(diǎn)。代碼可以更加完善。