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));
}
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;
}
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());
}
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;
}
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;
});
}
Aggregations