List of usage examples for java.util Vector isEmpty
public synchronized boolean isEmpty()
From source file:edu.umn.cs.spatialHadoop.nasa.SpatioAggregateQueries.java
/** * Performs a spatio-temporal aggregate query on an indexed directory * @param inFile/* w w w.j av a 2s . c o m*/ * @param params * @throws ParseException * @throws IOException * @throws InterruptedException */ public static AggregateQuadTree.Node aggregateQuery(Path inFile, OperationsParams params) throws ParseException, IOException, InterruptedException { // 1- Find matching temporal partitions final FileSystem fs = inFile.getFileSystem(params); Vector<Path> matchingPartitions = selectTemporalPartitions(inFile, params); // 2- Find all matching files (AggregateQuadTrees) in matching partitions final Rectangle spatialRange = params.getShape("rect", new Rectangle()).getMBR(); // Convert spatialRange from lat/lng space to Sinusoidal space double cosPhiRad = Math.cos(spatialRange.y1 * Math.PI / 180); double southWest = spatialRange.x1 * cosPhiRad; double southEast = spatialRange.x2 * cosPhiRad; cosPhiRad = Math.cos(spatialRange.y2 * Math.PI / 180); double northWest = spatialRange.x1 * cosPhiRad; double northEast = spatialRange.x2 * cosPhiRad; spatialRange.x1 = Math.min(northWest, southWest); spatialRange.x2 = Math.max(northEast, southEast); // Convert to the h v space used by MODIS spatialRange.x1 = (spatialRange.x1 + 180.0) / 10.0; spatialRange.x2 = (spatialRange.x2 + 180.0) / 10.0; spatialRange.y2 = (90.0 - spatialRange.y2) / 10.0; spatialRange.y1 = (90.0 - spatialRange.y1) / 10.0; // Vertically flip because the Sinusoidal space increases to the south double tmp = spatialRange.y2; spatialRange.y2 = spatialRange.y1; spatialRange.y1 = tmp; // Find the range of cells in MODIS Sinusoidal grid overlapping the range final int h1 = (int) Math.floor(spatialRange.x1); final int h2 = (int) Math.ceil(spatialRange.x2); final int v1 = (int) Math.floor(spatialRange.y1); final int v2 = (int) Math.ceil(spatialRange.y2); PathFilter rangeFilter = new PathFilter() { @Override public boolean accept(Path p) { Matcher matcher = MODISTileID.matcher(p.getName()); if (!matcher.matches()) return false; int h = Integer.parseInt(matcher.group(1)); int v = Integer.parseInt(matcher.group(2)); return h >= h1 && h < h2 && v >= v1 && v < v2; } }; final Vector<Path> allMatchingFiles = new Vector<Path>(); for (Path matchingPartition : matchingPartitions) { // Select all matching files FileStatus[] matchingFiles = fs.listStatus(matchingPartition, rangeFilter); for (FileStatus matchingFile : matchingFiles) { allMatchingFiles.add(matchingFile.getPath()); } } //noinspection SizeReplaceableByIsEmpty if (allMatchingFiles.isEmpty()) return null; final int resolution = AggregateQuadTree.getResolution(fs, allMatchingFiles.get(0)); // 3- Query all matching files in parallel List<Node> threadsResults = Parallel.forEach(allMatchingFiles.size(), new RunnableRange<AggregateQuadTree.Node>() { @Override public Node run(int i1, int i2) { Node threadResult = new AggregateQuadTree.Node(); for (int i_file = i1; i_file < i2; i_file++) { Path matchingFile = allMatchingFiles.get(i_file); try { Matcher matcher = MODISTileID.matcher(matchingFile.getName()); matcher.matches(); // It has to match int h = Integer.parseInt(matcher.group(1)); int v = Integer.parseInt(matcher.group(2)); // Clip the query region and normalize in this tile Rectangle translated = spatialRange.translate(-h, -v); int x1 = (int) (Math.max(translated.x1, 0) * resolution); int y1 = (int) (Math.max(translated.y1, 0) * resolution); int x2 = (int) (Math.min(translated.x2, 1.0) * resolution); int y2 = (int) (Math.min(translated.y2, 1.0) * resolution); AggregateQuadTree.Node fileResult = AggregateQuadTree.aggregateQuery(fs, matchingFile, new java.awt.Rectangle(x1, y1, (x2 - x1), (y2 - y1))); threadResult.accumulate(fileResult); } catch (Exception e) { throw new RuntimeException("Error reading file " + matchingFile, e); } } return threadResult; } }); AggregateQuadTree.Node finalResult = new AggregateQuadTree.Node(); for (Node threadResult : threadsResults) { finalResult.accumulate(threadResult); } numOfTreesTouchesInLastRequest = allMatchingFiles.size(); return finalResult; }
From source file:com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.java
/** * Checks if the XML-RPC response is an GreenPepper server Exception. * If so an GreenPepperServerException will be thrown with the error id found. * </p>/*from ww w .j a va2s .c o m*/ * * @param xmlRpcResponse a {@link java.lang.Object} object. * @throws com.greenpepper.server.GreenPepperServerException if any. */ public static void checkForErrors(Object xmlRpcResponse) throws GreenPepperServerException { if (xmlRpcResponse instanceof Vector) { Vector temp = (Vector) xmlRpcResponse; if (!temp.isEmpty()) { checkErrors(temp.elementAt(0)); } } else if (xmlRpcResponse instanceof Hashtable) { Hashtable table = (Hashtable) xmlRpcResponse; if (!table.isEmpty()) { checkForErrors(table.get(GreenPepperServerErrorKey.ERROR)); } } else { checkErrors(xmlRpcResponse); } }
From source file:com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.java
/** * Transforms the Vector of the Project parameters into a Project Object.<br> * Structure of the parameters:<br> * Vector[name]/*from w ww.java2s . c o m*/ * </p> * * @param xmlRpcParameters a {@link java.util.Vector} object. * @return the Project. */ public static Project toProject(Vector<Object> xmlRpcParameters) { Project project = null; if (!xmlRpcParameters.isEmpty()) { project = Project.newInstance((String) xmlRpcParameters.get(PROJECT_NAME_IDX)); } return project; }
From source file:com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.java
/** * Transforms the Vector of the EnvironmentType parameters into a EnvironmentType Object.<br> * </p>/*from ww w . j a v a 2 s. co m*/ * * @param xmlRpcParameters a {@link java.util.Vector} object. * @return the EnvironmentType. */ public static EnvironmentType toEnvironmentType(Vector<Object> xmlRpcParameters) { EnvironmentType type = null; if (!xmlRpcParameters.isEmpty()) type = EnvironmentType.newInstance((String) xmlRpcParameters.get(ENVTYPE_NAME_IDX)); return type; }
From source file:com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.java
/** * Transforms the Vector of the Runner parameters into a Runner Object.<br> * </p>/*from w ww . j a va 2s .co m*/ * * @param xmlRpcParameters Runner['name','cmd',['envtypename'],'servername','serverport','mainclass',['cp1','cp2'],'secured'] * @return the Runner. */ @SuppressWarnings("unchecked") public static Runner toRunner(Vector<Object> xmlRpcParameters) { Runner runner = null; if (!xmlRpcParameters.isEmpty()) { runner = Runner.newInstance((String) getParameter(RUNNER_NAME_IDX, xmlRpcParameters)); runner.setCmdLineTemplate(toNullIfEmpty((String) getParameter(RUNNER_CMDLINE_IDX, xmlRpcParameters))); runner.setEnvironmentType( toEnvironmentType((Vector) getParameter(RUNNER_ENVTYPE_IDX, xmlRpcParameters))); runner.setServerName(toNullIfEmpty((String) getParameter(RUNNER_SERVER_NAME_IDX, xmlRpcParameters))); runner.setServerPort(toNullIfEmpty((String) getParameter(RUNNER_SERVER_PORT_IDX, xmlRpcParameters))); runner.setMainClass(toNullIfEmpty((String) getParameter(RUNNER_MAINCLASS_IDX, xmlRpcParameters))); ClasspathSet classpaths = new ClasspathSet( (Vector) getParameter(RUNNER_CLASSPATH_IDX, xmlRpcParameters)); runner.setClasspaths(classpaths); runner.setSecured((Boolean) getParameter(RUNNER_SECURED_IDX, xmlRpcParameters)); } return runner; }
From source file:com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.java
/** * Transforms the Vector of the Requirement parameters into a Requirement Object.<br> * Structure of the parameters:<br> * Vector[name, Vector[repository parameters]] * </p>/*from w w w . jav a 2 s . co m*/ * * @param xmlRpcParameters a {@link java.util.Vector} object. * @return the Requirement. */ @SuppressWarnings("unchecked") public static Requirement toRequirement(Vector<Object> xmlRpcParameters) { Requirement requirement = null; if (!xmlRpcParameters.isEmpty()) { String name = (String) xmlRpcParameters.get(DOCUMENT_NAME_IDX); requirement = Requirement.newInstance(name); requirement.setRepository(toRepository((Vector<Object>) xmlRpcParameters.get(DOCUMENT_REPOSITORY_IDX))); } return requirement; }
From source file:com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.java
/** * Transforms the Vector of the Reference parameters into a Reference Object.<br> * * @param xmlRpcParameters a {@link java.util.Vector} object. * @return the Reference./*from w ww . j av a2 s .c o m*/ */ @SuppressWarnings("unchecked") public static Reference toReference(Vector<Object> xmlRpcParameters) { Reference reference = null; if (!xmlRpcParameters.isEmpty()) { Requirement requirement = toRequirement( (Vector<Object>) xmlRpcParameters.get(REFERENCE_REQUIREMENT_IDX)); Specification specification = toSpecification( (Vector<Object>) xmlRpcParameters.get(REFERENCE_SPECIFICATION_IDX)); SystemUnderTest sut = toSystemUnderTest((Vector<Object>) xmlRpcParameters.get(REFERENCE_SUT_IDX)); String sections = toNullIfEmpty((String) xmlRpcParameters.get(REFERENCE_SECTIONS_IDX)); reference = Reference.newInstance(requirement, specification, sut, sections); Execution exe = toExecution((Vector<Object>) xmlRpcParameters.get(REFERENCE_LAST_EXECUTION_IDX)); reference.setLastExecution(exe); } return reference; }
From source file:com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.java
/** * Transforms the Vector of the Repository parameters into a Repository Object.<br> * Structure of the parameters:<br> * Vector[name, Vector[project parameters], type, content type, uri] * </p>/*w w w .jav a 2s . c o m*/ * * @param xmlRpcParameters Vector[name, Vector[project parameters], type, content type, uri] * @return the Repository. */ @SuppressWarnings("unchecked") public static Repository toRepository(Vector<Object> xmlRpcParameters) { Repository repository = null; if (!xmlRpcParameters.isEmpty()) { repository = Repository.newInstance((String) xmlRpcParameters.get(REPOSITORY_UID_IDX)); repository.setName((String) xmlRpcParameters.get(REPOSITORY_NAME_IDX)); repository.setProject(toProject((Vector) xmlRpcParameters.get(REPOSITORY_PROJECT_IDX))); repository.setType(toRepositoryType((Vector) xmlRpcParameters.get(REPOSITORY_TYPE_IDX))); repository.setContentType( ContentType.getInstance((String) xmlRpcParameters.get(REPOSITORY_CONTENTTYPE_IDX))); repository.setBaseUrl((String) xmlRpcParameters.get(REPOSITORY_BASE_URL_IDX)); repository.setBaseRepositoryUrl((String) xmlRpcParameters.get(REPOSITORY_BASEREPO_URL_IDX)); repository.setBaseTestUrl((String) xmlRpcParameters.get(REPOSITORY_BASETEST_URL_IDX)); repository.setUsername(toNullIfEmpty((String) xmlRpcParameters.get(REPOSITORY_USERNAME_IDX))); repository.setPassword(toNullIfEmpty((String) xmlRpcParameters.get(REPOSITORY_PASSWORD_IDX))); repository.setMaxUsers((Integer) xmlRpcParameters.get(REPOSITORY_MAX_USERS_IDX)); } return repository; }
From source file:com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.java
/** * Transforms the Vector of the SystemUnderTest parameters into a SystemUnderTest Object.<br> * Structure of the parameters:<br> * Vector[name, Vector[project parameters], Vector[seeds classPaths], Vector[fixture classPaths], fixturefactory, fixturefactoryargs, isdefault, Runner['name','cmd',['envtypename'],'servername','serverport','mainclass',['cp1','cp2'],'secured'], projectdependencydescriptor] * </p>/*from w ww .ja v a2 s. c o m*/ * * @param xmlRpcParameters a {@link java.util.Vector} object. * @return the SystemUnderTest. */ @SuppressWarnings("unchecked") public static SystemUnderTest toSystemUnderTest(Vector<Object> xmlRpcParameters) { SystemUnderTest sut = null; if (!xmlRpcParameters.isEmpty()) { ClasspathSet sutClasspaths = new ClasspathSet((Vector) xmlRpcParameters.get(SUT_CLASSPATH_IDX)); ClasspathSet fixtureClasspaths = new ClasspathSet( (Vector) xmlRpcParameters.get(SUT_FIXTURE_CLASSPATH_IDX)); sut = SystemUnderTest.newInstance((String) xmlRpcParameters.get(SUT_NAME_IDX)); sut.setProject(toProject((Vector<Object>) xmlRpcParameters.get(SUT_PROJECT_IDX))); sut.setSutClasspaths(sutClasspaths); sut.setFixtureClasspaths(fixtureClasspaths); sut.setFixtureFactory(toNullIfEmpty((String) xmlRpcParameters.get(SUT_FIXTURE_FACTORY_IDX))); sut.setFixtureFactoryArgs(toNullIfEmpty((String) xmlRpcParameters.get(SUT_FIXTURE_FACTORY_ARGS_IDX))); sut.setIsDefault((Boolean) xmlRpcParameters.get(SUT_IS_DEFAULT_IDX)); sut.setRunner(toRunner((Vector<Object>) xmlRpcParameters.get(SUT_RUNNER_IDX))); sut.setProjectDependencyDescriptor( toNullIfEmpty((String) xmlRpcParameters.get(SUT_PROJECT_DEPENDENCY_DESCRIPTOR_IDX))); } return sut; }
From source file:com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.java
/** * Transforms the Vector of the Specification parameters into a Specification Object.<br> * Structure of the parameters:<br> * Vector[name, Vector[repository parameters], Vector[SUT parameters]] * </p>/*from w ww . ja v a 2s . com*/ * * @param xmlRpcParameters a {@link java.util.Vector} object. * @return the Specification. */ @SuppressWarnings("unchecked") public static Specification toSpecification(Vector<Object> xmlRpcParameters) { Specification specification = null; if (!xmlRpcParameters.isEmpty()) { specification = Specification.newInstance((String) xmlRpcParameters.get(DOCUMENT_NAME_IDX)); specification .setRepository(toRepository((Vector<Object>) xmlRpcParameters.get(DOCUMENT_REPOSITORY_IDX))); specification.setTargetedSystemUnderTests( toSystemUnderTestList((Vector<Object>) xmlRpcParameters.get(SPECIFICATION_SUTS_IDX))); if (xmlRpcParameters.size() >= 4) { specification.setDialectClass((String) xmlRpcParameters.get(SPECIFICATION_DIALECT_IDX)); } } return specification; }