@Override
 public Double getValue(Double x, Double y, Double z) {
   Validate.notNull(x, "x");
   Validate.notNull(y, "y");
   Validate.notNull(z, "z");
   return _interpolator.interpolate(_dataBundle, new double[] {x, y, z});
 }
  @Override
  public String setStylesheetParameter(String name, String value) {
    Validate.notEmpty(name, "name cannot be null");
    Validate.notEmpty(value, "value cannot be null");

    return this.parameters.put(name, value);
  }
Esempio n. 3
0
  /**
   * Registers the given event to the specified listener using a directly passed EventExecutor
   *
   * @param event Event class to register
   * @param listener PlayerListener to register
   * @param priority Priority of this event
   * @param executor EventExecutor to register
   * @param plugin Plugin to register
   * @param ignoreCancelled Do not call executor if event was already cancelled
   */
  public void registerEvent(
      Class<? extends Event> event,
      Listener listener,
      EventPriority priority,
      EventExecutor executor,
      Plugin plugin,
      boolean ignoreCancelled) {
    Validate.notNull(listener, "Listener cannot be null");
    Validate.notNull(priority, "Priority cannot be null");
    Validate.notNull(executor, "Executor cannot be null");
    Validate.notNull(plugin, "Plugin cannot be null");

    if (!plugin.isEnabled()) {
      throw new IllegalPluginAccessException(
          "Plugin attempted to register " + event + " while not enabled");
    }

    if (useTimings) {
      getEventListeners(event)
          .register(
              new TimedRegisteredListener(listener, executor, priority, plugin, ignoreCancelled));
    } else {
      getEventListeners(event)
          .register(new RegisteredListener(listener, executor, priority, plugin, ignoreCancelled));
    }
  }
 @Override
 public Double visitBondFixedSecurity(
     final BondFixedSecurity bond, final YieldCurveBundle curves) {
   Validate.notNull(curves);
   Validate.notNull(bond);
   return METHOD_BOND.cleanPriceFromCurves(bond, curves);
 }
 /**
  * Creates the subcontext identified by the given <code>path</code>
  *
  * @param context
  * @param path slash separated hierarchy of sub contexts (e.g. /mdsp/brodcasterlistener/
  * @throws NamingException
  */
 public static Context createSubcontext(Context context, String path) throws NamingException {
   Validate.notNull(context, "context");
   Validate.notNull(path, "path");
   if (log.isDebugEnabled()) {
     log.debug(
         "> createSubcontext(context=" + context.getNameInNamespace() + ", path=" + path + ")");
   }
   String[] subContextsNames = StringUtils.split(path, "/");
   Context currentContext = context;
   for (String subContextName : subContextsNames) {
     try {
       currentContext = (Context) currentContext.lookup(subContextName);
       if (log.isDebugEnabled()) {
         log.debug("Context '" + subContextName + "' already exist");
       }
     } catch (NameNotFoundException e) {
       currentContext = currentContext.createSubcontext(subContextName);
       if (log.isDebugEnabled()) {
         log.debug("Context '" + subContextName + "' created");
       }
     }
   }
   if (log.isDebugEnabled()) {
     log.debug("< createSubcontext() : " + currentContext.getNameInNamespace());
   }
   return currentContext;
 }
 /**
  * For ForwardRateAgreement the ParSpread is the spread to be added to the fixed rate to obtain a
  * present value of zero.
  *
  * @param fra The forward rate agreement.
  * @param curves The yield curve bundle.
  * @return The par spread.
  */
 @Override
 public Double visitForwardRateAgreement(
     final ForwardRateAgreement fra, final YieldCurveBundle curves) {
   Validate.notNull(curves);
   Validate.notNull(fra);
   return METHOD_FRA.parSpread(fra, curves);
 }
  @Override
  public IPortletWindow createDelegatePortletWindow(
      HttpServletRequest request,
      IPortletEntityId portletEntityId,
      IPortletWindowId delegationParentId) {
    Validate.notNull(request, "request can not be null");
    Validate.notNull(portletEntityId, "portletEntityId can not be null");

    // TODO does a delegate portlet entity need some sort of special treatment or do we just assume
    // that the calling code is using one?

    final IPortletWindowId portletWindowId =
        this.getDefaultPortletWindowId(request, portletEntityId);

    final PortletWindowCache<IPortletWindow> portletWindowMap = getPortletWindowMap(request);

    // Check if there is portlet window cached in the request
    IPortletWindow portletWindow = portletWindowMap.getWindow(portletWindowId);
    if (portletWindow != null) {
      logger.trace("Found IPortletWindow {} in request cache", portletWindow.getPortletWindowId());
      return portletWindow;
    }

    final PortletWindowData portletWindowData =
        this.getOrCreateDefaultPortletWindowData(
            request, portletEntityId, portletWindowId, delegationParentId);
    portletWindow = wrapPortletWindowData(request, portletWindowData);
    if (portletWindow == null) {
      return null;
    }

    // Cache the wrapped window in the request
    return portletWindowMap.storeIfAbsentWindow(portletWindow);
  }
 /**
  * Computes the present value of a fixed coupon by discounting.
  *
  * @param cpn The coupon.
  * @param curves The curve bundle.
  * @return The present value.
  */
 public CurrencyAmount presentValue(CouponFixed cpn, YieldCurveBundle curves) {
   Validate.notNull(curves);
   Validate.notNull(cpn);
   final YieldAndDiscountCurve fundingCurve = curves.getCurve(cpn.getFundingCurveName());
   double pv = cpn.getAmount() * fundingCurve.getDiscountFactor(cpn.getPaymentTime());
   return CurrencyAmount.of(cpn.getCurrency(), pv);
 }
