static void nashornCompiledScript(String code) throws ScriptException, NoSuchMethodException { ScriptEngineManager factory = new ScriptEngineManager(); ScriptEngine engine = factory.getEngineByName("nashorn"); CompiledScript compiled = ((Compilable) engine).compile(code); Object result = null; ScriptContext context = new SimpleScriptContext(); Bindings engineScope = context.getBindings(ScriptContext.ENGINE_SCOPE); long total = 0; for (int i = 0; i < RUNS; ++i) { long start = System.nanoTime(); for (int j = 0; j < BATCH; ++j) { engineScope.put("value", "12345678"); result = compiled.eval(context); } long stop = System.nanoTime(); System.out.println( "Run " + (i * BATCH + 1) + "-" + ((i + 1) * BATCH) + ": " + Math.round((stop - start) / BATCH / 1000) + " us"); total += (stop - start); } System.out.println("Average run: " + Math.round(total / RUNS / BATCH / 1000) + " us"); System.out.println( "Data is " + ((Invocable) engine).invokeMethod(result, "toString").toString()); }
public double[] fitfunc(double[] fitparams) { Bindings b = engine.createBindings(); for (int i = 0; i < 10; i++) b.put("P" + (i + 1), fitparams[i]); /*String script1="P1="+fitparams[0]+"; "+ "P2="+fitparams[1]+"; "+ "P3="+fitparams[2]+"; "+ "P4="+fitparams[3]+"; "+ "P5="+fitparams[4]+"; "+ "P6="+fitparams[5]+"; "+ "P7="+fitparams[6]+"; "+ "P8="+fitparams[7]+"; "+ "P9="+fitparams[8]+"; "+ "P10="+fitparams[9]+"; "+ exdef+"; x="; String script2="; retval="+function+";";*/ try { double[] temp = new double[tempx.length]; for (int i = 0; i < tempx.length; i++) { // temp[i]=((Double)engine.eval(script1+(double)tempx[i]+script2)).doubleValue(); b.put("x", tempx[i]); b.put("y", tempdata[i]); temp[i] = (Double) cs.eval(b); } return temp; } catch (Exception e) { IJ.log(e.getMessage()); return null; } }
@Test public void putNullRefOnBindings() throws ScriptException { Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE); bindings.put("x", null); assertThat(engine.eval("is.null(x)"), CoreMatchers.<Object>equalTo(LogicalVector.TRUE)); }
/** Initializes the controller class. */ @Override public void initialize(URL url, ResourceBundle rb) { logger.entry(); OkButton.disableProperty() .bind( Bindings.isEmpty(FederationExecutionName.textProperty()) .or(Bindings.isEmpty(FederateType.textProperty()))); logger.exit(); }
private static void typeCastContextBindings(final ScriptContext context) { for (int scope : context.getScopes()) { Bindings bindings = context.getBindings(scope); if (!(bindings instanceof VariableLibrary) && null != bindings) { for (String key : bindings.keySet()) { Object object = bindings.get(key); if (object instanceof Atom) { bindings.put(key, ((Atom) object).getValue()); } } } } }
private Bindings getBindings(Execution execution, JCRSessionWrapper session) throws RepositoryException { EnvironmentImpl environment = EnvironmentImpl.getCurrent(); final Map<String, Object> vars = ((ExecutionImpl) execution).getVariables(); Locale locale = (Locale) vars.get("locale"); final Bindings bindings = new MyBindings(environment); ResourceBundle resourceBundle = JahiaResourceBundle.lookupBundle( "org.jahia.services.workflow." + ((ExecutionImpl) execution).getProcessDefinition().getKey(), locale); bindings.put("bundle", resourceBundle); JahiaUser jahiaUser = ServicesRegistry.getInstance() .getJahiaUserManagerService() .lookupUserByKey((String) vars.get("user")); bindings.put("user", jahiaUser); bindings.put("date", new DateTool()); bindings.put("submissionDate", Calendar.getInstance()); bindings.put("locale", locale); bindings.put("workspace", vars.get("workspace")); List<JCRNodeWrapper> nodes = new LinkedList<JCRNodeWrapper>(); @SuppressWarnings("unchecked") List<String> stringList = (List<String>) vars.get("nodeIds"); for (String s : stringList) { JCRNodeWrapper nodeByUUID = session.getNodeByUUID(s); if (!nodeByUUID.isNodeType("jnt:translation")) { nodes.add(nodeByUUID); } } bindings.put("nodes", nodes); return bindings; }
/** * Perform mediation with static inline script of the given scripting language * * @param synCtx message context * @return true, or the script return value * @throws ScriptException For any errors , when compile , run the script */ private Object mediateForInlineScript(MessageContext synCtx) throws ScriptException { ScriptMessageContext scriptMC = new ScriptMessageContext(synCtx, xmlHelper); processJSONPayload(synCtx, scriptMC); Bindings bindings = scriptEngine.createBindings(); bindings.put(MC_VAR_NAME, scriptMC); Object response; if (compiledScript != null) { response = compiledScript.eval(bindings); } else { response = scriptEngine.eval(scriptSourceCode, bindings); } return response; }
public boolean visit(SimpleName node) { if (fIgnoreBinding != null && Bindings.equals(fIgnoreBinding, node.resolveBinding())) return false; if (fIgnoreRange != null && fIgnoreRange.covers(node)) return false; fScope.addName(node.getIdentifier()); return false; }
private void initializeFilteredPersonnelTableView() { personnelNameColumn.setCellValueFactory(new PropertyValueFactory<Official, String>("name")); personnelRankColumn.setCellValueFactory( new Callback<TableColumn.CellDataFeatures<Official, String>, ObservableValue<String>>() { @Override public ObservableValue<String> call(CellDataFeatures<Official, String> arg0) { final Official official = arg0.getValue(); final StringExpression concat = Bindings.selectString(official.rankProperty(), "designation"); return concat; } }); Bindings.bindContent(officialsFilteredTableView.getItems(), officialFilteredList); gameData .getOfficials() .addListener( new ListChangeListener<Official>() { @Override public void onChanged(Change<? extends Official> arg0) { updateOfficialFiltersResult(); } }); // TODO initialize assignOfficialMenuItem to be sure that it's not // enable if not correct values are selected }
public boolean isDeclaredInScope(IBinding declaration, SimpleName selector, int flags) { try { // special case for switch on enum if (selector.getLocationInParent() == SwitchCase.EXPRESSION_PROPERTY) { ITypeBinding binding = ((SwitchStatement) selector.getParent().getParent()) .getExpression() .resolveTypeBinding(); if (binding != null && binding.isEnum()) { return hasEnumContants(declaration, binding.getTypeDeclaration()); } } ITypeBinding parentTypeBinding = Bindings.getBindingOfParentTypeContext(selector); if (parentTypeBinding != null) { ITypeBinding binding = getQualifier(selector); SearchRequestor requestor = new SearchRequestor(declaration, parentTypeBinding, flags); if (binding == null) { addLocalDeclarations(selector, flags, requestor); if (requestor.found()) return requestor.isVisible(); addTypeDeclarations(parentTypeBinding, flags, requestor); if (requestor.found()) return requestor.isVisible(); } else { addInherited(binding, flags, requestor); if (requestor.found()) return requestor.isVisible(); } } return false; } finally { clearLists(); } }
public IBinding[] getDeclarationsInScope(SimpleName selector, int flags) { try { // special case for switch on enum if (selector.getLocationInParent() == SwitchCase.EXPRESSION_PROPERTY) { ITypeBinding binding = ((SwitchStatement) selector.getParent().getParent()) .getExpression() .resolveTypeBinding(); if (binding != null && binding.isEnum()) { return getEnumContants(binding); } } ITypeBinding parentTypeBinding = Bindings.getBindingOfParentType(selector); if (parentTypeBinding != null) { ITypeBinding binding = getQualifier(selector); DefaultBindingRequestor requestor = new DefaultBindingRequestor(parentTypeBinding, flags); if (binding == null) { addLocalDeclarations(selector, flags, requestor); addTypeDeclarations(parentTypeBinding, flags, requestor); } else { addInherited(binding, flags, requestor); } List<IBinding> result = requestor.getResult(); return result.toArray(new IBinding[result.size()]); } return NO_BINDING; } finally { clearLists(); } }
public boolean acceptBinding(IBinding binding) { if (fFound) return true; if (binding == null) return false; if (fToSearch.getKind() != binding.getKind()) { return false; } boolean checkVisibility = hasFlag(CHECK_VISIBILITY, fFlags); if (binding == fToSearch) { fFound = true; } else { IBinding bindingDeclaration = Bindings.getDeclaration(binding); if (bindingDeclaration == fToSearch) { fFound = true; } else if (bindingDeclaration.getName().equals(fToSearch.getName())) { String signature = getSignature(bindingDeclaration); if (signature != null && signature.equals(getSignature(fToSearch))) { if (checkVisibility) { fIsVisible = false; } return true; // found element that hides the binding to find } } } if (fFound && checkVisibility) { fIsVisible = ScopeAnalyzer.isVisible(binding, fParentTypeBinding); } return fFound; }
public IBinding[] getDeclarationsInScope(int offset, int flags) { org.eclipse.che.ide.ext.java.jdt.core.dom.NodeFinder finder = new org.eclipse.che.ide.ext.java.jdt.core.dom.NodeFinder(fRoot, offset, 0); ASTNode node = finder.getCoveringNode(); if (node == null) { return NO_BINDING; } if (node instanceof SimpleName) { return getDeclarationsInScope((SimpleName) node, flags); } try { ITypeBinding binding = Bindings.getBindingOfParentType(node); DefaultBindingRequestor requestor = new DefaultBindingRequestor(binding, flags); addLocalDeclarations(node, offset, flags, requestor); if (binding != null) { addTypeDeclarations(binding, flags, requestor); } List<IBinding> result = requestor.getResult(); return result.toArray(new IBinding[result.size()]); } finally { clearLists(); } }
private static ITypeBinding getQualifier(SimpleName selector) { ASTNode parent = selector.getParent(); switch (parent.getNodeType()) { case ASTNode.METHOD_INVOCATION: MethodInvocation decl = (MethodInvocation) parent; if (selector == decl.getName()) { return getBinding(decl.getExpression()); } return null; case ASTNode.QUALIFIED_NAME: QualifiedName qualifiedName = (QualifiedName) parent; if (selector == qualifiedName.getName()) { return getBinding(qualifiedName.getQualifier()); } return null; case ASTNode.FIELD_ACCESS: FieldAccess fieldAccess = (FieldAccess) parent; if (selector == fieldAccess.getName()) { return getBinding(fieldAccess.getExpression()); } return null; case ASTNode.SUPER_FIELD_ACCESS: { ITypeBinding curr = Bindings.getBindingOfParentType(parent); return curr.getSuperclass(); } case ASTNode.SUPER_METHOD_INVOCATION: { SuperMethodInvocation superInv = (SuperMethodInvocation) parent; if (selector == superInv.getName()) { ITypeBinding curr = Bindings.getBindingOfParentType(parent); return curr.getSuperclass(); } return null; } default: if (parent instanceof Type) { // bug 67644: in 'a.new X()', all member types of A are visible as location of X. ASTNode normalizedNode = ASTNodes.getNormalizedNode(parent); if (normalizedNode.getLocationInParent() == ClassInstanceCreation.TYPE_PROPERTY) { ClassInstanceCreation creation = (ClassInstanceCreation) normalizedNode.getParent(); return getBinding(creation.getExpression()); } } return null; } }
public boolean visit(FunctionInvocation node) { Expression receiver = node.getExpression(); if (receiver == null) { SimpleName name = node.getName(); if (fIgnoreBinding == null || (name != null && !Bindings.equals(fIgnoreBinding, name.resolveBinding()))) node.getName().accept(this); } else { receiver.accept(this); } accept(node.arguments()); return false; }
private boolean addOuterDeclarationsForLocalType( ITypeBinding localBinding, int flags, IBindingRequestor requestor) { ASTNode node = fRoot.findDeclaringNode(localBinding); if (node == null) { return false; } if (node instanceof AbstractTypeDeclaration || node instanceof AnonymousClassDeclaration) { if (addLocalDeclarations(node.getParent(), flags, requestor)) return true; ITypeBinding parentTypeBinding = Bindings.getBindingOfParentType(node.getParent()); if (parentTypeBinding != null) { if (addTypeDeclarations(parentTypeBinding, flags, requestor)) return true; } } return false; }
/* */ public BooleanBinding isNotEqualTo(ObservableBooleanValue paramObservableBooleanValue) /* */ { /* 160 */ return Bindings.notEqual(this, paramObservableBooleanValue); /* */ }
/** * This method adds all triples of a given Bindings to the internal list of read triples for these * bindings. This method must be overridden by Bindings-subclasses, which support this feature, * e.g. BindingsArrayReadTriples */ @Override public void addAllTriples(final Bindings bindings) { addAllTriples(bindings.getTriples()); }
/* */ public BooleanBinding isNotEqualTo(Object paramObject) /* */ { /* 143 */ return Bindings.notEqual(this, paramObject); /* */ }
/* */ public BooleanBinding isNotEqualTo(ObservableObjectValue<?> paramObservableObjectValue) /* */ { /* 131 */ return Bindings.notEqual(this, paramObservableObjectValue); /* */ }
/* */ public BooleanBinding isEqualTo(Object paramObject) /* */ { /* 117 */ return Bindings.equal(this, paramObject); /* */ }
/* */ public BooleanBinding not() /* */ { /* 132 */ return Bindings.not(this); /* */ }
private void initializeSkillFilterTab() { skillFilterComboBox.getItems().addAll(skills); PropertyListCellFactory<Skill> propertyListCellFactory = new PropertyListCellFactory<>("name", null); skillFilterComboBox.setButtonCell( new ListCell<Skill>() { @Override protected void updateItem(Skill arg0, boolean arg1) { super.updateItem(arg0, arg1); if (arg1 || arg0 == null) { this.setText(null); } else { this.setText(arg0.getName()); } } }); skillFilterComboBox.setCellFactory(propertyListCellFactory); skillFiltersNameColumn.setCellValueFactory( new Callback<CellDataFeatures<SkillFilter, String>, ObservableValue<String>>() { @Override public ObservableValue<String> call(CellDataFeatures<SkillFilter, String> arg0) { return Bindings.selectString(arg0.getValue().skillProperty(), "name"); } }); skillFilterMinValueColumn.setCellValueFactory( new PropertyValueFactory<SkillFilter, Integer>("minValue")); skillFilterMaxValueColumn.setCellValueFactory( new PropertyValueFactory<SkillFilter, Integer>("maxValue")); skillFiltersTableView .getItems() .addListener( new ListChangeListener<SkillFilter>() { @Override public void onChanged(Change<? extends SkillFilter> arg0) { while (arg0.next()) { for (SkillFilter skillFilter : arg0.getAddedSubList()) { final Skill skill = skillFilter.getSkill(); TableColumn<Official, Number> skillColumn = new TableColumn<>(skill.getName()); skillColumn.setCellValueFactory( new Callback< CellDataFeatures<Official, Number>, ObservableValue<Number>>() { @Override public ObservableValue<Number> call( CellDataFeatures<Official, Number> arg0) { Official official = arg0.getValue(); IntegerBinding selectInteger = Bindings.selectInteger( official.skillLevelsProperty().valueAt(skill), "level"); selectInteger.addListener( new ChangeListener<Number>() { @Override public void changed( ObservableValue<? extends Number> arg0, Number arg1, Number arg2) { updateOfficialFiltersResult(); } }); return selectInteger; } }); officialsFilteredTableView.getColumns().add(skillColumn); skillFiltersColumn.put(skill, skillColumn); } for (SkillFilter skillFilter : arg0.getRemoved()) { final Skill skill = skillFilter.getSkill(); TableColumn<Official, Number> column = skillFiltersColumn.remove(skill); if (column != null) { officialsFilteredTableView.getColumns().remove(column); } } } } }); Bindings.bindContent(skillFiltersMatcher.getMatchers(), skillFiltersTableView.getItems()); }
@Override // This method is called by the FXMLLoader when initialization is complete public void initialize(URL fxmlFileLocation, ResourceBundle resources) { assert civilianAdministratorCheckBox != null : "fx:id=\"civilianAdministratorCheckBox\" was not injected: check your FXML file 'PersonnelManagementScreen.fxml'."; assert officialsFilteredTableView != null : "fx:id=\"filteredPersonnelTableView\" was not injected: check your FXML file 'PersonnelManagementScreen.fxml'."; assert groundOfficerFilterCheckBox != null : "fx:id=\"groundOfficerFilterCheckBox\" was not injected: check your FXML file 'PersonnelManagementScreen.fxml'."; assert navalOfficerFilterCheckBox != null : "fx:id=\"navalOfficerFilterCheckBox\" was not injected: check your FXML file 'PersonnelManagementScreen.fxml'."; assert personnelNameColumn != null : "fx:id=\"personnelNameColumn\" was not injected: check your FXML file 'PersonnelManagementScreen.fxml'."; assert personnelRankColumn != null : "fx:id=\"personnelRankColumn\" was not injected: check your FXML file 'PersonnelManagementScreen.fxml'."; assert scientistFilterCheckBox != null : "fx:id=\"scientistFilterCheckBox\" was not injected: check your FXML file 'PersonnelManagementScreen.fxml'."; assert skillFilterComboBox != null : "fx:id=\"skillFilterComboBox\" was not injected: check your FXML file 'PersonnelManagementScreen.fxml'."; assert skillFilterMaxValueColumn != null : "fx:id=\"skillFilterMaxValueColumn\" was not injected: check your FXML file 'PersonnelManagementScreen.fxml'."; assert skillFilterMaxValueComponent != null : "fx:id=\"skillFilterMaxValueComponent\" was not injected: check your FXML file 'PersonnelManagementScreen.fxml'."; assert skillFilterMinValueColumn != null : "fx:id=\"skillFilterMinValueColumn\" was not injected: check your FXML file 'PersonnelManagementScreen.fxml'."; assert skillFilterMinValueComponent != null : "fx:id=\"skillFilterMinValueComponent\" was not injected: check your FXML file 'PersonnelManagementScreen.fxml'."; assert skillFiltersNameColumn != null : "fx:id=\"skillFiltersNameColumn\" was not injected: check your FXML file 'PersonnelManagementScreen.fxml'."; assert skillFiltersTableView != null : "fx:id=\"skillFiltersTableView\" was not injected: check your FXML file 'PersonnelManagementScreen.fxml'."; assert assignmentsFilterComboBox != null; assert assigmentsListView != null; assert createTeamMenuItem != null : "fx:id=\"createTeamMenuItem\" was not injected: check your FXML file 'PersonnelManagementScreen.fxml'."; assert assignOfficialMenuItem != null; assert skillsTableView != null : "fx:id=\"skillsTableView\" was not injected: check your FXML file 'PersonnelManagementScreen.fxml'."; assert skillColumn != null : "fx:id=\"skillColumn\" was not injected: check your FXML file 'PersonnelManagementScreen.fxml'."; assert levelColumn != null : "fx:id=\"levelColumn\" was not injected: check your FXML file 'PersonnelManagementScreen.fxml'."; // initialize your logic here: all @FXML variables will have been // injected initializeCompositeMatcher(); initializeFilteredPersonnelTableView(); initializeSkillFilterTab(); initializeAssignmentListViewAndFilters(); createTeamMenuItem .disableProperty() .bind( Bindings.select(officialsFilteredTableView.selectionModelProperty(), "selectedItem") .isNull()); final ObjectBinding<Official> selectedPersonnel = Bindings.select(officialsFilteredTableView.selectionModelProperty(), "selectedItem"); detailsPaneController .officialProperty() .bind(officialsFilteredTableView.getSelectionModel().selectedItemProperty()); skillColumn.setCellValueFactory( new Callback<CellDataFeatures<SkillLevel, String>, ObservableValue<String>>() { public ObservableValue<String> call(CellDataFeatures<SkillLevel, String> p) { SkillLevel value = p.getValue(); return Bindings.selectString(value, "skill", "name"); } }); levelColumn.setCellValueFactory(new PropertyValueFactory<SkillLevel, Integer>("level")); selectedPersonnel.addListener( new ChangeListener<Official>() { @Override public void changed( ObservableValue<? extends Official> arg0, Official arg1, Official arg2) { updateSkills(); } }); updateOfficialFiltersResult(); }
/* */ public BooleanBinding isEqualTo(ObservableBooleanValue paramObservableBooleanValue) /* */ { /* 146 */ return Bindings.equal(this, paramObservableBooleanValue); /* */ }
/* */ public BooleanBinding and(ObservableBooleanValue paramObservableBooleanValue) /* */ { /* 107 */ return Bindings.and(this, paramObservableBooleanValue); /* */ }
/* */ public BooleanBinding isNotNull() /* */ { /* 163 */ return Bindings.isNotNull(this); /* */ }
protected void removeBinding1(ResourceAddress address, NextProtocolBinding binding) { super.removeBinding0(address, binding); }
/* */ public BooleanBinding or(ObservableBooleanValue paramObservableBooleanValue) /* */ { /* 122 */ return Bindings.or(this, paramObservableBooleanValue); /* */ }