/** * Converts an list of strings into a space-separated string combining them all, suitable for use as an HTML class * attribute value. * * @param classes classes to combine * @return the joined classes, or null if classes is empty */ public static String toClassAttributeValue(List<String> classes) { if (classes.isEmpty()) return null; return InternalUtils.join(classes, " "); }
static String wrongPhaseResultType(List<String> expectedTypes) { return MESSAGES.format("wrong-phase-result-type", InternalUtils.join(expectedTypes)); }
public void attributes(Object... namesAndValues) { ensureCurrentElement(); int i = 0; int length = namesAndValues.length; if (length % 2 != 0) throw new IllegalArgumentException(String.format("Writing attributes of the element '%s' failed. An attribute name or value is omitted [%s]. Please provide an even number of values, alternating names and values.", current.getName(), InternalUtils.join(Arrays .asList(namesAndValues)))); while (i < length) { // name should never be null. String name = namesAndValues[i++].toString(); Object value = namesAndValues[i++]; if (value == null) continue; current.attribute(name, value.toString()); } }
@Override public ThreadInfo map(Thread t) { List<String> flags = CollectionFactory.newList(); if (t.isDaemon()) { flags.add("daemon"); } if (!t.isAlive()) { flags.add("NOT alive"); } if (t.isInterrupted()) { flags.add("interrupted"); } if (t.getPriority() != Thread.NORM_PRIORITY) { flags.add("priority " + t.getPriority()); } return new ThreadInfo(Thread.currentThread() == t ? "active-thread" : "", t.getName(), t.getState().name(), InternalUtils.join(flags), t.getThreadGroup()); } }).sort().toList();
public InputStream openStream() throws IOException { DecimalFormatSymbols decimalSymbols = DecimalFormatSymbols.getInstance(locale); Map<String, Object> symbols = CollectionFactory.newMap(); symbols.put("decimal-symbols.group", decimalSymbols.getGroupingSeparator()); symbols.put("decimal-symbols.minus", decimalSymbols.getMinusSign()); symbols.put("decimal-symbols.decimal", decimalSymbols.getDecimalSeparator()); DateFormatSymbols dateSymbols = new DateFormatSymbols(locale); List<String> months = Arrays.asList(dateSymbols.getMonths()).subList(0, 12); // Comma-separated list, starting with January symbols.put("date-symbols.months", InternalUtils.join(months, ",")); List<String> days = Arrays.asList(dateSymbols.getWeekdays()).subList(1, 8); // Comma-separated list, starting with Sunday symbols.put("date-symbols.days", InternalUtils.join(days, ",")); Calendar c = Calendar.getInstance(locale); // First day of the week, usually 0 for Sunday (e.g., in the US) or 1 for Monday // (e.g., France). symbols.put("date-symbols.first-day", c.getFirstDayOfWeek() - 1); StringBuilder builder = new StringBuilder(); for (Map.Entry<String, Object> entry : symbols.entrySet()) { write(builder, entry.getKey(), entry.getValue()); } return toInputStream(builder.toString()); }
private PersistenceProvider getPersistenceProvider(final String persistenceUnitName, final String providerClassName) { final PersistenceProviderResolver resolver = PersistenceProviderResolverHolder .getPersistenceProviderResolver(); final List<PersistenceProvider> providers = resolver.getPersistenceProviders(); if (providers.isEmpty()) { throw new IllegalStateException( "No PersistenceProvider implementation available in the runtime environment."); } if(1 < providers.size() && providerClassName == null) { throw new IllegalStateException( String.format("Persistence providers [%s] are available in the runtime environment " + "but no provider class is defined for the persistence unit %s.", InternalUtils.join(toProviderClasses(providers)), persistenceUnitName)); } if(providerClassName != null) { return findPersistenceProviderByName(providers, providerClassName); } return providers.get(0); }
private PersistenceProvider getPersistenceProvider(final String persistenceUnitName, final String providerClassName) { final PersistenceProviderResolver resolver = PersistenceProviderResolverHolder .getPersistenceProviderResolver(); final List<PersistenceProvider> providers = resolver.getPersistenceProviders(); if (providers.isEmpty()) { throw new IllegalStateException( "No PersistenceProvider implementation available in the runtime environment."); } if(1 < providers.size() && providerClassName == null) { throw new IllegalStateException( String.format("Persistence providers [%s] are available in the runtime environment " + "but no provider class is defined for the persistence unit %s.", InternalUtils.join(toProviderClasses(providers)), persistenceUnitName)); } if(providerClassName != null) { return findPersistenceProviderByName(providers, providerClassName); } return providers.get(0); }
private void validateSortedFields(List<PlasticField> sortedFields) { List<Integer> expectedIndexes = CollectionFactory.newList(); List<Integer> actualIndexes = CollectionFactory.newList(); Set<Boolean> activates = CollectionFactory.newSet(); Set<Boolean> passivates = CollectionFactory.newSet(); for (int i = 0; i < sortedFields.size(); ++i) { PlasticField field = sortedFields.get(i); PageActivationContext annotation = field.getAnnotation(PageActivationContext.class); expectedIndexes.add(i); actualIndexes.add(annotation.index()); activates.add(annotation.activate()); passivates.add(annotation.passivate()); } List<String> errors = CollectionFactory.newList(); if (!expectedIndexes.equals(actualIndexes)) { errors.add(String.format("Index values must start at 0 and increment by 1 (expected [%s], found [%s])", InternalUtils.join(expectedIndexes), InternalUtils.join(actualIndexes))); } if (activates.size() > 1) { errors.add("Illegal values for 'activate' (all fields must have the same value)"); } if (passivates.size() > 1) { errors.add("Illegal values for 'passivate' (all fields must have the same value)"); } if (!errors.isEmpty()) { throw new RuntimeException(String.format("Invalid values for @PageActivationContext: %s", InternalUtils.join(errors))); } }
public String getSpringBeans() { return InternalUtils.join(Arrays.asList(applicationContext.getBeanDefinitionNames())); } }
private PersistenceProvider findPersistenceProviderByName(final List<PersistenceProvider> providers, final String providerClassName) { PersistenceProvider provider = F.flow(providers).filter(new Predicate<PersistenceProvider>() { @Override public boolean accept(PersistenceProvider next) { return next.getClass().getName().equals(providerClassName); } }).first(); if(provider == null) { throw new IllegalStateException( String.format("No persistence provider of type %s found in the runtime environment. " + "Following providers are available: [%s]", providerClassName, InternalUtils.join(toProviderClasses(providers)))); } return provider; }
private PersistenceProvider findPersistenceProviderByName(final List<PersistenceProvider> providers, final String providerClassName) { PersistenceProvider provider = F.flow(providers).filter(new Predicate<PersistenceProvider>() { @Override public boolean accept(PersistenceProvider next) { return next.getClass().getName().equals(providerClassName); } }).first(); if(provider == null) { throw new IllegalStateException( String.format("No persistence provider of type %s found in the runtime environment. " + "Following providers are available: [%s]", providerClassName, InternalUtils.join(toProviderClasses(providers)))); } return provider; }
writeElement(writer, "td", InternalUtils.join(flags)); writeElement(writer, "td", addWordBreaks(pd.defaultValue)); writeElement(writer, "td class='colLast'", pd.defaultPrefix);
private FieldValidator createValidator(Field field, ValidatorSpecification spec, String overrideId, Messages overrideMessages) { String validatorType = spec.getValidatorType(); assert InternalUtils.isNonBlank(validatorType); Validator validator = validators.get(validatorType); if (validator == null) throw new IllegalArgumentException(String.format("Unknown validator type '%s'. Configured validators are %s.", validatorType, InternalUtils.join(InternalUtils.sortedKeys(validators)))); // I just have this thing about always treating parameters as finals, so // we introduce a second variable to treat a mutable. String formValidationid = formSupport.getFormValidationId(); Object coercedConstraintValue = computeConstraintValue(validatorType, validator, spec.getConstraintValue(), formValidationid, overrideId, overrideMessages); MessageFormatter formatter = findMessageFormatter(formValidationid, overrideId, overrideMessages, validatorType, validator); return new FieldValidatorImpl(field, coercedConstraintValue, formatter, validator, formSupport); }
@Override public void render(LessCompiler.Problem problem, MarkupWriter writer) { List<String> strings = CollectionFactory.newList(); if (InternalUtils.isNonBlank(problem.getMessage())) { strings.add(problem.getMessage()); } // Inside WRO4J we see that the LessSource is a StringSource with no useful toString(), so // it is omitted. We may need to create our own processors, stripping away a couple of layers of // WRO4J to get proper exception reporting! if (problem.getLine() > 0) { strings.add("line " + problem.getLine()); } if (problem.getCharacter() > 0) { strings.add("position " + problem.getCharacter()); } writer.write(InternalUtils.join(strings, " - ")); } });
InternalUtils.join(CollectionFactory.newList(result.errors), ";")));
@Override public void render(LessCompiler.Problem problem, MarkupWriter writer) { List<String> strings = CollectionFactory.newList(); if (InternalUtils.isNonBlank(problem.getMessage())) { strings.add(problem.getMessage()); } // Inside WRO4J we see that the LessSource is a StringSource with no useful toString(), so // it is omitted. We may need to create our own processors, stripping away a couple of layers of // WRO4J to get proper exception reporting! if (problem.getLine() > 0) { strings.add("line " + problem.getLine()); } if (problem.getCharacter() > 0) { strings.add("position " + problem.getCharacter()); } writer.write(InternalUtils.join(strings, " - ")); } });
InternalUtils.join(CollectionFactory.newList(result.errors), ";")));
private void validateUnitInfos(List<TapestryPersistenceUnitInfo> persistenceUnitInfos) { final List<String> affectedUnits = F.flow(persistenceUnitInfos).filter(new Predicate<TapestryPersistenceUnitInfo>() { @Override public boolean accept(TapestryPersistenceUnitInfo info) { return !info.excludeUnlistedClasses(); } }).map(new Mapper<TapestryPersistenceUnitInfo, String>() { @Override public String map(TapestryPersistenceUnitInfo info) { return info.getPersistenceUnitName(); } }).toList(); if (0 < affectedUnits.size()) { throw new RuntimeException( String.format( "Persistence units '%s' are configured to include managed classes that have not been explicitly listed. " + "This is forbidden when multiple persistence units are used in the same application. " + "Please configure persistence units to exclude unlisted managed classes (e.g. by removing <exclude-unlisted-classes> element) " + "and include them explicitly.", InternalUtils.join(affectedUnits))); } }
private void validateUnitInfos(List<TapestryPersistenceUnitInfo> persistenceUnitInfos) { final List<String> affectedUnits = F.flow(persistenceUnitInfos).filter(new Predicate<TapestryPersistenceUnitInfo>() { @Override public boolean accept(TapestryPersistenceUnitInfo info) { return !info.excludeUnlistedClasses(); } }).map(new Mapper<TapestryPersistenceUnitInfo, String>() { @Override public String map(TapestryPersistenceUnitInfo info) { return info.getPersistenceUnitName(); } }).toList(); if (0 < affectedUnits.size()) { throw new RuntimeException( String.format( "Persistence units '%s' are configured to include managed classes that have not been explicitly listed. " + "This is forbidden when multiple persistence units are used in the same application. " + "Please configure persistence units to exclude unlisted managed classes (e.g. by removing <exclude-unlisted-classes> element) " + "and include them explicitly.", InternalUtils.join(affectedUnits))); } }
public ExtensibleJavaScriptStack(AssetSource assetSource, List<StackExtension> configuration) { this.assetSource = assetSource; Flow<StackExtension> extensions = F.flow(configuration); libraries = extensions.filter(by(StackExtensionType.LIBRARY)).map(extractValue).map(stringToAsset).toList(); stacks = extensions.filter(by(StackExtensionType.STACK)).map(extractValue).toList(); modules = extensions.filter(by(StackExtensionType.MODULE)).map(extractValue).toList(); stylesheets = extensions.filter(by(StackExtensionType.STYLESHEET)).map(extractValue).map(stringToAsset) .map(assetToStylesheetLink).toList(); List<String> initializations = extensions.filter(by(StackExtensionType.INITIALIZATION)).map(extractValue) .toList(); initialization = initializations.isEmpty() ? null : InternalUtils.join(initializations, "\n"); strategy = toStrategy(extensions); }