Esempio n. 9
0
  /**
   * Executed on tab completion for this command, returning a list of options the player can tab
   * through.
   *
   * @param sender Source object which is executing this command
   * @param alias the alias being used
   * @param args All arguments passed to the command, split via ' '
   * @return a list of tab-completions for the specified arguments. This will never be null. List
   *     may be immutable.
   * @throws IllegalArgumentException if sender, alias, or args is null
   */
  public List<String> tabComplete(CommandSender sender, String alias, String[] args)
      throws IllegalArgumentException {
    Validate.notNull(sender, "Sender cannot be null");
    Validate.notNull(args, "Arguments cannot be null");
    Validate.notNull(alias, "Alias cannot be null");

    if (args.length == 0) {
      return ImmutableList.of();
    }

    String lastWord = args[args.length - 1];

    Player senderPlayer = sender instanceof Player ? (Player) sender : null;

    ArrayList<String> matchedPlayers = new ArrayList<String>();
    for (Player player : sender.getServer().getOnlinePlayers()) {
      String name = player.getName();
      if ((senderPlayer == null || senderPlayer.canSee(player))
          && StringUtil.startsWithIgnoreCase(name, lastWord)) {
        matchedPlayers.add(name);
      }
    }

    Collections.sort(matchedPlayers, String.CASE_INSENSITIVE_ORDER);
    return matchedPlayers;
  }
  private ContainerWrapper(
      ObjectWrapper objectWrapper,
      T container,
      ContainerStatus status,
      ItemPath path,
      boolean createProperties,
      PageBase pageBase) {
    Validate.notNull(container, "container must not be null.");
    Validate.notNull(status, "Container status must not be null.");
    Validate.notNull(pageBase, "pageBase must not be null.");

    this.objectWrapper = objectWrapper;
    this.container = container;
    this.status = status;
    this.path = path;
    main = path == null;
    readonly = objectWrapper.isReadonly(); // [pm] this is quite questionable
    showInheritedObjectAttributes = objectWrapper.isShowInheritedObjectAttributes();
    // have to be after setting "main" property
    containerDefinition = getItemDefinition();
    if (createProperties) {
      // HACK HACK HACK, the container wrapper should not parse itself. This code should not be
      // here.
      // Constructor should NOT parse the object
      // the createProperties parameter is here to avoid looping when parsing associations
      properties = createProperties(pageBase);
    } else {
      properties = new ArrayList<>();
    }
  }
