Example usage for org.apache.commons.lang3.tuple Pair getValue

List of usage examples for org.apache.commons.lang3.tuple Pair getValue

Introduction

In this page you can find the example usage for org.apache.commons.lang3.tuple Pair getValue.

Prototype

@Override
public R getValue() 

Source Link

Document

Gets the value from this pair.

This method implements the Map.Entry interface returning the right element as the value.

Usage

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();/*from   w  ww.ja v a  2s.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

protected IComponent findComponent(final String params) {
    final Pair<String, String> parsedParams = parseParams(params);
    if (parsedParams == null)
        return null;

    final String componentID = parsedParams.getValue();
    return ComponentUtilities.getFeatureComponent(componentID);
}

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   ww  w  . ja  v a  2s.c o  m
        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.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);
    }/*www  .  ja  v  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);// www  .ja  va 2 s  . c o 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 {//  w w w. ja  v  a2 s .co 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  www  .j  a v  a 2s. com
    }

    /* 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();
}

From source file:org.kitodo.dataaccess.storage.memory.GraphPath.java

/**
 * Creates a node representing the graph path string.
 *
 * @param string/*from ww  w  . j a v  a 2  s  . co  m*/
 *            string to parse
 * @param prefixes
 *            a mapping of prefixes to namespaces which was used to shorten
 *            the string
 */
public GraphPath(String string, Map<String, String> prefixes) {
    super(GRAPH_PATH);
    int index = 0;
    Node graphPosition = this;
    int length = string.length();
    while (index < length) {
        while ((index < length) && (string.codePointAt(index) <= ' ')) {
            index++;
        }
        if ((index < length) && (string.codePointAt(index) == '[')) {
            index++;
            Pair<Integer, Node> parseObjectRecursive = parseObject(string.substring(index), prefixes);
            index += parseObjectRecursive.getKey();
            index++;
            graphPosition.put(RDF.OBJECT, parseObjectRecursive.getValue());
        } else {
            Node nextLocationStep = new MemoryNode(LOCATION_STEP);
            NodeReference direction = RDF.NIL;
            switch (index < length ? string.codePointAt(index) : -1) {
            case '<':
                throw new IllegalArgumentException("Directive '<' not supported.");
            case '>':
                index++;
                switch (index < length ? string.codePointAt(index) : -1) {
                case '>':
                    index++;
                    if ((index < length) && (string.codePointAt(index) == '>')) {
                        index++;
                        throw new IllegalArgumentException("Directive '>|' not supported.");
                    } else {
                        throw new IllegalArgumentException("Directive '>>' not supported.");
                    }
                case '|':
                    throw new IllegalArgumentException("Directive '>|' not supported.");
                default:
                    direction = TO;
                    break;
                }
                break;
            case '|':
                if (((index + 1) < length) && (string.codePointAt(index + 1) == '<')) {
                    throw new IllegalArgumentException("Directive '|<' not supported.");
                }
                break;
            default:
                direction = TO;
                break;
            }
            while ((index < length) && (string.codePointAt(index) <= ' ')) {
                index++;
            }
            graphPosition.put(direction, nextLocationStep);
            graphPosition = nextLocationStep;
            int predicatesStart = index;
            int codePoint;
            while ((index < length) && ((codePoint = string.codePointAt(index)) > ' ')) {
                index += Character.charCount(codePoint);
            }
            String predicates = string.substring(predicatesStart, index);
            if (!predicates.equals(ANY_PREDICATE_CHAR)) {
                for (String predicate : predicates.split("\\|")) {
                    graphPosition.put(RDF.PREDICATE, applyPrefixes(prefixes, predicate));
                }
            }
        }
    }
}

From source file:org.kitodo.dataaccess.storage.memory.GraphPath.java

/**
 * Parses an object from a graph path string.
 *
 * @param string//from  w w  w  .  j a  va  2  s  . co m
 *            string to parse
 * @return the number of code points consumed and the object parsed
 */
private final Pair<Integer, Node> parseObject(String string, Map<String, String> prefixes) {
    int length = string.length();
    Node result = new MemoryNode();
    int index = 0;
    NodeReference currentPredicate = null;
    do {
        while ((index < length) && (string.codePointAt(index) <= ' ')) {
            index++;
        }
        if ((index >= length) || (string.codePointAt(index) == ']')) {
            return Pair.of(index, result);
        } else if (string.codePointAt(index) == ',') {
            index++;
            currentPredicate = null;
        } else if (string.codePointAt(index) == '[') {
            index++;
            Pair<Integer, Node> recursion = parseObject(string.substring(index), prefixes);
            index += recursion.getKey();
            index++;
            result.put(currentPredicate != null ? currentPredicate : ANY_PREDICATE, recursion.getValue());
        } else {
            if (currentPredicate == null) {
                int predicatesStart = index;
                int codePoint;
                while ((index < length) && ((codePoint = string.codePointAt(index)) > ' ')) {
                    index += Character.charCount(codePoint);
                }
                String predicate = string.substring(predicatesStart, index);
                currentPredicate = predicate.equals(ANY_PREDICATE_CHAR) ? ANY_PREDICATE
                        : MemoryStorage.INSTANCE.createNodeReference(applyPrefixes(prefixes, predicate));
            } else {
                int literalStart = index;
                int cp;
                while ((index < length) && ((cp = string.codePointAt(index)) > ' ') && (cp != ',')
                        && (cp != ']')) {
                    index += Character.charCount(cp);
                }
                String value = applyPrefixes(prefixes, string.substring(literalStart, index));
                result.put(currentPredicate, MemoryLiteral.createLeaf(value, null));
            }
        }
    } while (index < length);
    return Pair.of(length, result);
}