public Map toExternalFormat(Map attributeValueToObjectMap) { if (attributeValueToObjectMap.isEmpty()) { return attributeValueToObjectMap; } // Turn the values into ranges. Validations have already ensured that // the values are unique and contain no nulls. [Bob Boseko] Assert.isTrue(attributeValueToObjectMap instanceof SortedMap); TreeMap newMap = new Range.RangeTreeMap(); Object previousValue = null; for (Iterator i = attributeValueToObjectMap.keySet().iterator(); i.hasNext(); ) { Object value = i.next(); try { if (previousValue == null) { // Let the default style handle values from negative infinity to // the first value. [Bob Boseko] continue; } // Make one side inclusive and the other exclusive to ensure no // overlaps. [Bob Boseko] newMap.put( new Range(previousValue, true, value, false), attributeValueToObjectMap.get(previousValue)); } finally { previousValue = value; } } newMap.put( new Range(previousValue, true, new Range.PositiveInfinity(), false), attributeValueToObjectMap.get(previousValue)); return newMap; }
public void findEdge(List dirEdgeList) { /** * Check all forward DirectedEdges only. This is still general, because each edge has a forward * DirectedEdge. */ for (Iterator i = dirEdgeList.iterator(); i.hasNext(); ) { DirectedEdge de = (DirectedEdge) i.next(); if (!de.isForward()) continue; checkForRightmostCoordinate(de); } /** * If the rightmost point is a node, we need to identify which of the incident edges is * rightmost. */ Assert.isTrue( minIndex != 0 || minCoord.equals(minDe.getCoordinate()), "inconsistency in rightmost processing"); if (minIndex == 0) { findRightmostEdgeAtNode(); } else { findRightmostEdgeAtVertex(); } /** now check that the extreme side is the R side. If not, use the sym instead. */ orientedDe = minDe; int rightmostSide = getRightmostSide(minDe, minIndex); if (rightmostSide == Position.LEFT) { orientedDe = minDe.getSym(); } }
private void findRightmostEdgeAtVertex() { /** * The rightmost point is an interior vertex, so it has a segment on either side of it. If these * segments are both above or below the rightmost point, we need to determine their relative * orientation to decide which is rightmost. */ Coordinate[] pts = minDe.getEdge().getCoordinates(); Assert.isTrue( minIndex > 0 && minIndex < pts.length, "rightmost point expected to be interior vertex of edge"); Coordinate pPrev = pts[minIndex - 1]; Coordinate pNext = pts[minIndex + 1]; int orientation = CGAlgorithms.computeOrientation(minCoord, pNext, pPrev); boolean usePrev = false; // both segments are below min point if (pPrev.y < minCoord.y && pNext.y < minCoord.y && orientation == CGAlgorithms.COUNTERCLOCKWISE) { usePrev = true; } else if (pPrev.y > minCoord.y && pNext.y > minCoord.y && orientation == CGAlgorithms.CLOCKWISE) { usePrev = true; } // if both segments are on the same side, do nothing - either is safe // to select as a rightmost segment if (usePrev) { minIndex = minIndex - 1; } }
/** * Creates the levels higher than the given level * * @param boundablesOfALevel the level to build on * @param level the level of the Boundables, or -1 if the boundables are item boundables (that is, * below level 0) * @return the root, which may be a ParentNode or a LeafNode */ private AbstractNode createHigherLevels(List boundablesOfALevel, int level) { Assert.isTrue(!boundablesOfALevel.isEmpty()); List parentBoundables = createParentBoundables(boundablesOfALevel, level + 1); if (parentBoundables.size() == 1) { return (AbstractNode) parentBoundables.get(0); } return createHigherLevels(parentBoundables, level + 1); }
public boolean hasWrapper(Class c) { Assert.isTrue(FeatureCollectionWrapper.class.isAssignableFrom(c)); if (c.isInstance(this)) { return true; } return fc instanceof FeatureCollectionWrapper && ((FeatureCollectionWrapper) fc).hasWrapper(c); }
public ViewAttributesFrame(final Layer layer, final PlugInContext context) { this.layerManager = context.getLayerManager(); addInternalFrameListener( new InternalFrameAdapter() { public void internalFrameClosed(InternalFrameEvent e) { // Assume that there are no other views on the model [Jon // Aquino] attributeTab.getModel().dispose(); } }); setResizable(true); setClosable(true); setMaximizable(true); setIconifiable(true); getContentPane().setLayout(new BorderLayout()); attributeTab = new OneLayerAttributeTab( context.getWorkbenchContext(), ((TaskFrameProxy) context.getActiveInternalFrame()).getTaskFrame(), this) .setLayer(layer); addInternalFrameListener( new InternalFrameAdapter() { public void internalFrameOpened(InternalFrameEvent e) { attributeTab.getToolBar().updateEnabledState(); } }); getContentPane().add(attributeTab, BorderLayout.CENTER); setSize(500, 300); updateTitle(attributeTab.getLayer()); context .getLayerManager() .addLayerListener( new LayerListener() { public void layerChanged(LayerEvent e) { if (attributeTab.getLayer() != null) { updateTitle(attributeTab.getLayer()); } // Layer REMOVE [mmichaud 2012-01-05] if (e.getType() == LayerEventType.REMOVED) { if (e.getLayerable() == attributeTab.getLayer()) { attributeTab.getModel().dispose(); context.getLayerManager().removeLayerListener(this); context.getWorkbenchFrame().removeInternalFrame(ViewAttributesFrame.this); dispose(); } } } public void categoryChanged(CategoryEvent e) {} public void featuresChanged(FeatureEvent e) {} }); Assert.isTrue( !(this instanceof CloneableInternalFrame), I18N.get("ui.plugin.ViewAttributesPlugIn.there-can-be-no-other-views-on-the-InfoModels")); }
/** Removes an item from the tree. (Builds the tree, if necessary.) */ protected boolean remove(Object searchBounds, Object item) { build(); if (itemBoundables.isEmpty()) { Assert.isTrue(root.getBounds() == null); } if (getIntersectsOp().intersects(root.getBounds(), searchBounds)) { return remove(searchBounds, root, item); } return false; }
/** @param level -1 to get items */ private void boundablesAtLevel(int level, AbstractNode top, Collection boundables) { Assert.isTrue(level > -2); if (top.getLevel() == level) { boundables.add(top); return; } for (Iterator i = top.getChildBoundables().iterator(); i.hasNext(); ) { Boundable boundable = (Boundable) i.next(); if (boundable instanceof AbstractNode) { boundablesAtLevel(level, (AbstractNode) boundable, boundables); } else { Assert.isTrue(boundable instanceof ItemBoundable); if (level == -1) { boundables.add(boundable); } } } return; }
/** * Maps one Coordinate to another. * * @param c a Coordinate which must be inside one of the triangle keys passed into the constructor * @return the transformed Coordinate */ public Coordinate transform(Coordinate c) { monitor.report(++coordinatesTransformed, -1, "coordinates"); Triangle sourceTriangle = sourceTriangle(c); Assert.isTrue(sourceTriangle != null, "Unable to determine source triangle for " + c); Triangle destTriangle = destTriangle(sourceTriangle); return destTriangle.toEuclideanCoordinate(sourceTriangle.toSimplicialCoordinate(c)); }
private static void verifyAllMappingsMatchParameter( final Set<String> mappings, final Class<?> paramType, final String errorMessagePrefix) { final Set<String> attributeNames = ParserUtils.getAllAttributeNames(paramType); StringBuilder errors = new StringBuilder(); for (String mapping : mappings) { if (!attributeNames.contains(mapping)) { errors.append("\n * ").append(mapping); } } Assert.isTrue( 0 == errors.length(), errorMessagePrefix + errors + listOptions(attributeNames) + "\n"); }
/** * insert an item which is known to be contained in the tree rooted at the given QuadNode root. * Lower levels of the tree will be created if necessary to hold the item. */ private void insertContained(ExitEarlyNode tree, Envelope itemEnv, Object item) { Assert.isTrue(tree.getEnvelope().contains(itemEnv)); /** * Do NOT create a new quad for zero-area envelopes - this would lead to infinite recursion. * Instead, use a heuristic of simply returning the smallest existing quad containing the query */ boolean isZeroX = IntervalSize.isZeroWidth(itemEnv.getMinX(), itemEnv.getMaxX()); boolean isZeroY = IntervalSize.isZeroWidth(itemEnv.getMinY(), itemEnv.getMaxY()); ExitEarlyNodeBase node; if (isZeroX || isZeroY) node = tree.find(itemEnv); else node = tree.getNode(itemEnv); node.add(item); }
/** * Sorts the childBoundables then divides them into groups of size M, where M is the node * capacity. */ protected List createParentBoundables(List childBoundables, int newLevel) { Assert.isTrue(!childBoundables.isEmpty()); ArrayList parentBoundables = new ArrayList(); parentBoundables.add(createNode(newLevel)); ArrayList sortedChildBoundables = new ArrayList(childBoundables); Collections.sort(sortedChildBoundables, getComparator()); for (Iterator i = sortedChildBoundables.iterator(); i.hasNext(); ) { Boundable childBoundable = (Boundable) i.next(); if (lastNode(parentBoundables).getChildBoundables().size() == getNodeCapacity()) { parentBoundables.add(createNode(newLevel)); } lastNode(parentBoundables).addChildBoundable(childBoundable); } return parentBoundables; }
public String getTestXML(Geometry geometry, String opName, String[] arguments) { String xml = " <test>\n"; xml += " <op name=\"" + opName + "\" arg1=\"A\""; int j = 2; for (int i = 0; i < arguments.length; i++) { String argument = arguments[i]; Assert.isTrue(argument != null); xml += " arg" + j + "=\"" + argument + "\""; j++; } xml += ">\n"; xml += StringUtil.indent(wktWriter.writeFormatted(geometry) + "\n", 6); xml += " </op>\n"; xml += " </test>\n"; return xml; }
void insertNode(Node node) { Assert.isTrue(env == null || env.contains(node.env)); // System.out.println(env); // System.out.println(quad.env); int index = getSubnodeIndex(node.env, centrex, centrey); // System.out.println(index); if (node.level == level - 1) { subnode[index] = node; // System.out.println("inserted"); } else { // the quad is not a direct child, so make a new child quad to contain it // and recursively insert the quad Node childNode = createSubnode(index); childNode.insertNode(node); subnode[index] = childNode; } }
/** @param plugInDirectory null to leave unspecified */ public PlugInManager(WorkbenchContext context, File plugInDirectory, TaskMonitor monitor) throws Exception { this.monitor = monitor; Assert.isTrue((plugInDirectory == null) || plugInDirectory.isDirectory()); // add plugin folder and recursively all jar/zip files in it to classpath if (plugInDirectory instanceof File) { ArrayList<File> files = new ArrayList(); files.add(plugInDirectory); files.addAll(findFilesRecursively(plugInDirectory, true)); classLoader = new URLClassLoader(toURLs(files)); } else { classLoader = getClass().getClassLoader(); } // classLoader = plugInDirectory != null ? new URLClassLoader( // toURLs(findFilesRecursively(plugInDirectory,true))) : getClass().getClassLoader(); I18N.setClassLoader(classLoader); this.context = context; this.plugInDirectory = plugInDirectory; }
@Override void add(final List<Map<String, ?>> rows, final Values values, final Source source) throws JRException { JRDataSource dataSource = values.getObject(source.key, JRDataSource.class); Assert.isTrue( dataSource != null, "The Datasource object referenced by key: " + source.key + " does not exist. Check" + " that the key is correctly spelled in the config.yaml file.\n\t This is one of the" + " sources for the !mergeDataSources."); JRDesignField jrField = new JRDesignField(); while (dataSource.next()) { Map<String, Object> row = Maps.newHashMap(); for (Map.Entry<String, String> field : source.fields.entrySet()) { jrField.setName(field.getKey()); row.put(field.getValue(), dataSource.getFieldValue(jrField)); } rows.add(row); } }
/** * Constructs an AbstractSTRtree with the specified maximum number of child nodes that a node may * have * * @param nodeCapacity the maximum number of child nodes in a node */ public AbstractSTRtree(int nodeCapacity) { Assert.isTrue(nodeCapacity > 1, "Node capacity must be greater than 1"); this.nodeCapacity = nodeCapacity; }
public void checkNotWrappingSameClass() { Assert.isTrue( !(fc instanceof FeatureCollectionWrapper && ((FeatureCollectionWrapper) fc).hasWrapper(getClass()))); }
protected void insert(Object bounds, Object item) { Assert.isTrue(!built, "Cannot insert items into an STR packed R-tree after it has been built."); itemBoundables.add(new ItemBoundable(bounds, item)); }
public void addChoosableStyleClass(Class choosableStyleClass) { Assert.isTrue(ChoosableStyle.class.isAssignableFrom(choosableStyleClass)); choosableStyleClasses.add(choosableStyleClass); }
/** Returns the singleton. Be sure to call #setParameters first. */ public static Parameters getInstance() { Assert.isTrue(arguments != null); if (instance == null) instance = new Parameters(); return instance; }
/** * Create a {@link ProcessorDependencyGraph}. * * @param processors the processors that will be part of the graph * @return a {@link org.mapfish.print.processor.ProcessorDependencyGraph} constructed from the * passed in processors */ @SuppressWarnings("unchecked") public ProcessorDependencyGraph build(final List<? extends Processor> processors) { ProcessorDependencyGraph graph = new ProcessorDependencyGraph(); final Map<String, ProcessorGraphNode<Object, Object>> provideBy = new HashMap<String, ProcessorGraphNode<Object, Object>>(); final Map<String, Class<?>> outputTypes = new HashMap<String, Class<?>>(); final List<ProcessorGraphNode<Object, Object>> nodes = new ArrayList<ProcessorGraphNode<Object, Object>>(processors.size()); for (Processor<Object, Object> processor : processors) { final ProcessorGraphNode<Object, Object> node = new ProcessorGraphNode<Object, Object>(processor, this.metricRegistry); for (OutputValue value : getOutputValues(node)) { String outputName = value.getName(); if (provideBy.containsKey(outputName)) { // there is already an output with the same name if (value.canBeRenamed()) { // if this is just a debug output, we can simply rename it outputName = outputName + "_" + UUID.randomUUID().toString(); } else { throw new IllegalArgumentException( "Multiple processors provide the same output mapping: '" + processor + "' and '" + provideBy.get(outputName) + "' both provide: '" + outputName + "'. You have to rename one of the outputs and the corresponding input so that" + " there is no ambiguity with regards to the input a processor consumes."); } } provideBy.put(outputName, node); outputTypes.put(outputName, value.getType()); } nodes.add(node); } ArrayList<ProcessorDependency> allDependencies = Lists.newArrayList(this.dependencies); for (ProcessorGraphNode<Object, Object> node : nodes) { if (node.getProcessor() instanceof CustomDependencies) { CustomDependencies custom = (CustomDependencies) node.getProcessor(); allDependencies.addAll(custom.createDependencies(nodes)); } } final SetMultimap<ProcessorGraphNode<Object, Object>, InputValue> inputsForNodes = cacheInputsForNodes(nodes); for (ProcessorGraphNode<Object, Object> node : nodes) { final Set<InputValue> inputs = inputsForNodes.get(node); // check explicit, external dependencies between nodes checkExternalDependencies(allDependencies, node, nodes); // check input/output value dependencies for (InputValue input : inputs) { final ProcessorGraphNode<Object, Object> solution = provideBy.get(input.getName()); if (solution != null && solution != node) { // check that the provided output has the same type final Class<?> inputType = input.getType(); final Class<?> outputType = outputTypes.get(input.getName()); if (inputType.isAssignableFrom(outputType)) { solution.addDependency(node); } else { throw new IllegalArgumentException( "Type conflict: Processor '" + solution.getName() + "' provides an output with name '" + input.getName() + "' and of type '" + outputType + " ', while " + "processor '" + node.getName() + "' expects an input of that name with type '" + inputType + "'! Please rename one of the attributes in the mappings of the processors."); } } } } // once all dependencies are discovered, select the root nodes for (ProcessorGraphNode<Object, Object> node : nodes) { // a root node is a node that has no requirements (that is no other node // should be executed before the node) and that has only external inputs if (!node.hasRequirements() && hasNoneOrOnlyExternalInput(node, inputsForNodes.get(node), provideBy)) { graph.addRoot(node); } } Assert.isTrue( graph.getAllProcessors().containsAll(processors), "'" + graph + "' does not contain all the processors: " + processors); return graph; }
/** * Adds either an AbstractNode, or if this is a leaf node, a data object (wrapped in an * ItemBoundable) */ public void addChildBoundable(Boundable childBoundable) { Assert.isTrue(bounds == null); childBoundables.add(childBoundable); }
/** Returns true if key is one of the parameters. Case-insensitive. */ public boolean contains(String key) { Assert.isTrue(allowedKeys.contains(key.toLowerCase())); return hashtable.containsKey(key.toLowerCase()); }
/** * Returns the value of the specified parameter, or null if there is no such key. * Case-insensitive. */ public String get(String key) { Assert.isTrue(allowedKeys.contains(key.toLowerCase())); return (String) hashtable.get(key.toLowerCase()); }
public static Geometry obtenerGeometriaParcela(String dxf, WorkbenchContext context) { Geometry geometryParcela = null; GeopistaLoadDxfQueryChooser dxfLoad = new GeopistaLoadDxfQueryChooser(Dxf.class, "GEOPISTA dxf", extensions(Dxf.class), context); InputStream fileDXF = ImportarUtils_LCGIII.parseStringToIS(dxf); try { Assert.isTrue(!dxfLoad.getDataSourceQueries(fileDXF).isEmpty()); } catch (AssertionFailedException e) { throw new AssertionFailedException(I18N.get("FileEmpty")); } fileDXF = ImportarUtils_LCGIII.parseStringToIS(dxf); boolean exceptionsEncountered = false; for (Iterator i = dxfLoad.getDataSourceQueries(fileDXF).iterator(); i.hasNext(); ) { DataSourceQuery dataSourceQuery = (DataSourceQuery) i.next(); ArrayList exceptions = new ArrayList(); Assert.isTrue(dataSourceQuery.getDataSource().isReadable()); Connection connection = dataSourceQuery.getDataSource().getConnection(); try { FeatureCollection dataset = dataSourceQuery .getDataSource() .installCoordinateSystem( connection.executeQuery(dataSourceQuery.getQuery(), exceptions, null), null); if (dataset != null) { String layerName = dataSourceQuery.toString(); Geometry geometriaInicial = null; GeopistaFeature featureInicial = null; if (layerName.startsWith("PG-LP")) { // Obtener el borde con las features de la capa ArrayList lstFeatures = new ArrayList(); for (Iterator features = dataset.getFeatures().iterator(); features.hasNext(); ) { GeopistaFeature feature = (GeopistaFeature) features.next(); lstFeatures.add(feature); } ArrayList coordenadas = new ArrayList(); if (lstFeatures != null && lstFeatures.size() > 0) { featureInicial = (GeopistaFeature) lstFeatures.iterator().next(); lstFeatures.remove(featureInicial); geometriaInicial = featureInicial.getGeometry(); for (int indice = 0; indice < geometriaInicial.getCoordinates().length; indice++) coordenadas.add(geometriaInicial.getCoordinates()[indice]); if (geometriaInicial instanceof LineString) { Point puntoFinal = ((LineString) geometriaInicial).getEndPoint(); GeopistaFeature feature = null; Geometry geometria = null; int indice; while (lstFeatures.size() > 0) { boolean encontrado = false; Iterator features = lstFeatures.iterator(); while (features.hasNext() && !encontrado) { feature = (GeopistaFeature) features.next(); geometria = feature.getGeometry(); if (geometria instanceof LineString) { if (puntoFinal.distance(((LineString) geometria).getStartPoint()) == 0) { for (indice = 1; indice < geometria.getCoordinates().length; indice++) coordenadas.add(geometria.getCoordinates()[indice]); puntoFinal = ((LineString) geometria).getEndPoint(); encontrado = true; } else if (puntoFinal.distance(((LineString) geometria).getEndPoint()) == 0) { for (indice = geometria.getCoordinates().length - 2; indice >= 0; indice--) coordenadas.add(geometria.getCoordinates()[indice]); puntoFinal = ((LineString) geometria).getStartPoint(); encontrado = true; } } } if (encontrado) { lstFeatures.remove(feature); } } Coordinate[] coordenadasParcela = new Coordinate[coordenadas.size()]; indice = 0; for (Iterator coordenada = coordenadas.iterator(); coordenada.hasNext(); ) { coordenadasParcela[indice] = (Coordinate) coordenada.next(); indice++; } if (coordenadasParcela[0].equals3D( coordenadasParcela[coordenadasParcela.length - 1])) { LinearRing lineaParcela = geometriaInicial.getFactory().createLinearRing(coordenadasParcela); Polygon poligonoParcela = null; poligonoParcela = geometriaInicial.getFactory().createPolygon(lineaParcela, null); geometryParcela = poligonoParcela; } } } } } } finally { connection.close(); } if (!exceptions.isEmpty()) { if (!exceptionsEncountered) { context.getIWorkbench().getFrame().getOutputFrame().createNewDocument(); exceptionsEncountered = true; } reportExceptions(exceptions, dataSourceQuery, context); } } if (exceptionsEncountered) { context .getIWorkbench() .getGuiComponent() .warnUser("Problems were encountered. See Output Window for details."); } return geometryParcela; }