List of usage examples for java.util Set toArray
<T> T[] toArray(T[] a);
From source file:hoot.services.osm.OsmTestUtils.java
public static void verifyTestWaysUnmodified(final Set<Long> wayIds, final Set<Long> nodeIds, final long changesetId, final boolean verifyTags) { QCurrentWays currentWays = QCurrentWays.currentWays; final Long[] nodeIdsArr = nodeIds.toArray(new Long[] {}); final Long[] wayIdsArr = wayIds.toArray(new Long[] {}); try {//from w ww . j a va 2 s .com final Map<Long, CurrentWays> ways = new SQLQuery(conn, DbUtils.getConfiguration(mapId)) .from(currentWays).where((currentWays.changesetId.eq(changesetId))) .map(currentWays.id, currentWays) ; Assert.assertEquals(3, ways.size()); QCurrentWayNodes currentWayNodes = QCurrentWayNodes.currentWayNodes; CurrentWays wayRecord = (CurrentWays) ways.get(wayIdsArr[0]); Assert.assertEquals(new Long(changesetId), wayRecord.getChangesetId()); Assert.assertEquals(wayIdsArr[0], wayRecord.getId()); Assert.assertEquals(new Long(1), wayRecord.getVersion()); List<CurrentWayNodes> wayNodes = new SQLQuery(conn, DbUtils.getConfiguration(mapId)) .from(currentWayNodes).where(currentWayNodes.wayId.eq(wayIdsArr[0])) .orderBy(currentWayNodes.sequenceId.asc()).list(currentWayNodes); Assert.assertEquals(3, wayNodes.size()); CurrentWayNodes wayNode = wayNodes.get(0); Assert.assertEquals(nodeIdsArr[0], wayNode.getNodeId()); Assert.assertEquals(new Long(1), wayNode.getSequenceId()); Assert.assertEquals(wayRecord.getId(), wayNode.getWayId()); wayNode = wayNodes.get(1); Assert.assertEquals(nodeIdsArr[1], wayNode.getNodeId()); Assert.assertEquals(new Long(2), wayNode.getSequenceId()); Assert.assertEquals(wayRecord.getId(), wayNode.getWayId()); wayNode = wayNodes.get(2); Assert.assertEquals(nodeIdsArr[4], wayNode.getNodeId()); Assert.assertEquals(new Long(3), wayNode.getSequenceId()); Assert.assertEquals(wayRecord.getId(), wayNode.getWayId()); if (verifyTags) { try { Map<String, String> tags = PostgresUtils.postgresObjToHStore((PGobject) wayRecord.getTags()); Assert.assertEquals(2, tags.size()); Assert.assertEquals("val 1", tags.get("key 1")); Assert.assertEquals("val 2", tags.get("key 2")); } catch (Exception e) { Assert.fail("Error checking way tags: " + e.getMessage()); } } wayRecord = (CurrentWays) ways.get(wayIdsArr[1]); Assert.assertEquals(new Long(changesetId), wayRecord.getChangesetId()); Assert.assertEquals(wayIdsArr[1], wayRecord.getId()); Assert.assertEquals(new Long(1), wayRecord.getVersion()); wayNodes = new SQLQuery(conn, DbUtils.getConfiguration(mapId)).from(currentWayNodes) .where(currentWayNodes.wayId.eq(wayIdsArr[1])).orderBy(currentWayNodes.sequenceId.asc()) .list(currentWayNodes) ; Assert.assertEquals(2, wayNodes.size()); wayNode = wayNodes.get(0); Assert.assertEquals(nodeIdsArr[2], wayNode.getNodeId()); Assert.assertEquals(new Long(1), wayNode.getSequenceId()); Assert.assertEquals(wayRecord.getId(), wayNode.getWayId()); wayNode = wayNodes.get(1); Assert.assertEquals(nodeIdsArr[1], wayNode.getNodeId()); Assert.assertEquals(new Long(2), wayNode.getSequenceId()); Assert.assertEquals(wayRecord.getId(), wayNode.getWayId()); if (verifyTags) { try { Assert.assertTrue(wayRecord.getTags() == null || StringUtils.isEmpty(((PGobject) wayRecord.getTags()).getValue())); } catch (Exception e) { Assert.fail("Error checking way tags: " + e.getMessage()); } } wayRecord = (CurrentWays) ways.get(wayIdsArr[2]); Assert.assertEquals(new Long(changesetId), wayRecord.getChangesetId()); Assert.assertEquals(wayIdsArr[2], wayRecord.getId()); Assert.assertEquals(new Long(1), wayRecord.getVersion()); wayNodes = new SQLQuery(conn, DbUtils.getConfiguration(mapId)).from(currentWayNodes) .where(currentWayNodes.wayId.eq(wayIdsArr[2])).orderBy(currentWayNodes.sequenceId.asc()) .list(currentWayNodes); Assert.assertEquals(2, wayNodes.size()); wayNode = wayNodes.get(0); Assert.assertEquals(nodeIdsArr[0], wayNode.getNodeId()); Assert.assertEquals(new Long(1), wayNode.getSequenceId()); Assert.assertEquals(wayRecord.getId(), wayNode.getWayId()); wayNode = wayNodes.get(1); Assert.assertEquals(nodeIdsArr[1], wayNode.getNodeId()); Assert.assertEquals(new Long(2), wayNode.getSequenceId()); Assert.assertEquals(wayRecord.getId(), wayNode.getWayId()); if (verifyTags) { try { Map<String, String> tags = PostgresUtils.postgresObjToHStore((PGobject) wayRecord.getTags()); Assert.assertEquals(1, tags.size()); Assert.assertEquals("val 3", tags.get("key 3")); } catch (Exception e) { Assert.fail("Error checking way tags: " + e.getMessage()); } } } catch (Exception e) { Assert.fail("Error checking ways: " + e.getMessage()); } }
From source file:org.apache.servicemix.jbi.deployer.impl.DeploymentService.java
public String[] getDeployedServiceAssemblies() throws Exception { Set<String> sas = deployer.getServiceAssemblies().keySet(); return sas.toArray(new String[sas.size()]); }
From source file:com.googlecode.arit.jmx.LeakDetector.java
@ManagedAttribute(description = "The list of all module names monitored by the leak detector") public String[] getModuleNames() { Set<String> moduleNames = new HashSet<String>(); for (Module module : lastReport.get().getRootModules()) { moduleNames.add(module.getName()); }//from www .j av a 2s . c o m return moduleNames.toArray(new String[moduleNames.size()]); }
From source file:de.vandermeer.skb.datatool.commons.DataSet.java
/** * Returns the path common to all files in the given file list. * The rest (after this common path) will be used for auto-key-generation * @param fsl list of data files/*from w w w.ja v a2 s .co m*/ * @return common path of all files in the list */ String calcCommonPath(List<FileSource> fsl) { //get shortest absolute path, everything else is part of the key Set<String> paths = new HashSet<>(); for (FileSource fs : fsl) { paths.add(fs.getAbsolutePath()); } String ret = StringUtils.getCommonPrefix(paths.toArray(new String[] {})); if (ret.endsWith(File.separator)) { ret = StringUtils.substringBeforeLast(ret, File.separator); } return ret; }
From source file:org.commonjava.aprox.depgraph.rest.ProjectController.java
public String relationshipsTargeting(final String groupId, final String artifactId, final String version, final String workspaceId, final Map<String, String[]> filterParams) throws AproxWorkflowException { final ProjectRelationshipFilter filter = requestAdvisor.createRelationshipFilter(filterParams, presetParamParser.parse(filterParams)); final ProjectVersionRef ref = new ProjectVersionRef(groupId, artifactId, version); final ViewParams params = new ViewParams(workspaceId, filter, NoOpGraphMutator.INSTANCE, ref); try {//from w w w . j a v a 2s .c om final Set<RelationshipType> types = filter.getAllowedTypes(); final Set<ProjectRelationship<?>> rels = ops.getDirectRelationshipsTo(ref, params, types.toArray(new RelationshipType[types.size()])); return rels == null ? null : serializer.writeValueAsString(new ProjectRelationshipListing(rels)); } catch (final CartoDataException e) { throw new AproxWorkflowException("Failed to lookup relationships specified by: {}:{}:{}. Reason: {}", e, groupId, artifactId, version, e.getMessage()); } catch (final JsonProcessingException e) { throw new AproxWorkflowException("Failed to serialize to JSON: %s", e, e.getMessage()); } }
From source file:com.edgenius.wiki.gwt.server.HelperControllerImpl.java
public boolean sendNotify(String receiver, String text) { SimpleMailMessage msg = new SimpleMailMessage(); msg.setSubject(messageService.getMessage("sent.msg.title")); if (receiver == null) { if (!StringUtils.isBlank(Global.DefaultReceiverMail)) msg.setTo(Global.DefaultReceiverMail); if (Global.ccToSystemAdmin || StringUtils.isBlank(Global.DefaultReceiverMail)) { Set<String> bcc = userReadingService.getSystemAdminMailList(); if (bcc != null && bcc.size() > 0) msg.setBcc(bcc.toArray(new String[bcc.size()])); }//from w w w. ja v a2 s .c o m } else { //TODO: send message to special user - receiver is userID or email address? } msg.setFrom(Global.DefaultNotifyMail); msg.setText(text + "\r\n" + messageService.getMessage("sent.by") + " " + WikiUtil.getUser().getFullname()); mailService.send(msg); return true; }
From source file:eu.openanalytics.rpooli.RPooliContext.java
@Override protected String[] getLibDirPaths() throws RjInvalidConfigurationException { try {/*from ww w. j a v a2 s . c om*/ final URL rjResourceUrl = RPooliContext.class.getClassLoader() .getResource(RJContext.class.getName().replace('.', '/') + ".class"); LOGGER.info("rj resource URL: " + rjResourceUrl); final String rjResourcePath = rjResourceUrl.getPath(); final int indexOfColon = rjResourcePath.indexOf(':'); final int indexOfBang = rjResourcePath.indexOf('!'); final String rjJarsPath = new File(rjResourcePath.substring(indexOfColon + 1, indexOfBang)) .getParentFile().getCanonicalPath(); LOGGER.info("rj JARs path: " + rjJarsPath); final String webInfLibPath = servletContext.getRealPath("WEB-INF/lib"); final Set<String> uniqueLibDirPaths = new HashSet<>(asList(rjJarsPath, webInfLibPath)); LOGGER.info("Collected lib dir paths: " + uniqueLibDirPaths); return uniqueLibDirPaths.toArray(EMPTY_STRING_ARRAY); } catch (final IOException ioe) { throw new RjInvalidConfigurationException("Failed to collect lib dir paths", ioe); } }
From source file:org.commonjava.aprox.depgraph.rest.ProjectController.java
public String relationshipsDeclaredBy(final String groupId, final String artifactId, final String version, final String workspaceId, final Map<String, String[]> filterParams) throws AproxWorkflowException { final ProjectRelationshipFilter filter = requestAdvisor.createRelationshipFilter(filterParams, presetParamParser.parse(filterParams)); final ProjectVersionRef ref = new ProjectVersionRef(groupId, artifactId, version); final ViewParams params = new ViewParams(workspaceId, filter, NoOpGraphMutator.INSTANCE, ref); try {/*from www.j a va 2 s .c om*/ final Set<RelationshipType> types = filter.getAllowedTypes(); final Set<ProjectRelationship<?>> rels = ops.getDirectRelationshipsFrom(ref, params, types.toArray(new RelationshipType[types.size()])); return rels == null ? null : serializer.writeValueAsString(new ProjectRelationshipListing(rels)); } catch (final CartoDataException e) { throw new AproxWorkflowException("Failed to lookup relationships specified by: {}:{}:{}. Reason: {}", e, groupId, artifactId, version, e.getMessage()); } catch (final JsonProcessingException e) { throw new AproxWorkflowException("Failed to serialize to JSON: %s", e, e.getMessage()); } }
From source file:com.espertech.esper.view.window.TimeAccumViewRStream.java
public void update(EventBean[] newData, EventBean[] oldData) { if ((newData != null) && (newData.length > 0)) { // If we have an empty window about to be filled for the first time, add a callback boolean removeSchedule = false; boolean addSchedule = false; long timestamp = agentInstanceContext.getStatementContext().getSchedulingService().getTime(); // if the window is already filled, then we may need to reschedule if (!currentBatch.isEmpty()) { // check if we need to reschedule long callbackTime = timestamp + msecIntervalSize; if (callbackTime != callbackScheduledTime) { removeSchedule = true;/*from w w w .j av a 2 s . com*/ addSchedule = true; } } else { addSchedule = true; } if (removeSchedule) { agentInstanceContext.getStatementContext().getSchedulingService().remove(handle, scheduleSlot); callbackScheduledTime = -1; } if (addSchedule) { agentInstanceContext.getStatementContext().getSchedulingService().add(msecIntervalSize, handle, scheduleSlot); callbackScheduledTime = msecIntervalSize + timestamp; } // add data points to the window for (int i = 0; i < newData.length; i++) { currentBatch.put(newData[i], timestamp); internalHandleAdded(newData[i], timestamp); lastEvent = newData[i]; } } if ((oldData != null) && (oldData.length > 0)) { boolean removedLastEvent = false; for (EventBean anOldData : oldData) { currentBatch.remove(anOldData); internalHandleRemoved(anOldData); if (anOldData == lastEvent) { removedLastEvent = true; } } // we may need to reschedule as the newest event may have been deleted if (currentBatch.size() == 0) { agentInstanceContext.getStatementContext().getSchedulingService().remove(handle, scheduleSlot); callbackScheduledTime = -1; lastEvent = null; } else { // reschedule if the last event was removed if (removedLastEvent) { Set<EventBean> keyset = currentBatch.keySet(); EventBean[] events = keyset.toArray(new EventBean[keyset.size()]); lastEvent = events[events.length - 1]; long lastTimestamp = currentBatch.get(lastEvent); // reschedule, newest event deleted long timestamp = agentInstanceContext.getStatementContext().getSchedulingService().getTime(); long callbackTime = lastTimestamp + msecIntervalSize; long deltaFromNow = callbackTime - timestamp; if (callbackTime != callbackScheduledTime) { agentInstanceContext.getStatementContext().getSchedulingService().remove(handle, scheduleSlot); agentInstanceContext.getStatementContext().getSchedulingService().add(deltaFromNow, handle, scheduleSlot); callbackScheduledTime = callbackTime; } } } } // update child views if (this.hasViews()) { updateChildren(newData, oldData); } }
From source file:edu.utexas.cs.tactex.subscriptionspredictors.LWRCustOldAppache.java
private ArrayRealVector createNormalizedXVector(Set<Double> xValues, double min, double max) { Double[] dummy1 = new Double[1]; // needed to determine the type of toArray? ArrayRealVector xVector = new ArrayRealVector(xValues.toArray(dummy1)); xVector.mapSubtractToSelf(min);//from ww w . j a va2 s .co m xVector.mapDivideToSelf(max - min); // translating [0,1]=>[0.1,0.9] xVector.mapMultiplyToSelf(SQUEEZE); xVector.mapAddToSelf(OFFSET); return xVector; }