com.gs.fw.common.mithra.util.WildcardParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of reladomo Show documentation
Show all versions of reladomo Show documentation
Reladomo is an object-relational mapping framework.
/*
Copyright 2016 Goldman Sachs.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
package com.gs.fw.common.mithra.util;
import java.io.Serializable;
import java.util.regex.Pattern;
public class WildcardParser implements Serializable
{
private static final long serialVersionUID = -2531503578551321454L;
private String wildcardPattern;
private String sqlExpression = null;
private transient volatile Pattern regexPattern = null;
public static final char SQL_ESCAPE = '=';
public static final char REGEX_ESCAPE = '\\';
private static final char WILDCARD_ESCAPE = '\'';
private static final char[] SQL_META_CHARS = {'=', '%', '_'};
private static final char WILDCARD_SUPPORTED_MULTIPLE_CHARS = '*';
private static final char WILDCARD_SUPPORTED_SINGLE_CHAR = '?';
private static final char SQL_SUPPORTED_EQUIVALENT_MULTIPLE_CHARS = '%';
private static final char SQL_SUPPORTED_EQUIVALENT_SINGLE_CHAR = '_';
private static final char[] REGEX_META_CHARS = {'\\', '.', '[', ']', '^', '$', '+',
'{', '}', '|'};
public WildcardParser(String wildcardPattern)
{
this.wildcardPattern = cleanPattern(wildcardPattern);
}
public static AnalyzedWildcardPattern getAnalyzedPattern(String pattern, AnalyzedWildcardPattern soFar)
{
if (soFar == null)
{
soFar = new AnalyzedWildcardPattern();
}
pattern = cleanPattern(pattern);
boolean lastCharWasQuote = false;
int wildCount = 0;
int firstStarPosition = -1;
int lastStarPosition = -1;
for(int i=0;i