Esempio n. 11
0
    private Criterion(String name, CriterionType type) {
        Validate.notEmpty(name);
        Validate.notNull(type);

        this.name = name;
        this.type = type;
    }
 /**
  * @param n The number of sample points to be used in the integration, not negative or zero
  * @param generator The generator of weights and abscissas
  */
 public GaussianQuadratureIntegrator1D(
     final int n, final QuadratureWeightAndAbscissaFunction generator) {
   Validate.isTrue(n > 0, "number of intervals must be > 0");
   Validate.notNull(generator, "generating function");
   _n = n;
   _generator = generator;
 }
  @Override
  public List<String> tabComplete(CommandSender sender, String alias, String[] args) {
    Validate.notNull(sender, "Sender cannot be null");
    Validate.notNull(args, "Arguments cannot be null");
    Validate.notNull(alias, "Alias cannot be null");

    if (args.length == 1) {
      return StringUtil.copyPartialMatches(
          args[0], WHITELIST_SUBCOMMANDS, new ArrayList<String>(WHITELIST_SUBCOMMANDS.size()));
    } else if (args.length == 2) {
      if (args[0].equalsIgnoreCase("add")) {
        List<String> completions = new ArrayList<String>();
        for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
          String name = player.getName();
          if (StringUtil.startsWithIgnoreCase(name, args[1]) && !player.isWhitelisted()) {
            completions.add(name);
          }
        }
        return completions;
      } else if (args[0].equalsIgnoreCase("remove")) {
        List<String> completions = new ArrayList<String>();
        for (OfflinePlayer player : Bukkit.getWhitelistedPlayers()) {
          String name = player.getName();
          if (StringUtil.startsWithIgnoreCase(name, args[1])) {
            completions.add(name);
          }
        }
        return completions;
      }
    }
    return ImmutableList.of();
  }
Esempio n. 14
0
  public InstrumentDefinition<?> convert(final Trade trade) {
    Validate.notNull(trade, "trade");
    Validate.isTrue(
        trade.getSecurity() instanceof IRFutureOptionSecurity,
        "Can only handle trades with security type IRFutureOptionSecurity");
    final Object securityDefinition =
        _securityConverter.convert((IRFutureOptionSecurity) trade.getSecurity());
    final int quantity =
        1; // trade.getQuantity().intValue(); TODO: correct when position/trade dilemma is solved.
    // TODO trade time or premium time?
    //    final ZonedDateTime tradeDate =
    // ZonedDateTime.of(trade.getPremiumDate().atTime(trade.getPremiumTime()),
    //        TimeZone.UTC); //TODO get the real time zone
    final ZonedDateTime tradeDate =
        ZonedDateTime.of(
            trade.getTradeDate().atTime(trade.getTradeTime()),
            TimeZone.UTC); // TODO get the real time zone

    final Double tradePrice = trade.getPremium();
    Validate.notNull(
        tradePrice,
        "IRFutureOption trade must have a premium set. The interpretation of premium is the market price, without unit, i.e. not %");
    // TODO: The premium is not the right place to store the trade price...

    if (securityDefinition instanceof InterestRateFutureOptionMarginSecurityDefinition) {
      final InterestRateFutureOptionMarginSecurityDefinition underlyingOption =
          (InterestRateFutureOptionMarginSecurityDefinition) securityDefinition;
      return new InterestRateFutureOptionMarginTransactionDefinition(
          underlyingOption, quantity, tradeDate, tradePrice);
    }
    final InterestRateFutureOptionPremiumSecurityDefinition underlyingOption =
        (InterestRateFutureOptionPremiumSecurityDefinition) securityDefinition;
    return new InterestRateFutureOptionPremiumTransactionDefinition(
        underlyingOption, quantity, tradeDate, tradePrice);
  }
    @SuppressWarnings("synthetic-access")
    @Override
    public Double visitStrike(final BlackVolatilitySurfaceStrike surface, final DoublesPair data) {

      Validate.isTrue(data.first >= 0, "Negative lower limit");
      Validate.isTrue(data.second > data.first, "upper limit not greater than lower");

      if (_t < 1e-4) {
        if (data.first < _f && data.second > _f) {
          final double atmVol = surface.getVolatility(_t, _f);
          return atmVol * atmVol;
        }
        return 0.0;
      }

      final Function1D<Double, Double> integrand = getStrikeIntegrand(surface);
      // if external left tail residual is provided, only integrate from cut-off, otherwise we will
      // double count
      final double lowerLimit = Math.max(_lowStrikeCutoff, data.first);
      final double upperLimit = data.second;

      // Do the call/k^2 integral - split up into the the put integral and the call integral because
      // the function is not smooth at strike = forward
      double res = _integrator.integrate(integrand, _f, upperLimit);
      res += _integrator.integrate(integrand, lowerLimit, _f);

      if (_addResidual) {
        res += _residual;
      }
      return 2 * res / _t;
    }
