Search in sources :

Example 16 with Arrays

use of java.util.Arrays in project AuthMeReloaded by AuthMe.

the class SettingsClassConsistencyTest method shouldHaveAllClassesInConfigurationData.

/**
 * Checks that {@link AuthMeSettingsRetriever} returns a ConfigurationData with all
 * available SettingsHolder classes.
 */
@Test
public void shouldHaveAllClassesInConfigurationData() {
    // given
    long totalProperties = classes.stream().map(Class::getDeclaredFields).flatMap(Arrays::stream).filter(field -> Property.class.isAssignableFrom(field.getType())).count();
    // when
    ConfigurationData configData = AuthMeSettingsRetriever.buildConfigurationData();
    // then
    assertThat("ConfigurationData should have " + totalProperties + " properties (as found manually)", configData.getProperties(), hasSize((int) totalProperties));
}
Also used : Arrays(java.util.Arrays) ClassCollector(fr.xephi.authme.ClassCollector) BeforeClass(org.junit.BeforeClass) Set(java.util.Set) Test(org.junit.Test) Field(java.lang.reflect.Field) ReflectionTestUtils(fr.xephi.authme.ReflectionTestUtils) HashSet(java.util.HashSet) Assert.assertThat(org.junit.Assert.assertThat) List(java.util.List) Property(ch.jalu.configme.properties.Property) Modifier(java.lang.reflect.Modifier) Matchers.equalTo(org.hamcrest.Matchers.equalTo) SettingsHolder(ch.jalu.configme.SettingsHolder) ConfigurationData(ch.jalu.configme.configurationdata.ConfigurationData) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Assert.fail(org.junit.Assert.fail) TestHelper(fr.xephi.authme.TestHelper) ConfigurationData(ch.jalu.configme.configurationdata.ConfigurationData) Arrays(java.util.Arrays) Test(org.junit.Test)

Example 17 with Arrays

use of java.util.Arrays in project pinpoint by naver.

the class ExperimentalConfig method readExperimentalProperties.

private Map<String, Object> readExperimentalProperties(Environment environment) {
    MutablePropertySources propertySources = ((AbstractEnvironment) environment).getPropertySources();
    Map<String, Object> collect = propertySources.stream().filter(ps -> ps instanceof EnumerablePropertySource).map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).filter(propName -> propName.startsWith(PREFIX)).collect(Collectors.toMap(Function.identity(), toValue(environment)));
    return collect;
}
Also used : Objects(java.util.Objects) Component(org.springframework.stereotype.Component) Arrays(java.util.Arrays) Environment(org.springframework.core.env.Environment) Map(java.util.Map) EnumerablePropertySource(org.springframework.core.env.EnumerablePropertySource) MutablePropertySources(org.springframework.core.env.MutablePropertySources) AbstractEnvironment(org.springframework.core.env.AbstractEnvironment) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) EnumerablePropertySource(org.springframework.core.env.EnumerablePropertySource) AbstractEnvironment(org.springframework.core.env.AbstractEnvironment) MutablePropertySources(org.springframework.core.env.MutablePropertySources) Arrays(java.util.Arrays)

Example 18 with Arrays

use of java.util.Arrays in project druid by druid-io.

the class TopNQueryRunnerTest method testTopNBySegment.

