Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.myfaces.trinidadinternal.agent.parse;
import java.util.ArrayList;
import java.util.Iterator;
import java.text.ParseException;
import org.apache.myfaces.trinidad.logging.TrinidadLogger;
/**
* An implementation that encapsulates "Name/Version Name/version ..." string and
* supports a match method for matching other names and versions
*
* Name String can contain .*'s wild char
* //TODO: Check if Name String *really* needs to support wild char
*
* Version string can contain +'s or *'s at the end
* "*" at the end of version implies an 5xx.xx.xx version
* "+" at the end implies greater than version 5
* E.g "ie/5* ie/5.5+"
*
*
* the name can have wild char charactes (at the end)
* the version string may contain wild char or "+" (at the end)
*
*/
class NameVersion
{
NameVersion(String value) throws ParseException
{
_entries = _parseEntries(value);
}
public double match(String name, VersionId version)
{
if (_entries == null)
return 0;
if (name == null)
return 0;
double score = 0;
for (int i = 0; i < _entries.length; i++)
{
Object[] entry = (Object[]) _entries[i];
if (entry[0] != null)
{
double score1 = _matchName((NameEntry) entry[0], name);
if (score1 > 0)
{
if ((entry[1] == null) & (score1 >= score))
{
score = score1;
}
else
{
double score2 = _matchVersion((VersionEntry) entry[1], version);
//a match only if the score is > 0
if ((score2 > 0) && (score1 + score2 >= score))
score = score1 + score2;
}
}
}
}
return score;
}
/**
* Parse the condtions into an an array of [name, version] pairs
* Right now the parse routine is very forgiving.
* It will parse strings like "name/version/something", "name///version"
*
* @param value
* @return
*/
private Object[] _parseEntries(String value)
throws ParseException
{
if (value == null)
return null;
int length = value.length();
char[] data = new char[length + 1];
value.getChars(0, length, data, 0);
data[length] = (char) 0x1000000; //untype-able ascii char;
boolean inQuote = false;
int start = 0;
int i = 0;
char ch = data[i];
ArrayList