Esempio n. 16
0
  /**
   * Downloads a {@link Document} from the DMS.
   *
   * @param uuid the ID of the document in DMS.<br>
   * @param versionLabel the version label to be downloaded. Use {@link
   *     DMSConstants#INITIAL_VERSION_LABEL} for first version. Null is not allowed.
   * @return not null {@link Document} or Exception occurs if no content or no document for the
   *     given frameID, or if the version label does not exist.
   * @throws RemoteException Communication Exception.
   * @throws DMSException if an error occurs in DMS back end
   */
  @Interceptors(AuthenticationInterceptor.class)
  public Document getDocumentInVersion(String uuid, String versionLabel)
      throws RemoteException, DMSException {
    Validate.notNull(uuid);
    Validate.notNull(versionLabel);
    /** Get the version history. */
    VersionHistory versionHistory = null;
    Document document = null;

    versionHistory =
        getAuthoringService()
            .getVersionHistory(getReference(null, uuid, DMSStoreRegistry.STORE_REF));

    for (org.alfresco.webservice.types.Version version : versionHistory.getVersions()) {
      Reference reference = version.getId();
      if (version.getLabel().equals(versionLabel)) {
        document = getContent(reference, DMSStoreRegistry.VERSION_STORE_REF);
        if (document != null) {
          return document;
        }
      }
    }

    throw new IllegalStateException("Could not download the version :  " + versionLabel);
  }
Esempio n. 17
0
  /**
   * @param location the {@link Location} around which players must be to see the effect
   * @param effectName list of effects: https://gist.github.com/riking/5759002
   * @param offsetX the amount to be randomly offset by in the X axis
   * @param offsetY the amount to be randomly offset by in the Y axis
   * @param offsetZ the amount to be randomly offset by in the Z axis
   * @param speed the speed of the particles
   * @param count the number of particles
   * @param radius the radius around the location
   */
  public static void playParticleEffect(
      Location location,
      String effectName,
      float offsetX,
      float offsetY,
      float offsetZ,
      float speed,
      int count,
      int radius) {
    Validate.notNull(location, "Location cannot be null");
    Validate.notNull(effectName, "Effect cannot be null");
    Validate.notNull(location.getWorld(), "World cannot be null");

    PacketPlayOutWorldParticles packet =
        new PacketPlayOutWorldParticles(
            effectName,
            (float) location.getX(),
            (float) location.getY(),
            (float) location.getZ(),
            offsetX,
            offsetY,
            offsetZ,
            speed,
            count);

    for (Player player : location.getWorld().getPlayers()) {
      if ((int) player.getLocation().distance(location) <= radius) {
        ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
      }
    }
  }