@Test
public void testTopNBySegment() {
    final HashMap<String, Object> specialContext = new HashMap<String, Object>();
    specialContext.put(QueryContexts.BY_SEGMENT_KEY, "true");
    TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.DATA_SOURCE).granularity(QueryRunnerTestHelper.ALL_GRAN).dimension(QueryRunnerTestHelper.MARKET_DIMENSION).metric(QueryRunnerTestHelper.INDEX_METRIC).threshold(4).intervals(QueryRunnerTestHelper.FIRST_TO_THIRD).aggregators(commonAggregators).postAggregators(QueryRunnerTestHelper.ADD_ROWS_INDEX_CONSTANT).context(specialContext).build();
    List<Result<TopNResultValue>> expectedResults = Collections.singletonList(new Result<>(DateTimes.of("2011-04-01T00:00:00.000Z"), new TopNResultValue(Arrays.<Map<String, Object>>asList(ImmutableMap.of("addRowsIndexConstant", 5356.814783D, "index", 5351.814783D, QueryRunnerTestHelper.MARKET_DIMENSION, "total_market", "uniques", QueryRunnerTestHelper.UNIQUES_2, "rows", 4L), ImmutableMap.of("addRowsIndexConstant", 4880.669692D, "index", 4875.669692D, QueryRunnerTestHelper.MARKET_DIMENSION, "upfront", "uniques", QueryRunnerTestHelper.UNIQUES_2, "rows", 4L), ImmutableMap.of("addRowsIndexConstant", 2250.876812D, "index", 2231.876812D, QueryRunnerTestHelper.MARKET_DIMENSION, "spot", "uniques", QueryRunnerTestHelper.UNIQUES_9, "rows", 18L)))));
    Sequence<Result<TopNResultValue>> results = runWithMerge(query);
    List<Result<BySegmentTopNResultValue>> resultList = results.map((Result<TopNResultValue> input) -> {
        // Stupid type erasure
        Object val = input.getValue();
        if (val instanceof BySegmentResultValue) {
            BySegmentResultValue bySegVal = (BySegmentResultValue) val;
            return new Result<>(input.getTimestamp(), new BySegmentTopNResultValue(Lists.transform(bySegVal.getResults(), res -> {
                if (Preconditions.checkNotNull(res) instanceof Result) {
                    Result theResult = (Result) res;
                    Object resVal = theResult.getValue();
                    if (resVal instanceof TopNResultValue) {
                        return new Result<>(theResult.getTimestamp(), (TopNResultValue) resVal);
                    }
                }
                throw new IAE("Bad input: [%s]", res);
            }), bySegVal.getSegmentId(), bySegVal.getInterval()));
        }
        throw new ISE("Bad type");
    }).toList();
    Result<BySegmentTopNResultValue> result = resultList.get(0);
    TestHelper.assertExpectedResults(expectedResults, result.getValue().getResults());
}
Also used : QueryPlus(org.apache.druid.query.QueryPlus) Arrays(java.util.Arrays) ExtractionFn(org.apache.druid.query.extraction.ExtractionFn) ByteBuffer(java.nio.ByteBuffer) Pair(org.apache.druid.java.util.common.Pair) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) DimExtractionFn(org.apache.druid.query.extraction.DimExtractionFn) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) Map(java.util.Map) QueryRunner(org.apache.druid.query.QueryRunner) IAE(org.apache.druid.java.util.common.IAE) ExtractionDimensionSpec(org.apache.druid.query.dimension.ExtractionDimensionSpec) Parameterized(org.junit.runners.Parameterized) AndDimFilter(org.apache.druid.query.filter.AndDimFilter) DateTimes(org.apache.druid.java.util.common.DateTimes) Sequence(org.apache.druid.java.util.common.guava.Sequence) FinalizeResultsQueryRunner(org.apache.druid.query.FinalizeResultsQueryRunner) Longs(com.google.common.primitives.Longs) HyperUniquesAggregatorFactory(org.apache.druid.query.aggregation.hyperloglog.HyperUniquesAggregatorFactory) AfterClass(org.junit.AfterClass) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Closer(org.apache.druid.java.util.common.io.Closer) AggregatorFactory(org.apache.druid.query.aggregation.AggregatorFactory) FloatMaxAggregatorFactory(org.apache.druid.query.aggregation.FloatMaxAggregatorFactory) ISE(org.apache.druid.java.util.common.ISE) TestExprMacroTable(org.apache.druid.query.expression.TestExprMacroTable) HyperUniqueFinalizingPostAggregator(org.apache.druid.query.aggregation.hyperloglog.HyperUniqueFinalizingPostAggregator) FloatLastAggregatorFactory(org.apache.druid.query.aggregation.last.FloatLastAggregatorFactory) RegexDimExtractionFn(org.apache.druid.query.extraction.RegexDimExtractionFn) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) QueryContexts(org.apache.druid.query.QueryContexts) ExprMacroTable(org.apache.druid.math.expr.ExprMacroTable) BySegmentResultValue(org.apache.druid.query.BySegmentResultValue) BySegmentResultValueClass(org.apache.druid.query.BySegmentResultValueClass) List(java.util.List) StringFormatExtractionFn(org.apache.druid.query.extraction.StringFormatExtractionFn) CloseableStupidPool(org.apache.druid.collections.CloseableStupidPool) ExpressionPostAggregator(org.apache.druid.query.aggregation.post.ExpressionPostAggregator) DimFilter(org.apache.druid.query.filter.DimFilter) QueryRunnerTestHelper(org.apache.druid.query.QueryRunnerTestHelper) DimensionSpec(org.apache.druid.query.dimension.DimensionSpec) Doubles(com.google.common.primitives.Doubles) DoubleFirstAggregatorFactory(org.apache.druid.query.aggregation.first.DoubleFirstAggregatorFactory) Iterables(com.google.common.collect.Iterables) DoubleSumAggregatorFactory(org.apache.druid.query.aggregation.DoubleSumAggregatorFactory) Intervals(org.apache.druid.java.util.common.Intervals) JavaScriptExtractionFn(org.apache.druid.query.extraction.JavaScriptExtractionFn) FilteredAggregatorFactory(org.apache.druid.query.aggregation.FilteredAggregatorFactory) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) JavaScriptConfig(org.apache.druid.js.JavaScriptConfig) ArrayList(java.util.ArrayList) MapLookupExtractor(org.apache.druid.query.extraction.MapLookupExtractor) Lists(com.google.common.collect.Lists) ColumnHolder(org.apache.druid.segment.column.ColumnHolder) ImmutableList(com.google.common.collect.ImmutableList) LookupExtractionFn(org.apache.druid.query.lookup.LookupExtractionFn) DoubleMinAggregatorFactory(org.apache.druid.query.aggregation.DoubleMinAggregatorFactory) TestQueryRunners(org.apache.druid.query.TestQueryRunners) LongLastAggregatorFactory(org.apache.druid.query.aggregation.last.LongLastAggregatorFactory) StringComparators(org.apache.druid.query.ordering.StringComparators) LongFirstAggregatorFactory(org.apache.druid.query.aggregation.first.LongFirstAggregatorFactory) MultipleIntervalSegmentSpec(org.apache.druid.query.spec.MultipleIntervalSegmentSpec) FloatMinAggregatorFactory(org.apache.druid.query.aggregation.FloatMinAggregatorFactory) ListFilteredDimensionSpec(org.apache.druid.query.dimension.ListFilteredDimensionSpec) BoundDimFilter(org.apache.druid.query.filter.BoundDimFilter) ExpressionVirtualColumn(org.apache.druid.segment.virtual.ExpressionVirtualColumn) ExpectedException(org.junit.rules.ExpectedException) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) FloatFirstAggregatorFactory(org.apache.druid.query.aggregation.first.FloatFirstAggregatorFactory) Nullable(javax.annotation.Nullable) DoubleMaxAggregatorFactory(org.apache.druid.query.aggregation.DoubleMaxAggregatorFactory) CardinalityAggregatorFactory(org.apache.druid.query.aggregation.cardinality.CardinalityAggregatorFactory) ExpressionLambdaAggregatorFactory(org.apache.druid.query.aggregation.ExpressionLambdaAggregatorFactory) ResponseContext(org.apache.druid.query.context.ResponseContext) TimeFormatExtractionFn(org.apache.druid.query.extraction.TimeFormatExtractionFn) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test) IOException(java.io.IOException) ExtractionDimFilter(org.apache.druid.query.filter.ExtractionDimFilter) StrlenExtractionFn(org.apache.druid.query.extraction.StrlenExtractionFn) Granularities(org.apache.druid.java.util.common.granularity.Granularities) Result(org.apache.druid.query.Result) TestHelper(org.apache.druid.segment.TestHelper) Rule(org.junit.Rule) NullHandling(org.apache.druid.common.config.NullHandling) ColumnType(org.apache.druid.segment.column.ColumnType) Preconditions(com.google.common.base.Preconditions) Assert(org.junit.Assert) Collections(java.util.Collections) BySegmentResultValue(org.apache.druid.query.BySegmentResultValue) HashMap(java.util.HashMap) IAE(org.apache.druid.java.util.common.IAE) Result(org.apache.druid.query.Result) ISE(org.apache.druid.java.util.common.ISE) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 19 with Arrays

