view artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthAccess.java @ 8854:7bbfb24e6eec

SINFO - first prototype of BArt Fließtiefen
author gernotbelger
date Thu, 18 Jan 2018 18:34:41 +0100
parents
children d9dbf0b74bc2
line wrap: on
line source
/* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
 * Software engineering by 
 *  Björnsen Beratende Ingenieure GmbH 
 *  Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
 *
 * This file is Free Software under the GNU AGPL (>=v3)
 * and comes with ABSOLUTELY NO WARRANTY! Check out the
 * documentation coming with Dive4Elements River for details.
 */

package org.dive4elements.river.artifacts.sinfo.flowdepth;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

import org.dive4elements.river.artifacts.access.RangeAccess;
import org.dive4elements.river.artifacts.sinfo.SINFOArtifact;
import org.dive4elements.river.artifacts.sinfo.SinfoCalcMode;
import org.dive4elements.river.backend.utils.StringUtil;

/**
 * Access to the flow depth calculation type specific SInfo artifact data.
 * REMARK: this class is NOT intended to be hold in the results (or anywhere else), in order to avoid a permanent reference to the artifact instance. 
 * Hence we do NOT cache any data.
 * 
 * @author Gernot Belger
 */
public class FlowDepthAccess
extends      RangeAccess
{
	public static class DifferencesPair
	{
		private final String wstId;
		private final String soundingId;

		public DifferencesPair( final String wstId, final String soundingId ) {
			this.wstId = wstId;
			this.soundingId = soundingId;
		}
		
		public String getWstId() {
			return this.wstId;
		}

		public String getSoundingId() {
			return this.soundingId;
		}
	}

	private static final String FIELD_USE_TKH = "use_transport_bodies"; //$NON-NLS-1$

	public FlowDepthAccess(final SINFOArtifact artifact) {
		super(artifact);

		/* assert calculation mode */
		final SinfoCalcMode calculationMode = artifact.getCalculationMode();
		assert(calculationMode == SinfoCalcMode.sinfo_calc_flow_depth);
	}

	public boolean isUseTransportBodies() {
		final Boolean useTkh = artifact.getDataAsBoolean( FIELD_USE_TKH );
		return useTkh == null ? false : useTkh;
	}

	public Collection<DifferencesPair> getDifferencePairs() {

		final Collection<DifferencesPair> diffPairs = new ArrayList<>();

		 final String diffids = super.getString("diffids");
		 if( diffids == null )
		 {
			 // Should never happen as this is handled by the ui
			 return Collections.emptyList();
		 }

		 // FIXME: this way of parsing the datacage-ids is repeated all over flys!
		 final String datas[] = diffids.split("#");
		 for(int i = 0; i < datas.length; i+=2) {
			 final String leftId = StringUtil.unbracket( datas[i] );
			 final String rightId = StringUtil.unbracket( datas[i+1] );

			 diffPairs.add(new DifferencesPair(leftId, rightId));
		 }

		return Collections.unmodifiableCollection(diffPairs);
	}
}

http://dive4elements.wald.intevation.org