Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you 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 org.openqa.selenium.htmlunit.w3;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.openqa.selenium.htmlunit.HtmlUnitInputProcessor;
import org.openqa.selenium.htmlunit.HtmlUnitWebElement;
import org.openqa.selenium.interactions.Sequence;
/**
* To follow the spec as close as possible we have this collection of mehtods
* and no object oriented design.
*
* @author Ronald Brill
* @author Scott Babcock
*/
public final class Algorithms {
/**
* Private ctor because this class offers only static functions.
*/
private Algorithms() {
}
/**
* @see extract
* an action sequence
*
* @param sequences the sequences
* @return actions by tick
*/
public static List> extractActionSequence(
final Collection sequences /* InputState inputState, parameters */) {
// Let actions by tick be an empty List.
final List> actionsByTick = new ArrayList<>();
// For each value action sequence corresponding to an indexed property in
// actions:
for (final Sequence sequence : sequences) {
final Map actionSequence = sequence.encode();
// Let source actions be the result of trying to process an input source action
// sequence given input state and action sequence.
final ArrayList sourceActions = processInputSourceActionSequence(actionSequence);
// For each action in source actions:
// Let i be the zero-based index of action in source actions.
for (int i = 0; i < sourceActions.size(); i++) {
final Action action = sourceActions.get(i);
// If the length of actions by tick is less than i + 1, append a new List to
// actions by tick.
if (actionsByTick.size() < i + 1) {
actionsByTick.add(new ArrayList<>());
}
// Append action to the List at index i in actions by tick.
actionsByTick.get(i).add(action);
}
}
// Return success with data actions by tick.
return actionsByTick;
}
/**
* @see process
* an input source action sequence
*/
private static ArrayList processInputSourceActionSequence(final Map actionSequence) {
// Let type be the result of getting a property named "type" from action
// sequence.
final String type = actionSequence.get("type").toString();
// If type is not "key", "pointer", "wheel", or "none", return an error with
// error code invalid argument.
// Let id be the result of getting the property "id" from action sequence.
final Object id = actionSequence.get("id");
// If id is undefined or is not a String, return error with error code invalid
// argument.
// If type is equal to "pointer", let parameters data be the result of getting
// the
// property "parameters" from action sequence.
// Then let parameters be the result of trying to process pointer parameters
// with argument parameters data.
Map parameters = null;
if ("pointer".equals(type)) {
final Map parametersData = (Map) actionSequence.get("parameters");
parameters = processPointerParameters(parametersData);
}
// Let source be the result of trying to get or create an input source given
// input state, type and id.
// InputSource source = new InputSource(inputState, type, id);
// If parameters is not undefined, then if its pointerType property is not equal
// to
// source’s subtype property, return an error with error code invalid argument.
// Let action items be the result of getting a property named actions from
// action sequence.
final List