use of java.util.Arrays in project jOOQ by jOOQ.

the class AbstractResult method format0.

/**
 * @param value The value to be formatted
 * @param visual Whether the formatted output is to be consumed visually
 *            (HTML, TEXT) or by a machine (CSV, JSON, XML)
 */
private static final String format0(Object value, boolean changed, boolean visual) {
    // [#2741] TODO: This logic will be externalised in new SPI
    String formatted = changed && visual ? "*" : "";
    if (value == null) {
        formatted += visual ? "{null}" : null;
    } else if (value.getClass() == byte[].class) {
        formatted += DatatypeConverter.printBase64Binary((byte[]) value);
    } else if (value.getClass().isArray()) {
        // [#6545] Nested arrays are handled recursively
        formatted += Arrays.stream((Object[]) value).map(f -> format0(f, false, visual)).collect(joining(", ", "[", "]"));
    } else if (value instanceof EnumType) {
        EnumType e = (EnumType) value;
        formatted += e.getLiteral();
    } else if (value instanceof List) {
        List<?> l = (List<?>) value;
        formatted += l.stream().map(f -> format0(f, false, visual)).collect(joining(", ", "[", "]"));
    } else if (value instanceof Record) {
        Record r = (Record) value;
        formatted += Arrays.stream(r.intoArray()).map(f -> format0(f, false, visual)).collect(joining(", ", "(", ")"));
    } else // [#6080] Support formatting of nested ROWs
    if (value instanceof Param) {
        formatted += format0(((Param<?>) value).getValue(), false, visual);
    } else // [#5238] Oracle DATE is really a TIMESTAMP(0)...
    if (value instanceof Date) {
        Date d = (Date) value;
        String date = value.toString();
        if (Date.valueOf(date).equals(value))
            formatted += date;
        else
            formatted += new Timestamp(d.getTime());
    } else {
        formatted += value.toString();
    }
    return formatted;
}
Also used : Arrays(java.util.Arrays) Row(org.jooq.Row) Display(org.jooq.ChartFormat.Display) Table(org.jooq.Table) DatatypeConverter(jakarta.xml.bind.DatatypeConverter) VALUE_ELEMENTS_WITH_FIELD_ATTRIBUTE(org.jooq.XMLFormat.RecordFormat.VALUE_ELEMENTS_WITH_FIELD_ATTRIBUTE) IOException(org.jooq.exception.IOException) Document(org.w3c.dom.Document) StringUtils.leftPad(org.jooq.tools.StringUtils.leftPad) DSLContext(org.jooq.DSLContext) AttributesImpl(org.xml.sax.helpers.AttributesImpl) StringUtils.rightPad(org.jooq.tools.StringUtils.rightPad) DSL.name(org.jooq.impl.DSL.name) Timestamp(java.sql.Timestamp) SettingsTools.renderLocale(org.jooq.conf.SettingsTools.renderLocale) Constants(org.jooq.Constants) Field(org.jooq.Field) TableRecord(org.jooq.TableRecord) Math.min(java.lang.Math.min) ChartFormat(org.jooq.ChartFormat) Result(org.jooq.Result) Cursor(org.jooq.Cursor) Collectors.joining(java.util.stream.Collectors.joining) DocumentFragment(org.w3c.dom.DocumentFragment) List(java.util.List) TableField(org.jooq.TableField) COLUMN_NAME_ELEMENTS(org.jooq.XMLFormat.RecordFormat.COLUMN_NAME_ELEMENTS) SAXException(org.xml.sax.SAXException) Writer(java.io.Writer) Math.max(java.lang.Math.max) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) JSONValue(org.jooq.tools.json.JSONValue) XML(org.jooq.XML) EnumType(org.jooq.EnumType) Deque(java.util.Deque) FormattingProvider(org.jooq.FormattingProvider) ArrayList(java.util.ArrayList) JSONFormat(org.jooq.JSONFormat) DSL.insertInto(org.jooq.impl.DSL.insertInto) Schema(org.jooq.Schema) Attributes(org.xml.sax.Attributes) CSVFormat(org.jooq.CSVFormat) ContentHandler(org.xml.sax.ContentHandler) Record(org.jooq.Record) InputSource(org.xml.sax.InputSource) XMLFormat(org.jooq.XMLFormat) NodeList(org.w3c.dom.NodeList) Iterator(java.util.Iterator) JSON(org.jooq.JSON) TXTFormat(org.jooq.TXTFormat) Formattable(org.jooq.Formattable) StringUtils(org.jooq.tools.StringUtils) Date(java.sql.Date) Param(org.jooq.Param) DefaultHandler(org.xml.sax.helpers.DefaultHandler) Configuration(org.jooq.Configuration) StringUtils.abbreviate(org.jooq.tools.StringUtils.abbreviate) Element(org.w3c.dom.Element) StringReader(java.io.StringReader) TreeMap(java.util.TreeMap) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) JSONB(org.jooq.JSONB) ArrayDeque(java.util.ArrayDeque) DSL.table(org.jooq.impl.DSL.table) Collections(java.util.Collections) EnumType(org.jooq.EnumType) Param(org.jooq.Param) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) TableRecord(org.jooq.TableRecord) Record(org.jooq.Record) Timestamp(java.sql.Timestamp) Date(java.sql.Date)

