public void moveToHistory(Step step) { List currentSteps = (List) SerializableCache.getInstance().currentStepsCache.get(new Long(step.getEntryId())); List historySteps = (List) SerializableCache.getInstance().historyStepsCache.get(new Long(step.getEntryId())); if (historySteps == null) { historySteps = new ArrayList(); SerializableCache.getInstance() .historyStepsCache .put(new Long(step.getEntryId()), historySteps); } SimpleStep simpleStep = (SimpleStep) step; for (Iterator iterator = currentSteps.iterator(); iterator.hasNext(); ) { Step currentStep = (Step) iterator.next(); if (simpleStep.getId() == currentStep.getId()) { iterator.remove(); historySteps.add(simpleStep); break; } } SerializableCache.store(); }
@Override public void populateTextViews(View currView, Step currIterStep) { // Set tag to hold step number --> use as an ID to determine which step to highlight currView.setTag(R.id.stepNumber, currIterStep.getStepNumber()); // Bind TextView references // Note: These TextViews are created in the XML files we defined. TextView stepNumView = (TextView) currView.findViewById(R.id.stepListItem_stepNum); TextView stepTitleView = (TextView) currView.findViewById(R.id.stepListItem_stepTitle); TextView stepTimeView = (TextView) currView.findViewById(R.id.stepListItem_stepTimeTakes); // Populate views with data if (stepNumView != null) { stepNumView.setText(String.valueOf(currIterStep.getStepNumber())); } if (stepTitleView != null) { stepTitleView.setText(currIterStep.getTitle()); } if (stepTimeView != null) { stepTimeView.setText(currIterStep.getTime()); } // Highlight the first step if (currIterStep.getStepNumber() == 1) { AssistantActivity.updateStepListItemColors( currView, R.color.orange, R.color.light_orange, getContext().getResources().getColor(R.color.orange)); ; } }
private Predicates getPredicates(Step step, Traversal.Admin traversal) { Predicates predicates = new Predicates(); Step<?, ?> nextStep = step.getNextStep(); while (true) { if (nextStep instanceof HasContainerHolder) { HasContainerHolder hasContainerHolder = (HasContainerHolder) nextStep; boolean skip = false; for (HasContainer has : hasContainerHolder.getHasContainers()) if (has.getPredicate().getTraversals().size() > 0) skip = true; if (!skip) { hasContainerHolder.getHasContainers().forEach((has) -> predicates.hasContainers.add(has)); nextStep.getLabels().forEach(label -> predicates.labels.add(label.toString())); traversal.removeStep(nextStep); } } else if (nextStep instanceof RangeGlobalStep) { RangeGlobalStep rangeGlobalStep = (RangeGlobalStep) nextStep; predicates.limitLow = rangeGlobalStep.getLowRange(); predicates.limitHigh = rangeGlobalStep.getHighRange(); traversal.removeStep(nextStep); } else return predicates; nextStep = nextStep.getNextStep(); } }
@Override public final Expr optimize(final QueryContext qc, final VarScope scp) throws QueryException { final Value v = initial(qc); if (v != null && v.isEmpty() || emptyPath(v)) return optPre(qc); // merge descendant steps Expr e = mergeSteps(qc); if (e == this && v != null && v.type == NodeType.DOC) { // check index access e = index(qc, v); // rewrite descendant to child steps if (e == this) e = children(qc, v); } // recompile path if it has changed if (e != this) return e.compile(qc, scp); // set atomic type for single attribute steps to speed up predicate tests if (root == null && steps.length == 1 && steps[0] instanceof Step) { final Step curr = (Step) steps[0]; if (curr.axis == ATTR && curr.test.kind == Kind.URI_NAME) curr.seqType(SeqType.NOD_ZO); } // choose best path implementation and set type information final Path path = get(info, root, steps); path.size = path.size(qc); path.seqType = SeqType.get(steps[steps.length - 1].seqType().type, size); return path; }
public Step selectStep(int stepId) throws Exception { SQLiteDatabase database = dbHelper.getReadableDatabase(); Step result = new Step(); try { Cursor cur = database.query( DbHelper.STEPS, new String[] { DbHelper.STEP_ID, DbHelper.STEP_NAME, DbHelper.STEP_ORDINAL, DbHelper.STEP_SECONDS }, DbHelper.STEP_ID + "=?", new String[] {Integer.toString(stepId)}, null, null, DbHelper.STEP_ID); if (!cur.moveToFirst()) { throw new Exception("No step found with step identity of " + Integer.toString(stepId)); } result.setId(cur.getInt(0)); result.setName(cur.getString(1)); result.setOrdinal(cur.getInt(2)); result.setDurationSeconds(cur.getLong(3)); } catch (Exception e) { database.close(); throw e; } database.close(); return result; }
/** * Computes the number of results. * * @param qc query context (may be @code null) * @return number of results */ private long size(final QueryContext qc) { final Value rt = initial(qc); // skip computation if value is not a document node if (rt == null || rt.type != NodeType.DOC) return -1; final Data data = rt.data(); // skip computation if no database instance is available, is out-of-date or // if context does not contain all database nodes if (data == null || !data.meta.uptodate || data.resources.docs().size() != rt.size()) return -1; ArrayList<PathNode> nodes = data.paths.root(); long m = 1; final int sl = steps.length; for (int s = 0; s < sl; s++) { final Step curr = axisStep(s); if (curr != null) { nodes = curr.nodes(nodes, data); if (nodes == null) return -1; } else if (s + 1 == sl) { m = steps[s].size(); } else { // stop if a non-axis step is not placed last return -1; } } long sz = 0; for (final PathNode pn : nodes) sz += pn.stats.count; return sz * m; }
public boolean isFluent() { if (description.getTestMethod() != null) { Step step = description.getTestMethod().getAnnotation(Step.class); return ((step != null) && (step.fluent())); } return false; }
/** * Checks if the expressions is a simple child step. * * @param expr expression to be checked * @return result of check */ private boolean simpleChild(final Expr expr) { if (expr instanceof Step) { final Step n = (Step) expr; if (n.axis == CHILD && !n.has(Flag.FCS)) return true; } return false; }
public int get(Step s) { Node n = nodes[(0x7F_FF_FF_FF & s.hashCode()) % size]; while (!s.equals(n.key)) { n = n.next; } return n.value; }
public void add(Step s, int value) { Node n = nodes[(0x7F_FF_FF_FF & s.hashCode()) % size]; while (!s.equals(n.key)) { n = n.next; } n.value += value; }
/** * {@inheritDoc} * * @see * org.eclipse.emf.eef.codegen.flow.Step#setResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) */ public void setResourceSet(ResourceSet resourceSet) { super.setResourceSet(resourceSet); thenStep.setResourceSet(resourceSet); if (elseStep != null) { elseStep.setResourceSet(resourceSet); } }
/** * {@inheritDoc} * * @see * org.eclipse.emf.eef.codegen.flow.Step#setContext(org.eclipse.emf.eef.codegen.flow.var.WorkflowContext) */ public void setContext(WorkflowContext context) { super.setContext(context); thenStep.setContext(context); if (elseStep != null) { elseStep.setContext(context); } }
@When("process will be executed") protected void executeProcess(TestDataCollector testDataCollector) throws StepVerificationException { for (Step step : testSteps) { step.verifyAndPerform(testDataCollector); } }
private Optional<String> getNameFromStepAnnotationIn(final Method testMethod) { Step step = testMethod.getAnnotation(Step.class); if ((step != null) && (!StringUtils.isEmpty(step.value()))) { return Optional.of(injectAnnotatedFieldValuesFrom(description).into(step.value())); } return Optional.absent(); }
private static boolean nodeInStep(List<Step> steps, Node node) { for (Step step : steps) { if (step.contains(node)) { return true; } } return false; }
public static List<String[]> getAutoStartOrder(CubeDockerConfiguration config) { List<String[]> sorted = new ArrayList<>(); List<Step> steps = sort(from(config)); for (Step step : steps) { sorted.add(step.getIDs()); } return sorted; }
/** * Converts descendant to child steps. * * @param qc query context * @param rt root value * @return original or new expression */ private Expr children(final QueryContext qc, final Value rt) { // skip if index does not exist or is out-dated, or if several namespaces occur in the input final Data data = rt.data(); if (data == null || !data.meta.uptodate || data.nspaces.globalNS() == null) return this; Path path = this; final int sl = steps.length; for (int s = 0; s < sl; s++) { // don't allow predicates in preceding location steps final Step prev = s > 0 ? axisStep(s - 1) : null; if (prev != null && prev.preds.length != 0) break; // ignore axes other than descendant, or numeric predicates final Step curr = axisStep(s); if (curr == null || curr.axis != DESC || curr.has(Flag.FCS)) continue; // check if child steps can be retrieved for current step ArrayList<PathNode> nodes = pathNodes(data, s); if (nodes == null) continue; // cache child steps final ArrayList<QNm> qnm = new ArrayList<>(); while (nodes.get(0).parent != null) { QNm nm = new QNm(data.elemNames.key(nodes.get(0).name)); // skip children with prefixes if (nm.hasPrefix()) return this; for (final PathNode p : nodes) { if (nodes.get(0).name != p.name) nm = null; } qnm.add(nm); nodes = PathSummary.parent(nodes); } qc.compInfo(OPTCHILD, steps[s]); // build new steps int ts = qnm.size(); final Expr[] stps = new Expr[ts + sl - s - 1]; for (int t = 0; t < ts; t++) { final Expr[] preds = t == ts - 1 ? ((Preds) steps[s]).preds : new Expr[0]; final QNm nm = qnm.get(ts - t - 1); final NameTest nt = nm == null ? new NameTest(false) : new NameTest(nm, Kind.NAME, false, null); stps[t] = Step.get(info, CHILD, nt, preds); } while (++s < sl) stps[ts++] = steps[s]; path = get(info, root, stps); break; } // check if all steps yield results; if not, return empty sequence final ArrayList<PathNode> nodes = pathNodes(qc); if (nodes != null && nodes.isEmpty()) { qc.compInfo(OPTPATH, path); return Empty.SEQ; } return path; }
public void setSteps(List<Step> steps) { this._steps = steps; this._stepsMap = new HashMap<String, Step>(); Iterator<Step> stepsIter = steps.iterator(); while (stepsIter.hasNext()) { Step step = stepsIter.next(); this._stepsMap.put(step.getCode(), step); } }
/** * {@inheritDoc} * * @see org.eclipse.emf.eef.codegen.flow.Step#execute(org.eclipse.core.runtime.IProgressMonitor) */ public IStatus execute(IProgressMonitor monitor) { if (condition()) { return thenStep.execute(monitor); } else { if (elseStep != null) { return elseStep.execute(monitor); } } return Status.OK_STATUS; }
/** * Optimizes descendant-or-self steps and static types. * * @param ctx query context */ void optSteps(final QueryContext ctx) { boolean opt = false; Expr[] st = steps; for (int l = 1; l < st.length; ++l) { if (!(st[l - 1] instanceof Step && st[l] instanceof Step)) continue; final Step prev = (Step) st[l - 1]; final Step curr = (Step) st[l]; if (!prev.simple(DESCORSELF, false)) continue; if (curr.axis == CHILD && !curr.has(Flag.FCS)) { // descendant-or-self::node()/child::X -> descendant::X final int sl = st.length; final Expr[] tmp = new Expr[sl - 1]; System.arraycopy(st, 0, tmp, 0, l - 1); System.arraycopy(st, l, tmp, l - 1, sl - l); st = tmp; curr.axis = DESC; opt = true; } else if (curr.axis == ATTR && !curr.has(Flag.FCS)) { // descendant-or-self::node()/@X -> descendant-or-self::*/@X prev.test = new NameTest(false); opt = true; } } if (opt) ctx.compInfo(OPTDESC); // set atomic type for single attribute steps to speedup predicate tests if (root == null && st.length == 1 && st[0] instanceof Step) { final Step curr = (Step) st[0]; if (curr.axis == ATTR && curr.test.mode == Mode.STD) curr.type = SeqType.NOD_ZO; } steps = st; }
/** * {@inheritDoc} * * @see org.eclipse.emf.eef.codegen.flow.Step#validateExecution() */ public boolean validateExecution() { if (condition()) { return thenStep.validateExecution(); } else { if (elseStep != null) { return elseStep.validateExecution(); } else { return super.validateExecution(); } } }
public void addBlankStep(Step s) { if (theSteps.size() > 0) { Step lastStep = theSteps.get(theSteps.size() - 1); s.setStartLocation(lastStep.getEndLocation()); theSteps.add(s); } else { theSteps.add(s); startingLocation = s.getStartLocation(); // first step endingLocation = s.getEndLocation(); } }
@Test public void should_copy_step() throws Exception { // given final Step step = createStep(); // when final Step stepCopy = step.copy(); // then assertThat(stepCopy).isNotSameAs(step); assertThat(stepCopy).isEqualToComparingFieldByField(step); }
public static List<Step> hanoi(int numberOfDiscs, Step step) { List<Step> result = new ArrayList<Step>(); if (numberOfDiscs == 1) { result.add(step); } else { Step helpStep = getHelpStep(step); result.addAll(hanoi(numberOfDiscs - 1, helpStep)); result.add(step); result.addAll(hanoi(numberOfDiscs - 1, new Step(helpStep.getToPeg(), step.getToPeg()))); } return result; }
/** * Akin to {@link JenkinsRule#configRoundtrip(Builder)}. * * @param <S> step type * @param before the incoming step * @return the result after displaying in a form and resaving */ @SuppressWarnings("unchecked") public <S extends Step> S configRoundTrip(S before) throws Exception { FreeStyleProject p = rule.createFreeStyleProject(); p.getBuildersList().add(new StepBuilder(before)); // workaround for eclipse compiler Ambiguous method call p = (FreeStyleProject) rule.configRoundtrip((Item) p); StepBuilder b = p.getBuildersList().get(StepBuilder.class); assertNotNull(b); Step after = b.s; assertNotNull(after); assertEquals(before.getClass(), after.getClass()); return (S) after; }
static StepFailedException createForFailingStep( Step step, ExecutionContext context, int exitCode, Optional<BuildTarget> buildTarget) { String message; if (buildTarget.isPresent()) { message = String.format( "%s failed on step \"%s\" with exit code %d", buildTarget.get().getFullyQualifiedName(), step.getShortName(context), exitCode); } else { message = String.format("Failed with %d: %s", exitCode, step.getDescription(context)); } return new StepFailedException(message, step, exitCode); }
@Test public void should_change_status() throws Exception { // given final Step step = createStep(); final StepStatus newStatus = StepStatus.PASSED; // when step.setStatus(newStatus); // then assertThat(step.getStatus()).isEqualTo(newStatus); assertThat(step.getErrorMessage()).isNull(); }
protected void doPreviousAction() { // Commit data of current step final Step currentStep = mySteps.get(myCurrentStep); LOG.assertTrue(currentStep != null); try { currentStep._commit(false); } catch (final CommitStepException exc) { Messages.showErrorDialog(myContentPanel, exc.getMessage()); return; } myCurrentStep = getPreviousStep(myCurrentStep); updateStep(); }
/** * Returns the path nodes that will result from this path. * * @param qc query context * @return path nodes, or {@code null} if nodes cannot be evaluated */ public final ArrayList<PathNode> pathNodes(final QueryContext qc) { final Value init = initial(qc); final Data data = init != null && init.type == NodeType.DOC ? init.data() : null; if (data == null || !data.meta.uptodate) return null; ArrayList<PathNode> nodes = data.paths.root(); final int sl = steps.length; for (int s = 0; s < sl; s++) { final Step curr = axisStep(s); if (curr == null) return null; nodes = curr.nodes(nodes, data); if (nodes == null) return null; } return nodes; }
private void saveSteps(Routine routine, SQLiteDatabase database) { ContentValues values = new ContentValues(); int stepId = this.selectMaxStepId() + 1; int stepOrdinal = 1; for (Step step : routine.getSteps()) { values.clear(); values.put(DbHelper.STEP_ID, stepId); values.put(DbHelper.STEP_NAME, step.getName()); values.put(DbHelper.STEP_ORDINAL, stepOrdinal); values.put(DbHelper.STEP_SECONDS, step.getDurationSeconds()); values.put(DbHelper.STEP_ROUTINE_ID, routine.getId()); stepId++; stepOrdinal++; database.insertOrThrow(DbHelper.STEPS, null, values); } }