net.sf.jabb.util.text
Class UrlStartWithMatcher

java.lang.Object
  extended by net.sf.jabb.util.text.StartWithMatcher
      extended by net.sf.jabb.util.text.UrlStartWithMatcher
All Implemented Interfaces:
Serializable

public class UrlStartWithMatcher
extends StartWithMatcher

Given a text string to be tested, and list of matching strings, find out which matching string the text string starts with.
给定一个待检查的URL字符串,以及一批开头匹配字符串,看看待检查的URL字符串以哪个匹配字符串开头。

The matching is case sensitive. If one matching string starts with another, and the text string starts with them, then the longer one will be considered to be matched.

匹配时对大小写敏感。如果匹配字符串之间互相饱含,则匹配其中最长的。

Author:
Zhengmao HU (James)
See Also:
Serialized Form

Field Summary
 
Fields inherited from class net.sf.jabb.util.text.StartWithMatcher
attachments, runAutomaton
 
Constructor Summary
UrlStartWithMatcher(Map<String,? extends Object> matchingDefinitions)
          Create a new instance according to matching strings and their corresponding attachment objects.
根据匹配字符串、匹配字符串所对应的附件对象,创建一个新的实例。
UrlStartWithMatcher(Map<String,? extends Object> matchingDefinitions, boolean moreSpaceForSpeed)
          Create a new instance according to matching strings and their corresponding attachment objects.
根据匹配字符串、匹配字符串所对应的附件对象,创建一个新的实例。
UrlStartWithMatcher(UrlStartWithMatcher toBeCopied)
          Create a copy, the copy will have exactly the same matching definitions as the original copy.
创建一个副本,这个副本与原先的对象具有完全相同匹配方式。
 
Method Summary
 Object match(String url)
          Find out which matching string matches the URL.
protected static List<MatchingDefinition> normalizeMatchingDefinitions(Map<String,? extends Object> matchingDefinitions, boolean moreSpaceForSpeed)
          Normalize matching definitions according to requirements of StartWithMatcher.
根据StartWithMatcher的需要来规范化匹配条件定义。
protected static String[] splitURL(String url)
          将URL拆成两块:反序后的斜线前面的主机、端口和帐号;斜线后面的路径和参数。 比如对于http://www.news.com/read/daily/headline.html,返回的是: moc.swen.www和read/daily/headline.html两项。
 
Methods inherited from class net.sf.jabb.util.text.StartWithMatcher
copyRunAutomaton, escapeForRegExp, getAllAcceptedStates, getLastAcceptedState, getLastAcceptedState, initialize, match, match, matchAll, matchAll, setAttachmentByExample
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UrlStartWithMatcher

public UrlStartWithMatcher(Map<String,? extends Object> matchingDefinitions)
Create a new instance according to matching strings and their corresponding attachment objects.
根据匹配字符串、匹配字符串所对应的附件对象,创建一个新的实例。

When initializing internal data structure, choose to consume more memory for better matching speed.

在创建内部数据结构的时候,选择占用更多内存,而换取速度上的提升。

Parameters:
matchingDefinitions - Key是匹配字符串,Value是附件对象。 当进行匹配检查的时候,返回附件对象来标识哪一个匹配字符串被匹配上了。

Key is the matching string, Value is its associated attachment object. When the heading string is matched, the attachment object will be returned as identifier.


UrlStartWithMatcher

public UrlStartWithMatcher(Map<String,? extends Object> matchingDefinitions,
                           boolean moreSpaceForSpeed)
Create a new instance according to matching strings and their corresponding attachment objects.
根据匹配字符串、匹配字符串所对应的附件对象,创建一个新的实例。

Parameters:
matchingDefinitions - Key是匹配字符串,Value是附件对象。 当进行匹配检查的时候,返回附件对象来标识哪一个匹配字符串被匹配上了。

Key is the matching string, Value is its associated attachment object. When the heading string is matched, the attachment object will be returned as identifier.

moreSpaceForSpeed - 是否占用更多内存,而换取速度上的提升。
Whether or not to consume more memory for better matching speed.

UrlStartWithMatcher

public UrlStartWithMatcher(UrlStartWithMatcher toBeCopied)
Create a copy, the copy will have exactly the same matching definitions as the original copy.
创建一个副本,这个副本与原先的对象具有完全相同匹配方式。

Parameters:
toBeCopied - 原本。
The original copy.
Method Detail

normalizeMatchingDefinitions

protected static List<MatchingDefinition> normalizeMatchingDefinitions(Map<String,? extends Object> matchingDefinitions,
                                                                       boolean moreSpaceForSpeed)
Normalize matching definitions according to requirements of StartWithMatcher.
根据StartWithMatcher的需要来规范化匹配条件定义。

Parameters:
matchingDefinitions - Key是匹配字符串,Value是附件对象。 当进行匹配检查的时候,返回附件对象来标识哪一个匹配字符串被匹配上了。

Key is the matching string, Value is its associated attachment object. When the matching string is matched, the attachment object will be returned as identifier.

moreSpaceForSpeed - 是否占用更多内存,而换取速度上的提升。
Whether or not to consume more memory for better matching speed.
Returns:
StartWithMatcher所需的匹配条件定义。
Matching definitions for usage of StartWithMatcher.

match

public Object match(String url)
Find out which matching string matches the URL. URL can start with protocol (such as "http://"), or not.
进行匹配判断,URL可以包含协议头,也可以不包含,匹配时对大小写不敏感。

Matching is case insensitive.

Parameters:
url - 需要进行匹配判断的URL
The URL need to be tested.
Returns:
匹配到的字符串所对应的附件,如果找不到任何匹配,则返回null
The corresponding attachment object of the matching string that matches the URL. Return null if no matching found.

splitURL

protected static String[] splitURL(String url)
将URL拆成两块:反序后的斜线前面的主机、端口和帐号;斜线后面的路径和参数。 比如对于http://www.news.com/read/daily/headline.html,返回的是: moc.swen.www和read/daily/headline.html两项。

Parameters:
url - URL,可以带http://,也可不带
Returns:
第一项是反序后的斜线前面的,第二项是斜线后面的。而且已经被转为小写。


Copyright © 2012. All Rights Reserved.