Example 20 with Arrays

use of java.util.Arrays in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class DataLayerBuilder method forAsset.

/**
 * Get an AssetDataBuilder with standard asset data.
 * This builder is suitable for most DAM Assets and pre-populates all required fields from the asset metadata.
 *
 * @param asset The asset used to initialize the AssetDataBuilder.
 * @return A new AssetDataBuilder pre-initialized using the DAM asset metadata.
 */
public static AssetDataBuilder forAsset(@NotNull final Asset asset) {
    return DataLayerBuilder.forAsset().withId(asset::getID).withFormat(asset::getMimeType).withUrl(asset::getPath).withLastModifiedDate(() -> new Date(Optional.of(asset.getLastModified()).filter(lastMod -> lastMod > 0).orElseGet(() -> Optional.ofNullable(asset.adaptTo(ValueMap.class)).map(vm -> vm.get(JcrConstants.JCR_CREATED, Calendar.class)).map(Calendar::getTimeInMillis).orElse(0L)))).withTags(() -> Optional.ofNullable(asset.getMetadataValueFromJcr(TagConstants.PN_TAGS)).filter(StringUtils::isNotEmpty).map(tagsValue -> tagsValue.split(",")).map(Arrays::stream).orElseGet(Stream::empty).filter(StringUtils::isNotEmpty).toArray(String[]::new)).withSmartTags(() -> {
        Map<String, Object> smartTags = new HashMap<>();
        Optional.ofNullable(asset.adaptTo(Resource.class)).map(assetResource -> assetResource.getChild(DamConstants.PREDICTED_TAGS)).map(predictedTagsResource -> {
            for (Resource smartTagResource : predictedTagsResource.getChildren()) {
                Optional.ofNullable(smartTagResource.adaptTo(ValueMap.class)).map(props -> Optional.ofNullable(props.get(AssetDataBuilder.SMARTTAG_NAME_PROP)).map(tagName -> Optional.ofNullable(smartTags.put((String) tagName, props.get(AssetDataBuilder.SMARTTAG_CONFIDENCE_PROP)))));
            }
            return Optional.empty();
        });
        return smartTags;
    });
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) Arrays(java.util.Arrays) JcrConstants(org.apache.jackrabbit.JcrConstants) Asset(com.day.cq.dam.api.Asset) ImageData(com.adobe.cq.wcm.core.components.models.datalayer.ImageData) Date(java.util.Date) AssetData(com.adobe.cq.wcm.core.components.models.datalayer.AssetData) Resource(org.apache.sling.api.resource.Resource) PageData(com.adobe.cq.wcm.core.components.models.datalayer.PageData) EMPTY_SUPPLIER(com.adobe.cq.wcm.core.components.models.datalayer.builder.DataLayerSupplier.EMPTY_SUPPLIER) HashMap(java.util.HashMap) ComponentData(com.adobe.cq.wcm.core.components.models.datalayer.ComponentData) StringUtils(org.apache.commons.lang3.StringUtils) DamConstants(com.day.cq.dam.api.DamConstants) DataLayerSupplierImpl(com.adobe.cq.wcm.core.components.internal.models.v1.datalayer.builder.DataLayerSupplierImpl) TagConstants(com.day.cq.tagging.TagConstants) Calendar(java.util.Calendar) Stream(java.util.stream.Stream) Map(java.util.Map) Optional(java.util.Optional) ContainerData(com.adobe.cq.wcm.core.components.models.datalayer.ContainerData) NotNull(org.jetbrains.annotations.NotNull) HashMap(java.util.HashMap) ValueMap(org.apache.sling.api.resource.ValueMap) Calendar(java.util.Calendar) Resource(org.apache.sling.api.resource.Resource) Stream(java.util.stream.Stream) Date(java.util.Date)

Aggregations

Arrays (java.util.Arrays)69 List (java.util.List)45 ArrayList (java.util.ArrayList)39 Map (java.util.Map)31 Test (org.junit.Test)23 Collections (java.util.Collections)21 HashMap (java.util.HashMap)18 Collectors (java.util.stream.Collectors)14 Set (java.util.Set)12 Function (java.util.function.Function)12 Stream (java.util.stream.Stream)12 IOException (java.io.IOException)11 TimeUnit (java.util.concurrent.TimeUnit)11 Optional (java.util.Optional)9 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)9 Logger (org.slf4j.Logger)9 LoggerFactory (org.slf4j.LoggerFactory)9 HashSet (java.util.HashSet)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6