
com.romanpierson.vertx.web.accesslogger.configuration.pattern.ExtractedPosition Maven / Gradle / Ivy
/*
* Copyright (c) 2016-2024 Roman Pierson
* ------------------------------------------------------
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Apache License v2.0
* which accompanies this distribution.
*
* The Apache License v2.0 is available at
* http://www.opensource.org/licenses/apache2.0.php
*
* You may elect to redistribute this code under either of these licenses.
*/
package com.romanpierson.vertx.web.accesslogger.configuration.pattern;
import java.util.function.Function;
import java.util.function.Supplier;
import com.romanpierson.vertx.web.accesslogger.configuration.element.AccessLogElement;
import io.vertx.core.json.JsonObject;
public class ExtractedPosition {
private final int start;
private final int offset;
private final Supplier elementSupplier;
private final Function elementFunction;
private final JsonObject config;
public static ExtractedPosition build(final int start, final int offset,
final Supplier elementSupplier)
{
return new ExtractedPosition(start, offset, elementSupplier, null, null);
}
public static ExtractedPosition build(final int start, final int offset,
final Function elementFunction, JsonObject config)
{
return new ExtractedPosition(start, offset, null, elementFunction, config);
}
private ExtractedPosition(final int start, final int offset,
final Supplier elementSupplier,
final Function elementFunction,
JsonObject config) {
super();
this.start = start;
this.offset = offset;
this.elementSupplier = elementSupplier;
this.elementFunction = elementFunction;
this.config = config;
}
public int getStart() {
return start;
}
public int getOffset() {
return offset;
}
public Supplier getElementSupplier() {
return elementSupplier;
}
public Function getElementFunction(){
return elementFunction;
}
public JsonObject getConfig() {
return config;
}
public boolean isCustom() {
if(elementSupplier != null) {
return !elementSupplier.get().getClass().getName().startsWith("com.romanpierson.vertx.web.accesslogger.configuration.element");
}else if(elementFunction != null && config != null) {
return !elementFunction.apply(config).getClass().getName().startsWith("com.romanpierson.vertx.web.accesslogger.configuration.element");
}else {
throw new IllegalStateException("Extracted Position must either have element supplier or function");
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy