List of usage examples for java.util Collection toArray
Object[] toArray();
From source file:gov.pnnl.goss.gridappsd.GridAppsDataSourcesComponentTests.java
@Test /**/*from w ww .j av a 2 s . co m*/ * Succeeds when the proper number of properties are set on the updated call, and datasourcebuilder.create is called, and the correct registered datasource name is added */ public void registryKeysExistWhen_dataSourcesStarted() { ArgumentCaptor<String> argCaptor = ArgumentCaptor.forClass(String.class); try { //When datasourceBuilder.create is called add a face datasource object to the datasourceRegistry (similar to what the actual implementation would do) Answer answer = new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); String dsName = args[0].toString(); datasourceRegistry.add(dsName, datasourceObject); return null; } }; Mockito.doAnswer(answer).when(datasourceBuilder).create(argCaptor.capture(), Mockito.any()); } catch (Exception e) { e.printStackTrace(); } Properties datasourceProperties = new Properties(); GridAppsDataSourcesImpl dataSources = new GridAppsDataSourcesImpl(logger, datasourceBuilder, datasourceRegistry, datasourceProperties); Hashtable<String, String> props = new Hashtable<String, String>(); String datasourceName = "pnnl.goss.sql.datasource.gridappsd"; props.put("name", datasourceName); props.put(DataSourceBuilder.DATASOURCE_USER, "gridappsduser"); props.put(DataSourceBuilder.DATASOURCE_PASSWORD, "gridappsdpw"); props.put(DataSourceBuilder.DATASOURCE_URL, "mysql://lalala"); props.put("driver", "com.mysql.jdbc.Driver"); dataSources.updated(props); assertEquals(5, datasourceProperties.size()); dataSources.start(); //verify datasourceBuilder.create(datasourceName, datasourceProperties); try { Mockito.verify(datasourceBuilder).create(argCaptor.capture(), Mockito.any()); assertEquals(datasourceName, argCaptor.getValue()); } catch (ClassNotFoundException e) { e.printStackTrace(); assert (false); } catch (Exception e) { e.printStackTrace(); assert (false); } //verify registeredDatasources.add(datasourceName); List<String> registeredDatasources = dataSources.getRegisteredDatasources(); assertEquals(1, registeredDatasources.size()); // test get data source keys Collection<String> dsKeys = dataSources.getDataSourceKeys(); assertEquals(datasourceName, dsKeys.toArray()[0]); // test get data source by key DataSourcePooledJdbc obj = dataSources.getDataSourceByKey(datasourceName); assertEquals(datasourceObject, obj); // test get connection by key dataSources.getConnectionByKey(datasourceName); try { Mockito.verify(datasourceObject).getConnection(); } catch (SQLException e) { e.printStackTrace(); } //verify datasourceregistry size assertEquals(1, datasourceRegistry.getAvailable().size()); }
From source file:org.beanfuse.persist.hibernate.EntityDaoHibernate.java
public boolean remove(Class entityClass, String attr, Collection values) { return remove(entityClass, attr, values.toArray()); }
From source file:org.springmodules.validation.valang.predicates.BasicValidationRule.java
public void validate(Object target, Errors errors) { Object tmpTarget;// w ww. j a v a 2 s. com if (target instanceof BeanWrapper || target instanceof Map) { tmpTarget = target; } else { tmpTarget = new BeanWrapperImpl(target); } if (!getPredicate().evaluate(tmpTarget)) { /* * Take into account error key and error args for localization */ if (StringUtils.hasLength(getErrorKey())) { if (getErrorArgs() != null && !getErrorArgs().isEmpty()) { Collection tmpColl = new ArrayList(); for (Iterator iter = getErrorArgs().iterator(); iter.hasNext();) { tmpColl.add(((Function) iter.next()).getResult(tmpTarget)); } errors.rejectValue(getField(), getErrorKey(), tmpColl.toArray(), getErrorMessage()); } else { errors.rejectValue(getField(), getErrorKey(), getErrorMessage()); } } else { errors.rejectValue(getField(), getField(), getErrorMessage()); } } }
From source file:com.nextep.designer.vcs.ui.jface.VersionableContentProvider.java
@Override public Object[] getChildren(Object parentElement) { if (parentElement instanceof VersionNavigatorRoot) { final VersionNavigatorRoot root = (VersionNavigatorRoot) parentElement; final Collection<?> contents = root.getContents(); // Registering all objects so that we'll keep track of their lifecycle for (Object o : contents) { registerObject(o);/*from ww w . j av a 2s .c om*/ } return contents.toArray(); } else if (parentElement instanceof IVersionContainer) { final IVersionContainer parent = (IVersionContainer) parentElement; // Registering controller as model listener (backward compatibility as the controller is // responsible for executing save events on specific events). for (IVersionable<?> v : new ArrayList<IVersionable<?>>(parent.getContents())) { registerObject(v); } return TypedNode.buildNodesFromCollection(parent, parent.getContents(), this).toArray(); } else if (parentElement instanceof ITypedNode) { return ((ITypedNode) parentElement).getChildren().toArray(); } return null; }
From source file:org.seamless_ip.services.dao.test.ProjectDaoTest.java
@SuppressWarnings("unchecked") @Test/* w ww. j ava2 s .c om*/ public void updateProjectTitleAndSpatialScaleTest() { Collection<EnumTO> spatialScales = enumDao.findAll(SpatialScale.class.getName()); // get the test user UserTO user = userDao.findByAccountNameAndPassword("testuser", "sselmaes"); // create a new project ProjectTO newProject = new ProjectTO(); SpatialScaleTO scale = (SpatialScaleTO) spatialScales.toArray()[0]; newProject.getProblem().setSpatialScale(scale); newProject.setTitle("Project with spatial scale " + scale.getLabel() + " created by UnitTest"); // save new project newProject = projectDao.save(user.getId(), newProject); System.out.println("Saved project '" + newProject.getTitle() + "' with id: " + newProject.getId()); // update project with other spatial scale scale = (SpatialScaleTO) spatialScales.toArray()[1]; newProject.setTitle("Project with spatial scale " + scale.getLabel() + " created by UnitTest"); newProject.getProblem().setSpatialScale(scale); newProject = projectDao.update(user.getId(), newProject, null); System.out.println("Updated project '" + newProject.getTitle() + "' with id: " + newProject.getId()); // remove test project projectDao.remove(user.getId(), newProject.getId()); System.out.println("Removed project '" + newProject.getTitle() + "' with id: " + newProject.getId()); }
From source file:com.nortal.petit.orm.StatementSupport.java
/** * Creates insert statement by beans//from ww w . jav a 2 s . co m * * @param beans * Beans to insert * @return {@link InsertStatement} */ public <B> InsertStatement<B> insertStm(Collection<B> beans) { return new InsertStatement<B>(getJdbcTemplate(), getStatementBuilder(), (B[]) beans.toArray()); }
From source file:com.nortal.petit.orm.StatementSupport.java
/** * Creates update statement by beans//w ww. j a v a 2 s .com * * @param beans * Beans to update * @return {@link UpdateStatement} */ public <B> UpdateStatement<B> updateStm(Collection<B> beans) { return new UpdateStatement<B>(getJdbcTemplate(), getStatementBuilder(), (B[]) beans.toArray()); }
From source file:com.nortal.petit.orm.StatementSupport.java
/** * Creates delete statement by beans * /*from w w w .j ava 2 s . c om*/ * @param beans * Beans to delete * @return {@link DeleteStatement} */ public <B> DeleteStatement<B> deleteStm(Collection<B> beans) { return new DeleteStatement<B>(getJdbcTemplate(), getStatementBuilder(), (B[]) beans.toArray()); }
From source file:de.kp.ames.web.function.map.MapDQM.java
/** * Create (Geo) Point representation of a registry object * /* w w w.j a v a2 s . c om*/ * @param ro * @return * @throws Exception */ private JSONObject getJPoint(RegistryObjectImpl ro) throws Exception { String lat = null; String lon = null; SlotImpl slot = null; Collection<?> values; /* * Latitude */ slot = (SlotImpl) ro.getSlot(JaxrConstants.SLOT_LATITUDE); if (slot != null) { values = slot.getValues(); lat = (String) values.toArray()[0]; } /* * Longitude */ slot = (SlotImpl) ro.getSlot(JaxrConstants.SLOT_LONGITUDE); if (slot != null) { values = slot.getValues(); lon = (String) values.toArray()[0]; } if ((lat == null) || (lon == null)) return null; /* * Create JSON representation of point */ JSONObject jPoint = new JSONObject(); jPoint.put(JsonConstants.J_ID, ro.getId()); jPoint.put(JsonConstants.J_LAT, lat); jPoint.put(JsonConstants.J_LON, lon); return jPoint; }
From source file:de.kp.ames.web.function.domain.model.JsonAccessor.java
/** * A helper method to retrieve the transformators * from a service object/*from w ww . j av a 2 s. c om*/ * * @param service * @return * @throws JAXRException * @throws JSONException */ private JSONArray getSpecifications(ServiceImpl service) throws JAXRException, JSONException { Map<Integer, JSONObject> collector = new TreeMap<Integer, JSONObject>(new Comparator<Integer>() { public int compare(Integer seqno1, Integer seqno2) { return seqno1.compareTo(seqno2); } }); /* * Specifications */ Collection<?> bindings = service.getServiceBindings(); if ((bindings == null) || (bindings.size() == 0)) return new JSONArray(); /* * Take the first binding of the respective service into account */ ServiceBindingImpl binding = (ServiceBindingImpl) bindings.toArray()[0]; /* * Next the specification links of the respective binding are determined */ Collection<?> specs = binding.getSpecificationLinks(); if ((specs == null) || (specs.size() == 0)) return new JSONArray(); Iterator<?> iterator = specs.iterator(); while (iterator.hasNext()) { SpecificationLinkImpl spec = (SpecificationLinkImpl) iterator.next(); Object[] values = spec.getSlot(JaxrConstants.SLOT_SEQNO).getValues().toArray(); int seqNo = Integer.parseInt((String) values[0]); RegistryObjectImpl ro = (RegistryObjectImpl) spec.getSpecificationObject(); JSONObject jTransformator = new JSONObject(); jTransformator.put(JaxrConstants.RIM_ID, ro.getId()); String name = jaxrBase.getName(ro); /* * If no matching locale string exists, get the closest match */ name = (name == "") ? ro.getDisplayName() : name; jTransformator.put(JaxrConstants.RIM_NAME, name); collector.put(seqNo, jTransformator); } return new JSONArray(collector.values()); }