use of nl.basjes.parse.useragent.calculate.FieldCalculator in project yauaa by nielsbasjes.
the class TestConcatenation method testFieldConcatenation.
@Test
void testFieldConcatenation() {
FieldCalculator fc;
MutableUserAgent userAgent = createUserAgent();
fc = new ConcatNONDuplicatedCalculator("Combined1", "One", "Two");
fc.calculate(userAgent);
assertEquals("One Two", userAgent.getValue("Combined1"));
fc = new ConcatNONDuplicatedCalculator("Combined2", "One", "One");
fc.calculate(userAgent);
assertEquals("One", userAgent.getValue("Combined2"));
fc = new ConcatNONDuplicatedCalculator("Combined3", "MinusOne", "One");
fc.calculate(userAgent);
assertEquals("MinusOne One", userAgent.getValue("Combined3"));
fc = new ConcatNONDuplicatedCalculator("Combined4", "One", "MinusOne");
fc.calculate(userAgent);
assertEquals("One MinusOne", userAgent.getValue("Combined4"));
}
use of nl.basjes.parse.useragent.calculate.FieldCalculator in project yauaa by nielsbasjes.
the class TestConcatenation method testFieldConcatenationNoConfidence.
@Test
void testFieldConcatenationNoConfidence() {
FieldCalculator fc;
MutableUserAgent userAgent = createUserAgent();
fc = new ConcatNONDuplicatedCalculator("Combined2", "One", "MinusOne");
fc.calculate(userAgent);
assertEquals("One MinusOne", userAgent.getValue("Combined2"));
fc = new ConcatNONDuplicatedCalculator("Combined3", "MinusOne", "Two");
fc.calculate(userAgent);
assertEquals("MinusOne Two", userAgent.getValue("Combined3"));
}
use of nl.basjes.parse.useragent.calculate.FieldCalculator in project yauaa by nielsbasjes.
the class TestConcatenation method testFieldConcatenationSamePrefix.
@Test
void testFieldConcatenationSamePrefix() {
FieldCalculator fc;
MutableUserAgent userAgent = createUserAgent();
fc = new ConcatNONDuplicatedCalculator("Combined1", "One", "Two");
fc.calculate(userAgent);
assertEquals("One Two", userAgent.getValue("Combined1"));
fc = new ConcatNONDuplicatedCalculator("Combined2", "One", "One");
fc.calculate(userAgent);
assertEquals("One", userAgent.getValue("Combined2"));
fc = new ConcatNONDuplicatedCalculator("Combined3", "One", "One Two");
fc.calculate(userAgent);
assertEquals("One Two", userAgent.getValue("Combined3"));
}
use of nl.basjes.parse.useragent.calculate.FieldCalculator in project yauaa by nielsbasjes.
the class TestConcatenation method testFieldConcatenationAllDefaults.
@Test
void testFieldConcatenationAllDefaults() {
FieldCalculator fc;
MutableUserAgent userAgent = new MutableUserAgent();
userAgent.set("FooBarName", "Dummy", 1);
userAgent.set("FooBarVersion", "Dummy", 1);
userAgent.reset();
fc = new ConcatNONDuplicatedCalculator("FooBarNameVersion", "FooBarName", "FooBarVersion");
fc.calculate(userAgent);
assertEquals("Unknown", userAgent.getValue("FooBarName"));
assertEquals("??", userAgent.getValue("FooBarVersion"));
assertEquals("Unknown ??", userAgent.getValue("FooBarNameVersion"));
assertTrue(userAgent.get("FooBarName").isDefaultValue());
assertTrue(userAgent.get("FooBarVersion").isDefaultValue());
assertTrue(userAgent.get("FooBarNameVersion").isDefaultValue());
}
use of nl.basjes.parse.useragent.calculate.FieldCalculator in project yauaa by nielsbasjes.
the class AbstractUserAgentAnalyzerDirect method getAllPossibleFieldNames.
public Set<String> getAllPossibleFieldNames() {
if (allPossibleFieldNamesCache == null) {
synchronized (this) {
if (allPossibleFieldNamesCache == null) {
Set<String> names = new TreeSet<>(CORE_SYSTEM_GENERATED_FIELDS);
if (wantedFieldNames == null) {
for (Matcher matcher : allMatchers) {
names.addAll(matcher.getAllPossibleFieldNames());
}
for (FieldCalculator calculator : fieldCalculators) {
names.add(calculator.getCalculatedFieldName());
}
} else {
for (Matcher matcher : allMatchers) {
// Not all wanted fields are possible !
for (String possibleFieldName : matcher.getAllPossibleFieldNames()) {
if (wantedFieldNames.contains(possibleFieldName)) {
names.add(possibleFieldName);
}
}
}
for (FieldCalculator calculator : fieldCalculators) {
String possibleFieldName = calculator.getCalculatedFieldName();
if (wantedFieldNames.contains(possibleFieldName)) {
names.add(possibleFieldName);
}
}
names.remove(SET_ALL_FIELDS);
}
allPossibleFieldNamesCache = names;
}
}
}
return allPossibleFieldNamesCache;
}
Aggregations