Esempio n. 18
0
  /**
   * {@inheritDoc}
   *
   * @see
   *     org.prowim.dms.alfresco.ContentService#updateDMSDocument(org.prowim.datamodel.dms.Document,
   *     java.lang.String)
   */
  @Override
  @Interceptors(AuthenticationInterceptor.class)
  public void updateDMSDocument(Document document, String uuid) throws DMSException {
    Validate.notNull(document);
    Validate.notNull(uuid);

    ContentFormat contentFormat =
        new ContentFormat(document.getContentType(), DMSConstants.ENCODING);
    try {
      DocumentIdentification documentIdentification = new DocumentIdentification(uuid, null);
      getContentService()
          .write(
              this.getReference(
                  documentIdentification.getPath(),
                  documentIdentification.getUuid(),
                  DMSStoreRegistry.STORE_REF),
              Constants.PROP_CONTENT,
              document.getContent(),
              contentFormat);

    } catch (ContentFault e) {
      String message = "Could not update content: ";
      LOG.error(message, e);
      DMSFault dmsFault = new DMSFault();
      dmsFault.setMessage(message);
      throw new DMSException(message, dmsFault, e.getCause());
    } catch (RemoteException e) {
      String message = "Could not create connection: ";
      LOG.error(message, e);
      DMSFault dmsFault = new DMSFault();
      dmsFault.setMessage(message);
      throw new DMSException(message, dmsFault, e.getCause());
    }
  }
  @Override
  public IPortletWindow getOrCreateDefaultPortletWindow(
      HttpServletRequest request, IPortletEntityId portletEntityId) {
    Validate.notNull(request, "request can not be null");
    Validate.notNull(portletEntityId, "portletEntityId can not be null");

    final IPortletWindowId portletWindowId =
        this.getDefaultPortletWindowId(request, portletEntityId);

    final PortletWindowCache<IPortletWindow> portletWindowMap = getPortletWindowMap(request);

    // Check if there is portlet window cached in the request
    IPortletWindow portletWindow = portletWindowMap.getWindow(portletWindowId);
    if (portletWindow != null) {
      logger.trace("Found IPortletWindow {} in request cache", portletWindow.getPortletWindowId());
      return portletWindow;
    }

    final PortletWindowData portletWindowData =
        this.getOrCreateDefaultPortletWindowData(request, portletEntityId, portletWindowId);
    portletWindow = wrapPortletWindowData(request, portletWindowData);
    if (portletWindow == null) {
      return null;
    }

    // Cache the wrapped window in the request
    return portletWindowMap.storeIfAbsentWindow(portletWindow);
  }
Esempio n. 20
0
 public Point(double lat, double lon) {
   Validate.isTrue(lat >= -90.0 && lat <= 90.0, "Latitude must be in [-90, 90] but was ", lat);
   Validate.isTrue(
       lon >= -180.0 && lon <= 180.0, "Longitude must be in [-180, 180] but was ", lon);
   this.lat = lat;
   this.lon = lon;
 }
Esempio n. 21
0
 public Potion(PotionType type, int level) {
   this(type);
   Validate.notNull(type, "Type cannot be null");
   Validate.isTrue(type != PotionType.WATER, "Water bottles don't have a level!");
   Validate.isTrue((level > 0) && (level < 3), "Level must be 1 or 2");
   this.level = level;
 }
  /**
   * Constructor
   *
   * @param name The name for the parameter. May not be <code>null</code>.
   * @param type The type for the parameter. May not be <code>null</code>.
   */
  public ParameterDefinition(String name, String type) {
    Validate.notNull(name);
    Validate.notNull(type);

    m_name = name;
    m_type = type;
  }
Esempio n. 23
0
 public boolean fileHasDependency(File file, File dependency) {
   Validate.notNull(file, "File can't be null");
   Validate.notNull(dependency, "Dependency can't be null");
   HierarchyNode fileNode = getNode(file);
   Validate.notNull(fileNode, "File isn't in hierarchy: " + file);
   return fileNode.containsDependency(dependency);
 }
  /**
   * Constructs a new {@link TestHandler} and reads the tests from the specified URL resource. It
   * uses the web client to run the tests.
   *
   * @param theBrowser The web client in which the tests will run. It cannot be null.
   * @param theTestFile QUnit test file. It cannot be null.
   * @throws java.net.MalformedURLException If the file path cannot be parsed as a URL
   */
  public TestHandler(final WebClient theBrowser, final URL theTestUrl) {
    Validate.notNull(theBrowser, "The web client cannot be null.");
    Validate.notNull(theTestUrl, "The test URL cannot be null.");

    browser = theBrowser;
    testUrl = theTestUrl;
  }
 /**
  * Computes the interest rate sensitivity of future price.
  *
  * @param future The future security.
  * @param curves The curves.
  * @return The curve sensitivity.
  */
 @Override
 public InterestRateCurveSensitivity priceCurveSensitivity(
     final FederalFundsFutureSecurity future, final YieldCurveBundle curves) {
   Validate.notNull(future, "Future");
   Validate.notNull(curves, "Curves");
   int nbFixing = future.getFixingPeriodAccrualFactor().length;
   YieldAndDiscountCurve ois = curves.getCurve(future.getOISCurveName());
   double[] df = new double[nbFixing + 1];
   for (int loopfix = 0; loopfix < nbFixing + 1; loopfix++) {
     df[loopfix] = ois.getDiscountFactor(future.getFixingPeriodTime()[loopfix]);
   }
   // Backward sweep
   double priceBar = 1.0;
   double interestBar = -1.0 / future.getFixingTotalAccrualFactor() * priceBar;
   double[] dfBar = new double[nbFixing + 1];
   for (int loopfix = 0; loopfix < nbFixing; loopfix++) {
     dfBar[loopfix] += 1.0 / df[loopfix + 1] * interestBar;
     dfBar[loopfix + 1] += -df[loopfix] / (df[loopfix + 1] * df[loopfix + 1]) * interestBar;
   }
   Map<String, List<DoublesPair>> resultMap = new HashMap<String, List<DoublesPair>>();
   List<DoublesPair> listOIS = new ArrayList<DoublesPair>();
   for (int loopfix = 0; loopfix < nbFixing + 1; loopfix++) {
     listOIS.add(
         new DoublesPair(
             future.getFixingPeriodTime()[loopfix],
             -future.getFixingPeriodTime()[loopfix] * df[loopfix] * dfBar[loopfix]));
   }
   resultMap.put(future.getOISCurveName(), listOIS);
   InterestRateCurveSensitivity result = new InterestRateCurveSensitivity(resultMap);
   return result;
 }
