List of usage examples for org.apache.commons.lang3.tuple Pair getKey
@Override public final L getKey()
Gets the key from this pair.
This method implements the Map.Entry interface returning the left element as the key.
From source file:org.kalypso.kalypsomodel1d2d.ui.map.channeledit.editdata.BanklineIntersector.java
private BankData intersectBankline(final IProfileData downProfile, final IProfileData upProfile) throws GM_Exception { final LineString upProfileLine = convertProfilesToLineStrings(upProfile); final LineString downProfileLine = convertProfilesToLineStrings(downProfile); final Pair<LineString, Pair<Point, Point>> intersection = findBankForProfiles(downProfileLine, upProfileLine);// w w w. j a v a2 s . c o m if (intersection == null) return null; final Pair<Point, Point> points = intersection.getValue(); final Point downPoint = points.getLeft(); final Point upPoint = points.getRight(); final LineString bankLine = intersection.getKey(); /* extract line between start end end intersection */ final LineString croppedBankLine = (LineString) JTSUtilities.extractLineString(bankLine, downPoint, upPoint); /* handle z values of start a<nd end point */ final double downZ = findIntersectionZ(downProfile, croppedBankLine.getStartPoint(), bankLine); final double upZ = findIntersectionZ(upProfile, croppedBankLine.getEndPoint(), bankLine); /* cropped line has z if bankLine has z; addionally, we want to force the profile height onto the endpoints */ final LineString croppedBankLineWithZEndPoints = replaceEndpointZ(croppedBankLine, downZ, upZ); /* now make sure, we have z everywhere */ final LineString croppedBankLineWithZ = JTSUtilities.interpolateMissingZ(croppedBankLineWithZEndPoints); final LineString segmentedGeometry = ChannelEditUtil.intersectLineString(croppedBankLineWithZ, m_numberOfBankPoints); return new BankData(m_segment, bankLine, croppedBankLine, segmentedGeometry, false); }
From source file:org.kalypso.model.flood.ui.map.EventManagementWidget.java
protected void handleEventSelectionChanged(final ScrolledComposite sc, final Pair<Group, FeatureComposite> infoGroupComponents, final IStructuredSelection selection) { m_treeSelection = selection.toArray(); final Group infoGroup = infoGroupComponents.getKey(); final FeatureComposite infoComposite = infoGroupComponents.getValue(); infoComposite.disposeControl();//from ww w.java 2s.c o m final IRunoffEvent runoffEvent = getSelectedEvent(); IKalypsoFeatureTheme runoffEventTheme = findThemeForEvent(runoffEvent); try { // Always check, if sld file exists if (runoffEvent != null) AddEventOperation.checkSLDFile(runoffEvent, getEventFolder(runoffEvent), SLD_TEMPLATE_LOCATION); final IKalypsoCascadingTheme wspThemes = findWspTheme(); if (runoffEventTheme == null && runoffEvent != null) { /* A bit crude: if the theme does not yet exist, we create it right now */ AddEventOperation.addEventThemes(wspThemes, runoffEvent); } /* Also add result theme if results are available */ if (runoffEvent != null && getResultFolder(runoffEvent).exists() && FloodModelHelper.findResultTheme(runoffEvent, wspThemes) == -1) FloodModelHelper.addResultTheme(runoffEvent, wspThemes, -1); } catch (final Exception e) { e.printStackTrace(); } runoffEventTheme = findThemeForEvent(runoffEvent); // TODO: add theme if missing if (runoffEventTheme == null) m_infoWidget.setThemes(null); else m_infoWidget.setThemes(new IKalypsoTheme[] { runoffEventTheme }); updateStylePanel(runoffEventTheme); if (m_treeSelection != null && m_treeSelection.length > 0) { infoComposite.setFeature((Feature) m_treeSelection[0]); infoComposite.createControl(infoGroup, SWT.NONE); } sc.getParent().layout(true, true); final Control panel = sc.getContent(); final Point size = panel.computeSize(SWT.DEFAULT, SWT.DEFAULT); panel.setSize(size); sc.setMinHeight(size.y); getMapPanel().repaintMap(); }
From source file:org.kalypso.model.wspm.pdb.wspm.CheckinStatePdbOperation.java
private CrossSectionPart[] checkin(final Session session, final State state, final List<IProfileObject> clonedProfileObjects, final IProfile profile, final EventUploadProvider eventProvider) throws PdbConnectException { final List<CrossSectionPart> parts = new ArrayList<>(); final CrossSectionPartTypes partTypes = session == null ? null : new CrossSectionPartTypes(session); final double station = profile.getStation(); final int dbSRID = m_data.getGeometryFactory().getSRID(); final int profileSRID = JTSAdapter.toSrid(profile.getSrsName()); final ICoefficients coefficients = m_data.getCoefficients(); for (final IProfileObject clonedProfileObject : clonedProfileObjects) { final Pair<Event, Boolean> findEventResult = findEvent(state, clonedProfileObject, eventProvider); final boolean shouldUpload = findEventResult.getValue(); if (shouldUpload) { final Event event = findEventResult.getKey(); final CheckinHorizonPartOperation operation = new CheckinHorizonPartOperation(clonedProfileObject, profileSRID, dbSRID, station, partTypes, event, coefficients); operation.execute();/* w w w .java 2 s. c om*/ final CrossSectionPart part = operation.getPart(); parts.add(part); } else { // TODO: part ws not uploaded -> log it! final String eventName = clonedProfileObject.getValue(IWspmTuhhConstants.PROFIL_PROPERTY_EVENT_NAME, null); System.out.format(Messages.getString("CheckinStatePdbOperation.8"), profile.getStation(), //$NON-NLS-1$ clonedProfileObject.getType(), eventName); } } return parts.toArray(new CrossSectionPart[] {}); }
From source file:org.kalypso.model.wspm.tuhh.core.profile.pattern.ProfileResultPattern.java
@Override public Object getValue(final IProfilePatternData data, final String param) { final IProfileFeature profileFeature = data.getProfileFeature(); if (profileFeature == null) return null; final Pair<String, String> parsedParams = parseParams(param); if (parsedParams == null) return null; final String nodeID = parsedParams.getKey(); final String component = parsedParams.getValue(); try {//from www. j a va 2 s . c om final Pair<IProfileFeature, String> pair = Pair.of(profileFeature, nodeID); final WspmResultLengthSection lengthSection = m_lengthSectionCache.get(pair); final BigDecimal station = profileFeature.getBigStation(); return lengthSection.getValue(station, component); } catch (final NullPointerException e) { // happens, if cache has no value return StringUtils.EMPTY; } catch (final ExecutionException e) { // happens, if computation function throws an exception return StringUtils.EMPTY; } }
From source file:org.kalypso.model.wspm.tuhh.core.profile.pattern.ProfileResultPattern.java
public IWspmResult getResult(final IProfileFeature[] profiles, final String param) { final Pair<String, String> parsedParams = parseParams(param); if (parsedParams == null) return null; final String nodeID = parsedParams.getKey(); if (StringUtils.isBlank(nodeID)) return null; if (profiles.length == 0) return null; // CHECK: we assume, that all profiles live in the same container -> we can use the first profile to determine the // results... is this always correct? return ResultFinder.findResult(profiles[0], nodeID); }
From source file:org.kalypso.model.wspm.tuhh.core.util.river.line.RiverLineBuilder.java
private Coordinate[] buildCoordinates() { final List<Pair<Coordinate, Vector2D>> directedLowPoints = new ArrayList<>(m_profiles.length); /* Find low points including direction */ for (final IProfileFeature profileFeature : m_profiles) { final Pair<Coordinate, Vector2D> locationAndDirction = getLocationAndDirction(profileFeature); directedLowPoints.add(locationAndDirction); }//from w ww . jav a 2 s .c o m /* add intermediate points: in order to keep direction of river line orthogonal to cross section */ final Collection<Coordinate> crds = new ArrayList<>(directedLowPoints.size() * 3); // TODO: very poor approximation if an arc two adjacent cross sections // we should use a proper arc implementation for (int i = 0; i < directedLowPoints.size(); i++) { final Coordinate prevLocation = i < 1 ? null : directedLowPoints.get(i - 1).getKey(); final Pair<Coordinate, Vector2D> current = directedLowPoints.get(i); final Coordinate nextLocation = i > directedLowPoints.size() - 2 ? null : directedLowPoints.get(i + 1).getKey(); final Coordinate currentLocation = current.getKey(); final Vector2D currentDirection = current.getValue(); if (currentDirection != null && prevLocation != null) { final double prevDistance = prevLocation.distance(currentLocation); final Vector2D shift = currentDirection.multiply(prevDistance / -10.0); crds.add(shift.translate(currentLocation)); } crds.add(currentLocation); if (currentDirection != null && nextLocation != null) { final double nextDistance = nextLocation.distance(currentLocation); final Vector2D shift = currentDirection.multiply(nextDistance / 10.0); crds.add(shift.translate(currentLocation)); } } return crds.toArray(new Coordinate[crds.size()]); }
From source file:org.kalypso.model.wspm.tuhh.ui.rules.RauheitRule.java
private void checkRoughnessValues(final IValidatorMarkerCollector collector, final String stationId, final IProfileRecord[] points) throws CoreException { for (final IProfileRecord point : points) { final Pair<String, Double> result = getValue(point); if (result == null) { final String msg = String.format(Messages.getString("RauheitRule.0"), point.getBreite()); //$NON-NLS-1$ // TODO: this resolution makes no sense, as it adds a component, but this is already here; problem is the empty vlaue, we need another resolution instead // final AddRoughnessResolution resolution = new AddRoughnessResolution( new String[] { IWspmConstants.POINT_PROPERTY_RAUHEIT_KS, IWspmConstants.POINT_PROPERTY_RAUHEIT_KST, // IWspmPointProperties.POINT_PROPERTY_ROUGHNESS_CLASS } ); collector.createProfilMarker(IMarker.SEVERITY_ERROR, msg, stationId, point.getIndex(), StringUtils.EMPTY);// w ww.j a v a 2 s.co m return; } final String id = result.getKey(); final Double value = result.getValue(); if (value == null || value.isNaN()) { // FIXME: this prefix is nonsense -> use real label // ComponentUtilities.getComponentLabel( null ); final String prefix = StringUtils.EMPTY; final String message = prefix + Messages.getString("org.kalypso.model.wspm.tuhh.ui.rules.RauheitRule.0"); //$NON-NLS-1$ collector.createProfilMarker(IMarker.SEVERITY_ERROR, message, stationId, point.getIndex(), id); //$NON-NLS-1$ //$NON-NLS-2$ return; } if (value <= 0.0) { // FIXME: this prefix is nonsense -> use real label // ComponentUtilities.getComponentLabel( null ); final String prefix = StringUtils.EMPTY; final String message = prefix + Messages.getString("org.kalypso.model.wspm.tuhh.ui.rules.RauheitRule.1"); //$NON-NLS-1$ collector.createProfilMarker(IMarker.SEVERITY_ERROR, message, stationId, point.getIndex(), id); //$NON-NLS-1$ //$NON-NLS-2$ return; } } }
From source file:org.kalypso.model.wspm.ui.profil.dialogs.reducepoints.SimplifyProfileOperation.java
public IStatus doRemovePoints() { final Pair<IProfileRecord[], IStatus> result = findPointsToRemove(); final IProfileRecord[] pointsToRemove = result.getKey(); final IStatus reduceStatus = result.getValue(); if (pointsToRemove == null) return reduceStatus; /* Create the profile operation. */ final PointRemove pointRemove = new PointRemove(m_profile, pointsToRemove); m_operation = new ProfileOperation( Messages.getString("org.kalypso.model.wspm.ui.profil.dialogs.reducepoints.DouglasPeuckerDialog.13"), //$NON-NLS-1$ m_profile, pointRemove, false); /* Create the runnable. */ final ProfileOperationRunnable operationRunnable = new ProfileOperationRunnable(m_operation); /* Execute the value. */ final IStatus operationStatus = operationRunnable.execute(new NullProgressMonitor()); if (!operationStatus.isOK()) return operationStatus; return reduceStatus; }
From source file:org.kalypso.ogc.gml.ImageHolder.java
public IStatus loadImage(final String filePath, final URL context) { try {//from ww w .ja v a2 s . c o m /* prepare for exception */ setImage(null, null, null); // UGLY HACK: replace backslashes with slashes. The add-picture-theme action seems to put backslashes (on windows) // in the relative URLs (which is even wrong in windows). Should be fixed there, but is fixed also here to support // older projects. final String filePathChecked = filePath.replaceAll("\\\\", "/"); //$NON-NLS-1$ //$NON-NLS-2$ final URL imageUrl = UrlResolverSingleton.resolveUrl(context, filePathChecked); final Pair<RenderedOp, SeekableStream> pair = openImage(imageUrl); final RenderedOp image = pair.getKey(); final SeekableStream stream = pair.getValue(); final TiledImage tiledImage = new TiledImage(image, false); setImage(tiledImage, stream, imageUrl); return Status.OK_STATUS; } catch (final MalformedURLException e) { return createStatus(e, Messages.getString("KalypsoPictureTheme.2"), filePath); //$NON-NLS-1$ } catch (final OutOfMemoryError error) { // REMARK: this will happen if we load big images // It is safe to catch it here, as the heap will be freed immediately, if the image could not be loaded return createStatus(error, Messages.getString("KalypsoPictureTheme.3"), filePath); //$NON-NLS-1$ } catch (final Throwable error) { // REMARK: this will happen if we load big images // It is safe to catch it here, as the heap will be freed immediately, if the image could not be loaded return createStatus(error, Messages.getString("KalypsoPictureTheme.4"), filePath); //$NON-NLS-1$ } }
From source file:org.kalypso.wspwin.core.WspWinProfProj.java
public void write(final File wspwinDir, final WspWinZustand[] zustaende) throws IOException { final WspWinProject wspwinProject = new WspWinProject(wspwinDir); final File profprojFile = wspwinProject.getProfProjFile(); final Collection<Pair<String, String>> profileStateMapping = new ArrayList<>(); /* Map profile files to state files */ for (final WspWinZustand zustand : zustaende) { final String stateFilename = zustand.getBean().getFileName(); final ProfileBean[] profileBeans = zustand.getProfileBeans(); for (final ProfileBean profileBean : profileBeans) { final String prfFilename = profileBean.getFileName(); profileStateMapping.add(Pair.of(prfFilename, stateFilename)); }//from ww w .j a va 2s. c o m } /* Write list of profiles */ final BufferedWriter pw = new BufferedWriter(new FileWriter(profprojFile)); pw.append(String.format("%d %d%n", m_profiles.size(), profileStateMapping.size())); //$NON-NLS-1$ for (final ProfileBean profile : m_profiles) pw.append(profile.formatProfprojLine()).append(SystemUtils.LINE_SEPARATOR); pw.append(SystemUtils.LINE_SEPARATOR); /* Write mapping from .prf to .str */ for (final Pair<String, String> entry : profileStateMapping) { final String prfFilename = entry.getKey(); final String stateFilename = entry.getValue(); pw.append(String.format("%s %s%n", prfFilename, stateFilename)); //$NON-NLS-1$ } pw.close(); }