Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright (C) 2011-2014 Rinde van Lon, iMinds DistriNet, KU Leuven
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *         http://www.apache.org/licenses/LICENSE-2.0
  *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.github.rinde.rinsim.scenario.measure;
import static com.google.common.base.Preconditions.checkArgument;
A com.google.common.base.Predicate that evaluates to true if the input scenario has a number of orders in the range as specified by this instance. An order is specified by a com.github.rinde.rinsim.scenario.AddParcelEvent.

Author(s):
Rinde van Lon <rinde.vanlon@cs.kuleuven.be>
  private final int min;
  private final int max;

  
Range constructor, only accepts scenarios that have a number of orders that is in the range [minNumOrders,maxNumOrders].

Parameters:
minNumOrders Minimum number of orders.
maxNumOrders Maximum number of orders.
  OrderCountRequirement(int minNumOrdersint maxNumOrders) {
    checkArgument(minNumOrders <= maxNumOrders);
     = minNumOrders;
     = maxNumOrders;
  }

  
Exact constructor, only accepts scenarios that have exactly the specified number of orders.

Parameters:
orders The number of orders.
  OrderCountRequirement(int orders) {
    this(ordersorders);
  }
  public boolean apply(@Nullable Scenario input) {
    if (input == null) {
      return false;
    }
    final int numOrders = Collections.frequency(
        Collections2.transform(input.asList(),
            new ToClassFunction()), AddParcelEvent.class);
    return numOrders >=  && numOrders <= ;
  }
  private static final class ToClassFunction implements
      Function<ObjectClass<?>> {
    @Override
    @Nullable
    public Class<?> apply(@Nullable Object obj) {
      if (obj == null) {
        return null;
      }
      return obj.getClass();
    }
  }
New to GrepCode? Check out our FAQ X