X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.history%2Fsrc%2Forg%2Fsimantics%2Fhistory%2Futil%2FWeightedMedianBinding.java;h=6e2f59fd99b55e1cf13368eeed2121d2d3a06aed;hb=d9d830062a16b727c65d9bbd04f519235c5ece01;hp=f91e7809deab797aca5a9f7bf1c67182a030d98e;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.history/src/org/simantics/history/util/WeightedMedianBinding.java b/bundles/org.simantics.history/src/org/simantics/history/util/WeightedMedianBinding.java index f91e7809d..6e2f59fd9 100644 --- a/bundles/org.simantics.history/src/org/simantics/history/util/WeightedMedianBinding.java +++ b/bundles/org.simantics.history/src/org/simantics/history/util/WeightedMedianBinding.java @@ -1,163 +1,163 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.history.util; - -import java.util.Iterator; - -import org.simantics.databoard.Bindings; -import org.simantics.databoard.binding.ArrayBinding; -import org.simantics.databoard.binding.error.BindingException; -import org.simantics.databoard.type.ArrayType; - -/** - * This class binds median class to as an array(double) where every second value - * represents value and odd weight. - */ -public class WeightedMedianBinding extends ArrayBinding { - - public WeightedMedianBinding() { - super(new ArrayType(Bindings.DOUBLE.type()), Bindings.DOUBLE); - } - - @Override - public Object create() { - return new WeightedMedian(); - } - - @Override - public Object create(int length, Iterator it) throws BindingException { - WeightedMedian result = new WeightedMedian( length ); - int count = length/2; - WeightedMedian.Item[] items = new WeightedMedian.Item[count]; - int index = 0; - double value=0.0, weight=0.0; - while (it.hasNext()) { - double d = (Double) it.next(); - if ( index%2==0 ) { - value = d; - } else { - weight = d; - WeightedMedian.Item i = new WeightedMedian.Item(weight, value); - items[ index/2 ] = i; - } - index++; - } - if ( count>0 ) { - items[0].next = items[1]; - items[count-1].prev = items[count-2]; - } - for (index=1; index0 ) { - items[0].next = items[1]; - items[count-1].prev = items[count-2]; - } - for (int index=1; index=c ) throw new BindingException("Index "+index+" out of bounds "+c); - WeightedMedian.Item i = median.head(); - for (int ix=1; ix it) throws BindingException { + WeightedMedian result = new WeightedMedian( length ); + int count = length/2; + WeightedMedian.Item[] items = new WeightedMedian.Item[count]; + int index = 0; + double value=0.0, weight=0.0; + while (it.hasNext()) { + double d = (Double) it.next(); + if ( index%2==0 ) { + value = d; + } else { + weight = d; + WeightedMedian.Item i = new WeightedMedian.Item(weight, value); + items[ index/2 ] = i; + } + index++; + } + if ( count>0 ) { + items[0].next = items[1]; + items[count-1].prev = items[count-2]; + } + for (index=1; index0 ) { + items[0].next = items[1]; + items[count-1].prev = items[count-2]; + } + for (int index=1; index=c ) throw new BindingException("Index "+index+" out of bounds "+c); + WeightedMedian.Item i = median.head(); + for (int ix=1; ix