public static Strategy getStrategy(Name name) { switch (name) { case SUM: return new Sum(); ... } }
public class f extends sum { public static void main(String[] args) { ArrayList<String> ac = new Sum().main(); // now you can use ac } }
Sum s = new Sum(); for(int i=0;i<1000;i++){ e.execute(s); }
final Sum sum = new Sum(); for (int i = 0; i < 1000; i++) { `e.execute(sum); }
function Sum() { this._total = 0; this.addTen = this.add.bind(this, 10); } Sum.prototype.add = function(amount) { this._total += amount; return this; }; Sum.prototype.toString = function() { return '' + this._total; }; var sum = new Sum(); sum.addTen().addTen(); console.info(sum); // 20
double f1 = 1; double ak1 = 1; double t = (4 / (ak1 + 1) - 2 / (ak1 + 4) - 1 / (ak1 + 5) - 1 / (ak1 + 6)) / f1; System.out.println(t); System.out.println(new Sum(BigDecimal.ONE, BigDecimal.ONE, MathContext.DECIMAL64).calculate()); System.out.println(new Sum(BigDecimal.ONE, BigDecimal.ONE, MathContext.DECIMAL128).calculate());
/** * Constructor SumBy creates a new SumBy instance. Use this constructor when used with a {@link AggregateBy} * instance. * * @param valueField of type Fields * @param sumField of type Fields */ @ConstructorProperties({"valueField", "sumField"}) public SumBy( Fields valueField, Fields sumField ) { super( valueField, new SumPartials( sumField ), new Sum( sumField ) ); }
public static void main(String args[]){ HasBarMethod defaultStrategy = new Sum(); DynamicBehavior dyn = new DynamicBehavior(defaultStrategy); if( /*condition*/ ){ dyn.setStrategy(new Multiply()); } double result = dyn.bar(5); }
/** * Constructor SumBy creates a new SumBy instance. Use this constructor when used with a {@link AggregateBy} * instance. * * @param valueField of type Fields * @param sumField of type Fields * @param sumType of type Class */ @ConstructorProperties({"valueField", "sumField", "sumType"}) public SumBy( Fields valueField, Fields sumField, Class sumType ) { super( valueField, new SumPartials( sumField, sumType ), new Sum( sumField, sumType ) ); }
if (a.length > 2) { Sum ob = new Sum(); ob.Sum1(a[a.length-1], a[a.length-2]); // <-- use length }
Sum sum=new Sum(); // creating a instance sum.Setsum(10, 10); // setting value System.out.println(sum.getSum()); // getting value back from same instance
/** * Constructor CountBy creates a new CountBy instance. Use this constructor when used with a {@link AggregateBy} * instance. * * @param countField of type Fields */ @ConstructorProperties({"countField"}) public CountBy( Fields countField ) { super( Fields.ALL, new CountPartials( countField.applyTypes( Long.TYPE ) ), new Sum( countField.applyTypes( Long.TYPE ) ) ); }
Sum s1 = new Sum(); s1.setSum(10,10); s1.getSum(); // using same object s1
/** * Constructor CountBy creates a new CountBy instance. Use this constructor when used with a {@link AggregateBy} * instance. * * @param countField of type Fields */ @ConstructorProperties({"valueFields", "countField", "include"}) public CountBy( Fields valueFields, Fields countField, Include include ) { super( valueFields, new CountPartials( countField.applyTypes( Long.TYPE ), include ), new Sum( countField.applyTypes( Long.TYPE ) ) ); }
public static void main(String args[]){ Sum s = new Sum(); s.setSequence(3); s.setSequence(9); System.out.println(s.getSequence()); }
/** * Constructor CountBy creates a new CountBy instance. Use this constructor when used with a {@link AggregateBy} * instance. * * @param countField of type Fields * @param include of type Include */ @ConstructorProperties({"countField", "include"}) public CountBy( Fields countField, Include include ) { super( Fields.ALL, new CountPartials( countField.applyTypes( Long.TYPE ), include ), new Sum( countField.applyTypes( Long.TYPE ) ) ); }
/** * Constructor CountBy creates a new CountBy instance. Use this constructor when used with a {@link AggregateBy} * instance. * * @param countField of type Fields */ @ConstructorProperties({"valueFields", "countField"}) public CountBy( Fields valueFields, Fields countField ) { super( valueFields, new CountPartials( countField.applyTypes( Long.TYPE ) ), new Sum( countField.applyTypes( Long.TYPE ) ) ); }
/** * Constructor CountBy creates a new CountBy instance. * * @param name of type String * @param pipes of type Pipe[] * @param groupingFields of type Fields * @param countField of type Fields * @param threshold of type int */ @ConstructorProperties({"name", "pipes", "groupingFields", "countField", "threshold"}) public CountBy( String name, Pipe[] pipes, Fields groupingFields, Fields countField, int threshold ) { super( name, pipes, groupingFields, groupingFields, new CountPartials( countField.applyTypes( Long.TYPE ) ), new Sum( countField.applyTypes( Long.TYPE ) ), threshold ); }
topology.newStream("aggregation", spout) .groupBy(new Fields("col1","col2")) .chainedAgg() .aggregate(new Fields("val1"), new Sum(), new Fields("val1sum")) .aggregate(new Fields("val2"), new Sum(), new Fields("val2sum")) .chainEnd() .each(new Fields("col1","col2","val1sum", "val2sum"), new Utils.PrintFilter());
@Test public void testSum() { Aggregator aggregator = new Sum(); Tuple[] arguments = new Tuple[]{new Tuple( new Double( 1.0 ) ), new Tuple( new Double( 3.0 ) ), new Tuple( new Double( 2.0 ) ), new Tuple( new Double( 4.0 ) ), new Tuple( new Double( -5.0 ) )}; Fields resultFields = new Fields( "field" ); TupleListCollector resultEntryCollector = invokeAggregator( aggregator, arguments, resultFields ); Tuple tuple = resultEntryCollector.iterator().next(); assertEquals( "got expected value after aggregate", 5.0, tuple.getDouble( 0 ), 0.0d ); }