List of usage examples for java.util Collections addAll
@SafeVarargs public static <T> boolean addAll(Collection<? super T> c, T... elements)
From source file:org.solmix.runtime.support.spring.ContainerApplicationContext.java
@Override protected Resource[] getConfigResources() { List<Resource> resources = new ArrayList<Resource>(); if (includeDefault) { try {/*from ww w . j a va2 s . c o m*/ PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver( Thread.currentThread().getContextClassLoader()); Collections.addAll(resources, resolver.getResources(DEFAULT_CFG_FILE)); Resource[] exts = resolver.getResources(DEFAULT_EXT_CFG_FILE); for (Resource r : exts) { InputStream is = r.getInputStream(); BufferedReader rd = new BufferedReader(new InputStreamReader(is, "UTF-8")); String line = rd.readLine(); while (line != null) { if (!"".equals(line)) { resources.add(resolver.getResource(line)); } line = rd.readLine(); } is.close(); } } catch (IOException ex) { // ignore } } boolean usingDefault = false; if (cfgFiles == null) { String userConfig = System.getProperty(BeanConfigurer.USER_CFG_FILE_PROPERTY_NAME); if (userConfig != null) { cfgFiles = new String[] { userConfig }; } } if (cfgFiles == null) { usingDefault = true; cfgFiles = new String[] { BeanConfigurer.USER_CFG_FILE }; } for (String cfgFile : cfgFiles) { final Resource f = findResource(cfgFile); if (f != null && f.exists()) { resources.add(f); LOG.info("Used configed file {}", cfgFile); } else { if (!usingDefault) { LOG.warn("Can't find configure file {}", cfgFile); throw new ApplicationContextException("Can't find configure file"); } } } if (cfgURLs != null) { for (URL u : cfgURLs) { UrlResource ur = new UrlResource(u); if (ur.exists()) { resources.add(ur); } else { LOG.warn("Can't find configure file {}", u.getPath()); } } } if (LOG.isDebugEnabled()) { LOG.debug("Creating application context with resources " + resources.size()); } if (0 == resources.size()) { return null; } Resource[] res = new Resource[resources.size()]; res = resources.toArray(res); return res; }
From source file:com.mmnaseri.dragonfly.metadata.impl.AnnotationTableMetadataResolver.java
@Override public <E> TableMetadata<E> resolve(final Class<E> entityType) { log.info("Resolving metadata for " + entityType.getCanonicalName()); final String tableName; final String schema; final Set<Set<String>> uniqueColumns = new HashSet<Set<String>>(); final Set<String> keyColumns = new HashSet<String>(); final Set<String> foreignKeys = new HashSet<String>(); final HashSet<RelationMetadata<E, ?>> foreignReferences = new HashSet<RelationMetadata<E, ?>>(); if (entityType.isAnnotationPresent(Table.class)) { final Table table = entityType.getAnnotation(Table.class); tableName = table.name().isEmpty() ? entityType.getSimpleName() : table.name(); schema = table.schema();/*from w w w . jav a 2 s . co m*/ for (UniqueConstraint constraint : table.uniqueConstraints()) { final HashSet<String> columns = new HashSet<String>(); uniqueColumns.add(columns); Collections.addAll(columns, constraint.columnNames()); } } else { tableName = entityType.getSimpleName(); schema = NO_SCHEMA; } final Set<StoredProcedureMetadata> storedProcedures = new HashSet<StoredProcedureMetadata>(); if (entityType.isAnnotationPresent(StoredProcedure.class)) { storedProcedures.add(getStoredProcedureMetadata(entityType.getAnnotation(StoredProcedure.class))); } else if (entityType.isAnnotationPresent(StoredProcedures.class)) { final StoredProcedure[] procedures = entityType.getAnnotation(StoredProcedures.class).value(); for (StoredProcedure procedure : procedures) { storedProcedures.add(getStoredProcedureMetadata(procedure)); } } //noinspection unchecked if (!withMethods(entityType).keep(new GetterMethodFilter()) .keep(new AnnotatedElementFilter(Column.class, JoinColumn.class)) .keep(new AnnotatedElementFilter(Transient.class)).isEmpty()) { throw new TransientColumnFoundError(entityType); } final Collection<SequenceMetadata> sequences = new HashSet<SequenceMetadata>(); final HashSet<ConstraintMetadata> constraints = new HashSet<ConstraintMetadata>(); final AtomicReference<ColumnMetadata> versionColumn = new AtomicReference<ColumnMetadata>(); //noinspection unchecked final List<Method> getters = withMethods(entityType).keep(new GetterMethodFilter()).list(); final List<Method> filteredGetters = new ArrayList<Method>(); for (Method getter : getters) { final PropertyAccessorFilter filter = new PropertyAccessorFilter( ReflectionUtils.getPropertyName(getter.getName())); final Method method = with(filteredGetters).find(filter); if (method == null) { filteredGetters.add(getter); } else if (method.getDeclaringClass().equals(getter.getDeclaringClass())) { filteredGetters.remove(method); filteredGetters.add(pickGetter(method, getter)); } } getters.clear(); getters.addAll(filteredGetters); //noinspection unchecked final Collection<ColumnMetadata> tableColumns = with(getters) .drop(new AnnotatedElementFilter(Transient.class)).drop(new AnnotatedElementFilter(OneToMany.class)) .drop(new AnnotatedElementFilter(ManyToMany.class)).drop(new Filter<Method>() { @Override public boolean accepts(Method item) { return item.isAnnotationPresent(OneToOne.class) && !item.isAnnotationPresent(JoinColumn.class); } }).drop(new PropertyAccessorFilter(CLASS_PROPERTY)) .transform(new Transformer<Method, ColumnMetadata>() { @Override public ColumnMetadata map(Method method) { final JoinColumn joinColumn = method.getAnnotation(JoinColumn.class); Column column = method.getAnnotation(Column.class); if (column == null && joinColumn == null) { //let's assume it is a column anyway column = new DefaultColumn(); } final String propertyName = ReflectionUtils.getPropertyName(method.getName()); if (column != null && joinColumn != null) { throw new ColumnDefinitionError( "Property " + propertyName + " is defined as both a column and a join column"); } final Class<?> propertyType = method.getReturnType(); String name = column != null ? column.name() : joinColumn.name(); if (name.isEmpty()) { name = propertyName; } final boolean nullable = column != null ? column.nullable() : joinColumn.nullable(); final int length = column != null ? column.length() : 0; final int precision = column != null ? column.precision() : 0; final int scale = column != null ? column.scale() : 0; final ValueGenerationType generationType = determineValueGenerationType(method); final String valueGenerator = determineValueGenerator(method); final ColumnMetadata foreignColumn = joinColumn == null ? null : determineForeignReference(method); final int type = getColumnType(method, foreignColumn); final Class<?> declaringClass = ReflectionUtils.getDeclaringClass(method); if (method.isAnnotationPresent(BasicCollection.class) && !(Collection.class.isAssignableFrom(method.getReturnType()))) { throw new ColumnDefinitionError( "Collection column must return a collection value: " + tableName + "." + name); } final ResolvedColumnMetadata columnMetadata = new ResolvedColumnMetadata( new UnresolvedTableMetadata<E>(entityType), declaringClass, name, type, propertyName, propertyType, nullable, length, precision, scale, generationType, valueGenerator, foreignColumn, method.isAnnotationPresent(BasicCollection.class), isComplex(method, foreignColumn)); if (foreignColumn != null) { foreignKeys.add(name); } if (method.isAnnotationPresent(Id.class)) { keyColumns.add(name); } if (method.isAnnotationPresent(SequenceGenerator.class)) { final SequenceGenerator annotation = method.getAnnotation(SequenceGenerator.class); sequences.add(new ImmutableSequenceMetadata(annotation.name(), annotation.initialValue(), annotation.allocationSize())); } if (joinColumn != null) { final RelationType relationType = getRelationType(method); final CascadeMetadata cascadeMetadata = getCascadeMetadata(method); final boolean isLazy = determineLaziness(method); final DefaultRelationMetadata<E, Object> reference = new DefaultRelationMetadata<E, Object>( declaringClass, columnMetadata.getPropertyName(), true, null, null, null, relationType, cascadeMetadata, isLazy, null); reference.setForeignColumn(foreignColumn); foreignReferences.add(reference); } if (method.isAnnotationPresent(Version.class)) { if (versionColumn.get() != null) { throw new MultipleVersionColumnsError(entityType); } if (column != null) { if (columnMetadata.isNullable()) { throw new VersionColumnDefinitionError("Version column cannot be nullable: " + entityType.getCanonicalName() + "." + columnMetadata.getName()); } versionColumn.set(columnMetadata); } else { throw new VersionColumnDefinitionError( "Only local columns can be used for optimistic locking"); } } return columnMetadata; } }).list(); //handling one-to-many relations //noinspection unchecked withMethods(entityType).keep(new GetterMethodFilter()) .drop(new AnnotatedElementFilter(Column.class, JoinColumn.class)) .keep(new AnnotatedElementFilter(OneToMany.class)).each(new Processor<Method>() { @Override public void process(Method method) { if (!Collection.class.isAssignableFrom(method.getReturnType())) { throw new RelationDefinitionError( "One to many relations must be collections. Error in " + method); } final OneToMany annotation = method.getAnnotation(OneToMany.class); Class<?> foreignEntity = annotation.targetEntity().equals(void.class) ? ((Class) ((ParameterizedType) method.getGenericReturnType()) .getActualTypeArguments()[0]) : annotation.targetEntity(); String foreignColumnName = annotation.mappedBy(); final String propertyName = ReflectionUtils.getPropertyName(method.getName()); if (foreignColumnName.isEmpty()) { //noinspection unchecked final List<Method> list = withMethods(foreignEntity) .keep(new AnnotatedElementFilter(JoinColumn.class)) .keep(new AnnotatedElementFilter(ManyToOne.class)) .keep(new MethodReturnTypeFilter(entityType)).list(); if (list.isEmpty()) { throw new RelationDefinitionError( "No ManyToOne relations for " + entityType.getCanonicalName() + " were found on " + foreignEntity.getCanonicalName()); } if (list.size() > 1) { throw new RelationDefinitionError("Ambiguous one to many relationship on " + entityType.getCanonicalName() + "." + propertyName); } final Method foreignMethod = list.get(0); final Column column = foreignMethod.getAnnotation(Column.class); final JoinColumn joinColumn = foreignMethod.getAnnotation(JoinColumn.class); foreignColumnName = column == null ? joinColumn.name() : column.name(); if (foreignColumnName.isEmpty()) { foreignColumnName = ReflectionUtils.getPropertyName(foreignMethod.getName()); } } final List<OrderMetadata> ordering = getOrdering(foreignEntity, method.getAnnotation(OrderBy.class)); //noinspection unchecked final UnresolvedColumnMetadata foreignColumn = new UnresolvedColumnMetadata( foreignColumnName, new UnresolvedTableMetadata<Object>((Class<Object>) foreignEntity)); final DefaultRelationMetadata<E, Object> reference = new DefaultRelationMetadata<E, Object>( ReflectionUtils.getDeclaringClass(method), propertyName, false, null, null, null, getRelationType(method), getCascadeMetadata(method), determineLaziness(method), ordering); reference.setForeignColumn(foreignColumn); foreignReferences.add(reference); } }); //Handling one-to-one relations where the entity is not the owner of the relationship //noinspection unchecked withMethods(entityType).keep(new GetterMethodFilter()).keep(new AnnotatedElementFilter(OneToOne.class)) .drop(new AnnotatedElementFilter(Column.class, JoinColumn.class)).each(new Processor<Method>() { @Override public void process(Method method) { final OneToOne annotation = method.getAnnotation(OneToOne.class); Class<?> foreignEntity = annotation.targetEntity().equals(void.class) ? method.getReturnType() : annotation.targetEntity(); final String propertyName = ReflectionUtils.getPropertyName(method.getName()); final DefaultRelationMetadata<E, Object> reference = new DefaultRelationMetadata<E, Object>( ReflectionUtils.getDeclaringClass(method), propertyName, false, null, null, null, getRelationType(method), getCascadeMetadata(method), determineLaziness(method), null); String foreignColumnName = annotation.mappedBy(); if (foreignColumnName.isEmpty()) { //noinspection unchecked final List<Method> methods = withMethods(foreignEntity).keep(new GetterMethodFilter()) .keep(new MethodReturnTypeFilter(entityType)) .keep(new AnnotatedElementFilter(OneToOne.class)) .keep(new AnnotatedElementFilter(Column.class, JoinColumn.class)).list(); if (methods.isEmpty()) { throw new EntityDefinitionError( "No OneToOne relations were found on " + foreignEntity.getCanonicalName() + " for " + entityType.getCanonicalName()); } if (methods.size() > 1) { throw new EntityDefinitionError("Ambiguous OneToOne relation on " + entityType.getCanonicalName() + "." + propertyName); } final Method foreignMethod = methods.get(0); final Column column = foreignMethod.getAnnotation(Column.class); final JoinColumn joinColumn = foreignMethod.getAnnotation(JoinColumn.class); foreignColumnName = column == null ? joinColumn.name() : column.name(); if (foreignColumnName.isEmpty()) { foreignColumnName = ReflectionUtils.getPropertyName(foreignMethod.getName()); } } //noinspection unchecked reference.setForeignColumn(new UnresolvedColumnMetadata(foreignColumnName, new UnresolvedTableMetadata<Object>((Class<Object>) foreignEntity))); foreignReferences.add(reference); } }); final HashSet<NamedQueryMetadata> namedQueries = new HashSet<NamedQueryMetadata>(); if (entityType.isAnnotationPresent(SequenceGenerator.class)) { final SequenceGenerator annotation = entityType.getAnnotation(SequenceGenerator.class); sequences.add(new ImmutableSequenceMetadata(annotation.name(), annotation.initialValue(), annotation.allocationSize())); } //finding orderings //noinspection unchecked final List<OrderMetadata> ordering = withMethods(entityType).keep(new AnnotatedElementFilter(Column.class)) .keep(new AnnotatedElementFilter(Order.class)).sort(new Comparator<Method>() { @Override public int compare(Method firstMethod, Method secondMethod) { final Order first = firstMethod.getAnnotation(Order.class); final Order second = secondMethod.getAnnotation(Order.class); return ((Integer) first.priority()).compareTo(second.priority()); } }).transform(new Transformer<Method, OrderMetadata>() { @Override public OrderMetadata map(Method input) { final Column column = input.getAnnotation(Column.class); String columnName = column.name().isEmpty() ? ReflectionUtils.getPropertyName(input.getName()) : column.name(); ColumnMetadata columnMetadata = with(tableColumns).find(new ColumnNameFilter(columnName)); if (columnMetadata == null) { columnMetadata = with(tableColumns).find(new ColumnPropertyFilter(columnName)); } if (columnMetadata == null) { throw new NoSuchColumnError(entityType, columnName); } return new ImmutableOrderMetadata(columnMetadata, input.getAnnotation(Order.class).value()); } }).list(); final ResolvedTableMetadata<E> tableMetadata = new ResolvedTableMetadata<E>(entityType, schema, tableName, constraints, tableColumns, namedQueries, sequences, storedProcedures, foreignReferences, versionColumn.get(), ordering); if (!keyColumns.isEmpty()) { constraints.add(new PrimaryKeyConstraintMetadata(tableMetadata, with(keyColumns).transform(new Transformer<String, ColumnMetadata>() { @Override public ColumnMetadata map(String columnName) { return getColumnMetadata(columnName, tableColumns, entityType); } }).list())); } if (entityType.isAnnotationPresent(NamedNativeQueries.class)) { final NamedNativeQuery[] queries = entityType.getAnnotation(NamedNativeQueries.class).value(); for (NamedNativeQuery query : queries) { namedQueries.add(new ImmutableNamedQueryMetadata(query.name(), query.query(), tableMetadata, QueryType.NATIVE)); } } else if (entityType.isAnnotationPresent(NamedNativeQuery.class)) { final NamedNativeQuery query = entityType.getAnnotation(NamedNativeQuery.class); namedQueries.add( new ImmutableNamedQueryMetadata(query.name(), query.query(), tableMetadata, QueryType.NATIVE)); } constraints .addAll(with(uniqueColumns).sort().transform(new Transformer<Set<String>, Set<ColumnMetadata>>() { @Override public Set<ColumnMetadata> map(Set<String> columns) { return with(columns).transform(new Transformer<String, ColumnMetadata>() { @Override public ColumnMetadata map(String columnName) { return getColumnMetadata(columnName, tableColumns, entityType); } }).set(); } }).transform(new Transformer<Set<ColumnMetadata>, UniqueConstraintMetadata>() { @Override public UniqueConstraintMetadata map(Set<ColumnMetadata> columns) { return new UniqueConstraintMetadata(tableMetadata, columns); } }).list()); constraints.addAll(with(foreignKeys).sort().transform(new Transformer<String, ColumnMetadata>() { @Override public ColumnMetadata map(String columnName) { return getColumnMetadata(columnName, tableColumns, entityType); } }).transform(new Transformer<ColumnMetadata, ForeignKeyConstraintMetadata>() { @Override public ForeignKeyConstraintMetadata map(ColumnMetadata columnMetadata) { return new ForeignKeyConstraintMetadata(tableMetadata, columnMetadata); } }).list()); //going after many-to-many relations //noinspection unchecked withMethods(entityType).drop(new AnnotatedElementFilter(Column.class, JoinColumn.class)) .keep(new GetterMethodFilter()).forThose(new Filter<Method>() { @Override public boolean accepts(Method item) { return item.isAnnotationPresent(ManyToMany.class); } }, new Processor<Method>() { @Override public void process(Method method) { final ManyToMany annotation = method.getAnnotation(ManyToMany.class); Class<?> foreignEntity = annotation.targetEntity().equals(void.class) ? ((Class) ((ParameterizedType) method.getGenericReturnType()) .getActualTypeArguments()[0]) : annotation.targetEntity(); String foreignProperty = annotation.mappedBy(); if (foreignProperty.isEmpty()) { //noinspection unchecked final List<Method> methods = withMethods(foreignEntity).keep(new GetterMethodFilter()) .keep(new AnnotatedElementFilter(ManyToMany.class)).list(); if (methods.isEmpty()) { throw new EntityDefinitionError( "Failed to locate corresponding many-to-many relation on " + foreignEntity.getCanonicalName()); } if (methods.size() == 1) { throw new EntityDefinitionError("Ambiguous many-to-many relationship defined"); } foreignProperty = ReflectionUtils.getPropertyName(methods.get(0).getName()); } final List<OrderMetadata> ordering = getOrdering(foreignEntity, method.getAnnotation(OrderBy.class)); //noinspection unchecked foreignReferences.add(new DefaultRelationMetadata<E, Object>( ReflectionUtils.getDeclaringClass(method), ReflectionUtils.getPropertyName(method.getName()), false, tableMetadata, null, new UnresolvedColumnMetadata(foreignProperty, new UnresolvedTableMetadata<Object>((Class<Object>) foreignEntity)), RelationType.MANY_TO_MANY, getCascadeMetadata(method), determineLaziness(method), ordering)); } }); return tableMetadata; }
From source file:com.manydesigns.portofino.pageactions.crud.ModelSelectionProviderSupport.java
public void setup() { crudSelectionProviders = new ArrayList<CrudSelectionProvider>(); Set<String> configuredSPs = new HashSet<String>(); for (SelectionProviderReference ref : crudAction.getCrudConfiguration().getSelectionProviders()) { boolean added; if (ref.getForeignKey() != null) { added = setupSelectionProvider(ref, ref.getForeignKey(), configuredSPs); } else if (ref.getSelectionProvider() instanceof DatabaseSelectionProvider) { DatabaseSelectionProvider dsp = (DatabaseSelectionProvider) ref.getSelectionProvider(); added = setupSelectionProvider(ref, dsp, configuredSPs); } else {//from w ww. j ava 2 s. co m AbstractCrudAction.logger.error("Unsupported selection provider: " + ref.getSelectionProvider()); continue; } if (ref.isEnabled() && !added) { AbstractCrudAction.logger .warn("Selection provider {} not added; check whether the fields on which it is configured " + "overlap with some other selection provider", ref); } } //Remove disabled selection providers and mark them as configured to avoid re-adding them Iterator<CrudSelectionProvider> it = crudSelectionProviders.iterator(); while (it.hasNext()) { CrudSelectionProvider sp = it.next(); if (sp.getSelectionProvider() == null) { it.remove(); Collections.addAll(configuredSPs, sp.getFieldNames()); } } Table table = crudAction.getCrudConfiguration().getActualTable(); if (table != null) { for (ForeignKey fk : table.getForeignKeys()) { setupSelectionProvider(null, fk, configuredSPs); } for (ModelSelectionProvider dsp : table.getSelectionProviders()) { if (dsp instanceof DatabaseSelectionProvider) { setupSelectionProvider(null, (DatabaseSelectionProvider) dsp, configuredSPs); } else { AbstractCrudAction.logger.error("Unsupported selection provider: " + dsp); } } } }
From source file:de.tor.tribes.util.bb.PointStatsFormatter.java
@Override public String[] getTemplateVariables() { List<String> vars = new LinkedList<>(); Collections.addAll(vars, VARIABLES); vars.add(TRIBE);/* w w w .j a va 2 s. c o m*/ vars.add(POINTS_BEFORE); vars.add(POINTS_AFTER); vars.add(POINTS_DIFFERENCE); vars.add(PERCENT_DIFFERENCE); vars.add(KILLS_PER_POINT); return vars.toArray(new String[vars.size()]); }
From source file:com.streamsets.pipeline.lib.fuzzy.FuzzyMatch.java
private static Set<String> tokenizeString(String str) { Set<String> set = new HashSet<>(); // Normalize and tokenize the input strings before storing as a set. StringTokenizer st = new StringTokenizer(str); while (st.hasMoreTokens()) { String t1 = st.nextToken(); String[] tokens = camelAndSnakeCaseSplitter.split(t1); for (int i = 0; i < tokens.length; i++) { tokens[i] = tokens[i].toLowerCase(); }/*from w w w . j a v a 2s. c o m*/ Collections.addAll(set, tokens); } set.remove(""); return set; }
From source file:com.bosscs.spark.commons.entity.Cells.java
/** * Builds a new Cells object containing the provided cells belonging to <i>table</i>. Sets the provided table name * as the default table.// w w w. j a v a2 s .c o m * * @param cells the array of Cells we want to use to create the Cells object. */ public Cells(String nameSpace, Cell... cells) { this.nameSpace = nameSpace; if (StringUtils.isEmpty(nameSpace)) { throw new IllegalArgumentException("table name cannot be null"); } Collections.addAll(getCellsByTable(nameSpace), cells); }
From source file:com.htmlhifive.pitalium.core.config.PtlTestConfig.java
/** * {@link PtlConfigurationProperty}????????? * //from w w w.j av a 2 s .c o m * @param object ? * @param arguments ? */ private static void fillConfigProperties(Object object, Map<String, String> arguments) { // Collect all fields include super classes Class clss = object.getClass(); List<Field> fields = new ArrayList<Field>(); Collections.addAll(fields, clss.getDeclaredFields()); while ((clss = clss.getSuperclass()) != Object.class) { Collections.addAll(fields, clss.getDeclaredFields()); } for (Field field : fields) { PtlConfigurationProperty propertyConfig = field.getAnnotation(PtlConfigurationProperty.class); if (propertyConfig == null) { PtlConfiguration config = field.getAnnotation(PtlConfiguration.class); if (config == null) { continue; } // Field is nested config class try { field.setAccessible(true); Object prop = field.get(object); if (prop != null) { fillConfigProperties(prop, arguments); } } catch (TestRuntimeException e) { throw e; } catch (Exception e) { throw new TestRuntimeException(e); } continue; } String value = arguments.get(propertyConfig.value()); if (value == null) { continue; } try { Object applyValue = convertFromString(field.getType(), value); field.setAccessible(true); field.set(object, applyValue); LOG.trace("[Load config] override property ({}). [{} => {}]", clss.getSimpleName(), field.getName(), applyValue); } catch (TestRuntimeException e) { throw e; } catch (Exception e) { throw new TestRuntimeException("ConfigurationProperty convert error", e); } } }
From source file:com.skelril.ShivtrAuth.AuthenticationCore.java
public synchronized JSONArray getFrom(String subAddress) { JSONArray objective = new JSONArray(); HttpURLConnection connection = null; BufferedReader reader = null; try {//from w w w . j a v a2 s .c o m JSONParser parser = new JSONParser(); for (int i = 1; true; i++) { try { // Establish the connection URL url = new URL(websiteURL + subAddress + "?page=" + i); connection = (HttpURLConnection) url.openConnection(); connection.setConnectTimeout(1500); connection.setReadTimeout(1500); // Check response codes return if invalid if (connection.getResponseCode() < 200 || connection.getResponseCode() >= 300) return null; // Begin to read results reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); StringBuilder builder = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { builder.append(line); } // Parse Data JSONObject o = (JSONObject) parser.parse(builder.toString()); JSONArray ao = (JSONArray) o.get("characters"); if (ao.isEmpty()) break; Collections.addAll(objective, (JSONObject[]) ao.toArray(new JSONObject[ao.size()])); } catch (ParseException e) { break; } finally { if (connection != null) connection.disconnect(); if (reader != null) { try { reader.close(); } catch (IOException ignored) { } } } } } catch (IOException e) { return null; } return objective; }
From source file:de.kaiserpfalzEdv.office.core.license.impl.LicenseBuilder.java
private Set<String> getModulesFromLicense(final License license) { HashSet<String> result = new HashSet<>(10); String modules = license.getFeature(LICENSE_FEATURES); try {// www .jav a2 s. c o m Collections.addAll(result, modules.split(",")); } catch (NullPointerException e) { // OK, there are no modules in there ... } return result; }
From source file:edu.ku.brc.af.ui.forms.validation.ValComboBox.java
/** * Constructor.//from w w w .j av a 2 s . co m * @param array object array of items */ public ValComboBox(final Object[] array, final boolean editable) { if (editable) { ArrayList<Object> items = new ArrayList<Object>(); Collections.addAll(items, array); comboBox = new Java2sAutoComboBox(items); } else { comboBox = new ClearableComboBox(array); setControlSize(comboBox); } init(editable); }