Esempio n. 26
0
  public <O extends ObjectType> O resolveObject(ObjectReferenceType ref) {
    Validate.notNull(ref.getOid(), "Object oid must not be null");
    Validate.notNull(ref.getType(), "Object type must not be null");

    Class type = prismContext.getSchemaRegistry().determineCompileTimeClass(ref.getType());
    return resolveObject(type, ref.getOid());
  }
  @Override
  public String setOutputProperty(String name, String value) {
    Validate.notEmpty(name, "name cannot be null");
    Validate.notEmpty(value, "value cannot be null");

    return this.outputProperties.put(name, value);
  }
  /** Creates the InmutableURIAndCtx. */
  public InmutableURIAndCtx(final URI uri, final Map<String, Object> ctx) {
    Validate.notNull(uri);
    Validate.notNull(ctx);

    this.uri = uri;
    this.ctx = Collections.unmodifiableMap(ctx);
  }
 @Override
 public Double visitVarianceSwap(
     final VarianceSwap derivative, final EquityOptionDataBundle market) {
   Validate.notNull(market);
   Validate.notNull(derivative);
   return PRICER.presentValue(derivative, market);
 }
  /**
   * This calculates the sensitivity of the present value (PV) to a unit move in the forward. The
   * volatility surface remains unchanged.
   *
   * @param swap the VarianceSwap
   * @param market the VarianceSwapDataBundle
   * @param relShift Relative size of shift made in centered-finite difference approximation.
   * @return A Double. Currency amount per unit amount change in the black volatility
   */
  @SuppressWarnings({})
  public Double calcForwardSensitivity(
      final VarianceSwap swap, final VarianceSwapDataBundle market, final double relShift) {
    Validate.notNull(swap, "null VarianceSwap");
    Validate.notNull(market, "null VarianceSwapDataBundle");

    final VarianceSwapPresentValueCalculator pricer =
        VarianceSwapPresentValueCalculator.getInstance();

    // Shift UP
    VarianceSwapDataBundle bumpedMarket =
        new VarianceSwapDataBundle(
            market.getVolatilitySurface(),
            market.getDiscountCurve(),
            market.getForwardCurve().withFractionalShift(relShift));
    final double pvUp = pricer.visitVarianceSwap(swap, bumpedMarket);

    // Shift Down
    bumpedMarket =
        new VarianceSwapDataBundle(
            market.getVolatilitySurface(),
            market.getDiscountCurve(),
            market.getForwardCurve().withFractionalShift(-relShift));
    final double pvDown = pricer.visitVarianceSwap(swap, bumpedMarket);

    final double t = swap.getTimeToSettlement();
    final double fwd = market.getForwardCurve().getForward(t);
    // Centered-difference result
    return (pvUp - pvDown) / 2.0 / relShift / fwd;
  }