/** * @param name The name of the parameter. Not empty. * @param value The string value of the parameter. Not null. * @return The newly created subdialogue parameter */ public static Parameter createWithValue(String name, String value) { Assert.notNull(value, "value"); Parameter parameter = new Parameter(name); parameter.mValue = value; return parameter; }
/** * @param name The name of the parameter. Not empty. * @param expression The ECMAScript expression of the parameter. Not null. * @return The newly created subdialogue parameter */ public static Parameter createWithExpression(String name, String expression) { Assert.notNull(expression, "expression"); Parameter parameter = new Parameter(name); parameter.mExpression = expression; return parameter; }
private boolean isValidParameter( String name, ParameterType type, InterpolationType interp, int requestedSize, Parameter p) { if (p == null) return false; if (p.type != type) { UI.printWarning( Module.API, "Parameter %s requested as a %s - declared as %s", name, type.name().toLowerCase(), p.type.name().toLowerCase()); return false; } if (p.interp != interp) { UI.printWarning( Module.API, "Parameter %s requested as a %s - declared as %s", name, interp.name().toLowerCase(), p.interp.name().toLowerCase()); return false; } if (requestedSize > 0 && p.size() != requestedSize) { UI.printWarning( Module.API, "Parameter %s requires %d %s - declared with %d", name, requestedSize, requestedSize == 1 ? "value" : "values", p.size()); return false; } p.checked = true; return true; }
/** * Creates a parameter editor instance for the given parameter. * * @param parameter the parameter * @return the parameter editor, never null */ public static ParamEditor createParamEditor(Parameter parameter) { Guardian.assertNotNull("parameter", parameter); ParamProperties paramProps = parameter.getProperties(); Debug.assertNotNull(paramProps); ParamEditor editor = null; // Step 1: Try to create an editor from the 'editorClass' property // Class editorClass = paramProps.getEditorClass(); if (editorClass != null) { Constructor editorConstructor = null; try { editorConstructor = editorClass.getConstructor(Parameter.class); } catch (NoSuchMethodException e) { Debug.trace(e); } catch (SecurityException e) { Debug.trace(e); } if (editorConstructor != null) { try { editor = (ParamEditor) editorConstructor.newInstance(parameter); } catch (InstantiationException e) { Debug.trace(e); } catch (IllegalAccessException e) { Debug.trace(e); } catch (IllegalArgumentException e) { Debug.trace(e); } catch (InvocationTargetException e) { Debug.trace(e); } } } if (editor != null) { return editor; } // Step 2: Create a default editor based on the parameter's type info // if (parameter.isTypeOf(Boolean.class)) { editor = new BooleanEditor(parameter); } else if (parameter.isTypeOf(Color.class)) { editor = new ColorEditor(parameter); } else if (parameter.isTypeOf(File.class)) { editor = new FileEditor(parameter); } else if (paramProps.getValueSet() != null && paramProps.getValueSet().length > 0) { if (parameter.isTypeOf(String[].class)) { editor = new ListEditor(parameter); } else { editor = new ComboBoxEditor(parameter); } } // The last choice works always: a text field! if (editor == null) { editor = new TextFieldEditor(parameter); } return editor; }
public boolean runScript() throws Exception { int fuel = 0; int org = 0; int equip = 0; int holds = Swath.ship.holds(); // Set product amounts switch (m_type.getCurrentChoice()) { case Swath.FUEL_ORE: fuel = holds; break; case Swath.ORGANICS: org = holds; break; case Swath.EQUIPMENT: equip = holds; break; } // Loop while (true) { Land.exec(m_planet.getInteger()); TakeLeaveProducts.exec(fuel, org, equip); LiftOff.exec(); Trade.exec(-fuel, -org, -equip); } }
/** getCellsBinary */ private void createCells() { ConstraintDefinition constraint = model.createConstraintDefinition(template); // int count = template.parameterCount(); ActivityDefinitonCell[] cells = new ActivityDefinitonCell[constraint.parameterCount()]; // ActivityDefinition [] params = new ActivityDefinition [count]; double total = 0; int c = 0; for (Parameter parameter : constraint.getParameters()) { ActivityDefinition activityDefinition = model.addActivityDefinition(); activityDefinition.setName(parameter.getName()); // params[i] = activityDefinition; constraint.addBranch(parameter, activityDefinition); ActivityDefinitonCell activityDefinitionCell = view.getActivityDefinitionCell(activityDefinition); total = activityDefinitionCell.getWidth() + 10; cells[c++] = activityDefinitionCell; } double radius = total / 2 + 100; Point[] points = Circle.getPoints(radius, cells.length); for (int i = 0; i < cells.length; i++) { ActivityDefinitonCell cell = cells[i]; int x = points[i].x + (new Double(cell.getWidth() / 2)).intValue(); int y = points[i].y + (new Double(cell.getHeight() / 2)).intValue(); cell.setPosition(new Point(x, y)); } model.addConstraintDefiniton(constraint); }
/* 121: */ /* 122: */ public String toString() /* 123: */ { /* 124:148 */ int i = getElementCount(); /* 125: */ /* 126:150 */ StringBuffer localStringBuffer = new StringBuffer( getClass().getName() + ": \\\n" + " Array length in bytes: " + getLength() + " \\\n" + " Entry class name: " + (i > 0 ? getMember(0).getClass().getName() : "array is empty") + " \\\n" + " Entry count: " + i + " \\\n" + " Entries: \\\n{\n"); /* 127:159 */ for (int j = 0; j < i; j++) /* 128: */ { /* 129:161 */ Parameter localParameter = getMember(j); /* 130:162 */ String str = localParameter.toString(); /* 131:163 */ localStringBuffer.append(indent(str, 12)); /* 132:164 */ localStringBuffer.append("\n"); /* 133: */ } /* 134:167 */ localStringBuffer.append("}"); /* 135: */ /* 136:169 */ return localStringBuffer.toString(); /* 137: */ }
/** * DOC ggu Comment method "getFunctionMethod". * * @param f */ public static String getFunctionMethod(Function f) { String newValue = ""; // $NON-NLS-1$ if (f != null) { final List<Parameter> parameters = f.getParameters(); if (isJavaProject()) { String fullName = f.getClassName() + JAVA_METHOD_SEPARATED + f.getName(); newValue = fullName + FUN_PREFIX; for (Parameter pa : parameters) { newValue += pa.getValue() + FUN_PARAM_SEPARATED; } if (!parameters.isEmpty()) { newValue = newValue.substring(0, newValue.length() - 1); } newValue += FUN_SUFFIX; } else { newValue = f.getName() + FUN_PREFIX; for (Parameter pa : parameters) { newValue += pa.getValue() + FUN_PARAM_SEPARATED; } if (!parameters.isEmpty()) { newValue = newValue.substring(0, newValue.length() - 1); } newValue += FUN_SUFFIX; } } return newValue; }
public ReflectionPostAction( String name, ActionParser parser, Object o, Method m, Class<?>... clazzes) { this.name = name; this.o = o; this.m = m; this.deprecated = m.isAnnotationPresent(Deprecated.class); Class<?>[] ps = m.getParameterTypes(); Annotation[][] as = m.getParameterAnnotations(); items = new Param[ps.length]; for (int i = 0; i < ps.length; i++) { Annotation a = null; for (int j = 0; j < as[i].length; j++) { if (as[i][j].annotationType().equals(Parameter.class)) a = as[i][j]; } if (a != null) { Parameter v = (Parameter) a; String pname = v.value(); Converter<?> converter = parser.getConverter(ps[i]); if (converter == null) throw new NullPointerException("for " + m + " parameter " + i); items[i] = new RequestParameter(pname, converter); } else { for (int j = 0; j < clazzes.length; j++) if (ps[i].equals(clazzes[j])) items[i] = new StaticParameter(j); if (ps[i].equals(HttpServletRequest.class)) items[i] = new ServletRequestParameter(); } if (items[i] == null) throw new NullPointerException("for " + m + " parameter " + i); } }
/** * Adds the necessary field and methods to support resource locating. * * @param declaringClass the class to which we add the support field and methods */ public static void apply(@Nonnull ClassNode declaringClass, @Nullable String beanName) { injectInterface(declaringClass, EVENT_PUBLISHER_CNODE); FieldNode epField = injectField( declaringClass, EVENT_ROUTER_FIELD_NAME, PRIVATE, EVENT_PUBLISHER_FIELD_CNODE, null); Parameter erParam = param(EVENT_ROUTER_CNODE, EVENT_ROUTER_PROPERTY); if (!isBlank(beanName)) { AnnotationNode namedAnnotation = new AnnotationNode(NAMED_TYPE); namedAnnotation.addMember("value", new ConstantExpression(beanName)); erParam.addAnnotation(namedAnnotation); } MethodNode setter = new MethodNode( METHOD_SET_EVENT_ROUTER, PRIVATE, VOID_TYPE, params(erParam), NO_EXCEPTIONS, stmnt(call(field(epField), METHOD_SET_EVENT_ROUTER, args(var(EVENT_ROUTER_PROPERTY))))); setter.addAnnotation(new AnnotationNode(INJECT_TYPE)); injectMethod(declaringClass, setter); addDelegateMethods(declaringClass, EVENT_PUBLISHER_CNODE, field(epField)); }
public static Parameter createInputParameter(String name, String datatype) { Parameter param = new Parameter(); param.setInput(true); param.setName(name); param.setDataType(datatype); return param; }
private void doAddConstructor(final ClassNode cNode, final ConstructorNode constructorNode) { cNode.addConstructor(constructorNode); // GROOVY-5814: Immutable is not compatible with @CompileStatic Parameter argsParam = null; for (Parameter p : constructorNode.getParameters()) { if ("args".equals(p.getName())) { argsParam = p; break; } } if (argsParam != null) { final Parameter arg = argsParam; ClassCodeVisitorSupport variableExpressionFix = new ClassCodeVisitorSupport() { @Override protected SourceUnit getSourceUnit() { return cNode.getModule().getContext(); } @Override public void visitVariableExpression(final VariableExpression expression) { super.visitVariableExpression(expression); if ("args".equals(expression.getName())) { expression.setAccessedVariable(arg); } } }; variableExpressionFix.visitConstructor(constructorNode); } }
private Object createTestUsingFieldInjection() throws Exception { List<FrameworkField> annotatedFieldsByParameter = getAnnotatedFieldsByParameter(); if (annotatedFieldsByParameter.size() != fParameters.length) { throw new Exception( "Wrong number of parameters and @Parameter fields." + " @Parameter fields counted: " + annotatedFieldsByParameter.size() + ", available parameters: " + fParameters.length + "."); } Object testClassInstance = getTestClass().getJavaClass().newInstance(); for (FrameworkField each : annotatedFieldsByParameter) { Field field = each.getField(); Parameter annotation = field.getAnnotation(Parameter.class); int index = annotation.value(); try { field.set(testClassInstance, fParameters[index]); } catch (IllegalArgumentException iare) { throw new Exception( getTestClass().getName() + ": Trying to set " + field.getName() + " with the value " + fParameters[index] + " that is not the right type (" + fParameters[index].getClass().getSimpleName() + " instead of " + field.getType().getSimpleName() + ").", iare); } } return testClassInstance; }
ParameterExtractor(TypeCaster caster, Class<?> type, Parameter param, Description description) { this.caster = caster; this.type = type; this.name = param.name(); this.optional = param.optional(); this.description = description == null ? "" : description.value(); }
private void writeParam(Parameter param, DataOutputStream out, String boundary) throws IOException { String name = param.getName(); out.writeBytes("\r\n"); if (param instanceof ImageParameter) { ImageParameter imageParam = (ImageParameter) param; Object value = param.getValue(); out.writeBytes( String.format( Locale.US, "Content-Disposition: form-data; name=\"%s\"; filename=\"%s\";\r\n", name, imageParam.getImageName())); out.writeBytes( String.format(Locale.US, "Content-Type: image/%s\r\n\r\n", imageParam.getImageType())); if (value instanceof InputStream) { InputStream in = (InputStream) value; byte[] buf = new byte[512]; int res = -1; while ((res = in.read(buf)) != -1) { out.write(buf, 0, res); } } else if (value instanceof byte[]) { out.write((byte[]) value); } } else { out.writeBytes("Content-Disposition: form-data; name=\"" + name + "\"\r\n"); out.writeBytes("Content-Type: text/plain; charset=UTF-8\r\n\r\n"); out.write(((String) param.getValue()).getBytes("UTF-8")); } out.writeBytes("\r\n"); out.writeBytes(boundary); }
/** * merge parameters from other table * * @param adds Parameters */ public void addAll(final ParameterTable adds) { synchronized (adds.table) { for (final Parameter p : adds.table) { add(p.getName(), p.getValue()); } } }
public void visit(MethodDeclaration n, Object arg) { if (n.getJavaDoc() != null) { n.getJavaDoc().accept(this, arg); } printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); printTypeParameters(n.getTypeParameters(), arg); if (n.getTypeParameters() != null) {} n.getType().accept(this, arg); if (n.getParameters() != null) { for (Iterator<Parameter> i = n.getParameters().iterator(); i.hasNext(); ) { Parameter p = i.next(); p.accept(this, arg); if (i.hasNext()) {} } } for (int i = 0; i < n.getArrayCount(); i++) {} if (n.getThrows() != null) { for (Iterator<NameExpr> i = n.getThrows().iterator(); i.hasNext(); ) { NameExpr name = i.next(); name.accept(this, arg); if (i.hasNext()) {} } } if (n.getBody() == null) { } else { n.getBody().accept(this, arg); } }
@Override public String print(int length) throws Exception { String space = TransformUtil.spaces(length); String space1 = TransformUtil.spaces(length + 4); String space2 = TransformUtil.spaces(length + 8); String result = ""; try { result += space + "RuntimeVisibleParameterAnnotations : \n"; result += space1 + "num_parameters : " + TransformUtil.bytesToInt(new byte[] {getNum_parameters()}) + "\n"; List<Parameter> parameters = getParameters(); for (Parameter parameter : parameters) { result += space1 + "parameter: \n"; result += space2 + "num_annotations: " + TransformUtil.bytesToInt(parameter.getNum_annotations()) + "\n"; List<Annotation> annotations = parameter.getAnnotations(); for (Annotation annotation : annotations) { result += annotation.print(length + 8); } } } catch (Exception e) { e.printStackTrace(); } return result; }
public void visit(ConstructorDeclaration n, Object arg) { if (n.getJavaDoc() != null) { n.getJavaDoc().accept(this, arg); } printMemberAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); printTypeParameters(n.getTypeParameters(), arg); if (n.getTypeParameters() != null) {} if (n.getParameters() != null) { for (Iterator<Parameter> i = n.getParameters().iterator(); i.hasNext(); ) { Parameter p = i.next(); p.accept(this, arg); if (i.hasNext()) {} } } if (n.getThrows() != null) { for (Iterator<NameExpr> i = n.getThrows().iterator(); i.hasNext(); ) { NameExpr name = i.next(); name.accept(this, arg); if (i.hasNext()) {} } } n.getBlock().accept(this, arg); }
/** Test if setting a stamp expressions marks the correct nodes as dirty. */ public void testStampExpression() { Node number1 = numberNode.newInstance(testLibrary, "number1"); Node stamp1 = Node.ROOT_NODE.newInstance(testLibrary, "stamp1", Integer.class); stamp1.addPort("value"); stamp1.getPort("value").connect(number1); // The code prepares upstream dependencies for stamping, processes them and negates the output. String stampCode = "def cook(self):\n" + " context.put('my_a', 99)\n" + " self.node.stampDirty()\n" + " self.node.updateDependencies(context)\n" + " return -self.value # Negate the output"; stamp1.setValue("_code", new PythonCode(stampCode)); Parameter pValue = number1.getParameter("value"); // Set number1 to a regular value. This should not influence the stamp operation. pValue.set(12); stamp1.update(); assertEquals(-12, stamp1.getOutputValue()); // Set number1 to an expression. Since we're not using stamp, nothing strange should happen to // the output. pValue.setExpression("2 + 1"); stamp1.update(); assertEquals(-3, stamp1.getOutputValue()); // Set number1 to an unknown stamp expression. The default value will be picked. pValue.setExpression("stamp(\"xxx\", 19)"); stamp1.update(); assertEquals(-19, stamp1.getOutputValue()); // Set number1 to the my_a stamp expression. The expression will be picked up. pValue.setExpression("stamp(\"my_a\", 33)"); stamp1.update(); assertEquals(-99, stamp1.getOutputValue()); }
@Override public void parseSelf(AttributeInfo attributeInfo, List<ConstantPoolInfo> cp_info) throws Exception { super.parseSelf(attributeInfo, cp_info); byte[] info = attributeInfo.getInfo(); int[] index = new int[] {0}; setNum_parameters(TransformUtil.subBytes(info, index, 1)[0]); int num_param = TransformUtil.bytesToInt(new byte[] {getNum_parameters()}); if (num_param > 0) { List<Parameter> parameters = new ArrayList<Parameter>(); for (int i = 0; i < num_param; i++) { Parameter parameter = new Parameter(); parameter.setNum_annotations(TransformUtil.subBytes(info, index, 2)); int num_anno = TransformUtil.bytesToInt(parameter.getNum_annotations()); if (num_anno > 0) { List<Annotation> annotations = new ArrayList<Annotation>(); for (int j = 0; j < num_anno; j++) { Annotation annotation = new Annotation(cp_info); annotation.parseSelf(info, index); annotations.add(annotation); } parameter.setAnnotations(annotations); } setParameters(parameters); } } }
private void addServerIPAndHostEntries() { String hostName = serverConfigurationInformation.getHostName(); String ipAddress = serverConfigurationInformation.getIpAddress(); if (hostName != null && !"".equals(hostName)) { Entry entry = new Entry(SynapseConstants.SERVER_HOST); entry.setValue(hostName); synapseConfiguration.addEntry(SynapseConstants.SERVER_HOST, entry); } if (ipAddress != null && !"".equals(ipAddress)) { Entry entry = new Entry(SynapseConstants.SERVER_IP); entry.setValue(ipAddress); if (synapseConfiguration.getAxisConfiguration().getTransportsIn() != null) { Map<String, TransportInDescription> transportInConfigMap = synapseConfiguration.getAxisConfiguration().getTransportsIn(); if (transportInConfigMap != null) { TransportInDescription transportInDescription = transportInConfigMap.get("http"); if (transportInDescription != null) { Parameter bindAddressParam = transportInDescription.getParameter("bind-address"); if (bindAddressParam != null) { entry.setValue(bindAddressParam.getValue()); } } } } synapseConfiguration.addEntry(SynapseConstants.SERVER_IP, entry); } }
public void testNodeAttributeEvent() { TestAttributeListener l = new TestAttributeListener(); Node test = Node.ROOT_NODE.newInstance(testLibrary, "test"); test.addNodeAttributeListener(l); // Setting the name to itself does not trigger an event. test.setName("test"); assertEquals(0, l.nameCounter); test.setName("newname"); assertEquals(1, l.nameCounter); Parameter p1 = test.addParameter("p1", Parameter.Type.FLOAT); assertEquals(1, l.parameterCounter); p1.setName("parameter1"); assertEquals(2, l.parameterCounter); // TODO: These trigger ParameterAttributeChanged // p1.setBoundingMethod(Parameter.BoundingMethod.HARD); // assertEquals(3, l.parameterCounter); // p1.setMinimumValue(0F); // assertEquals(4, l.parameterCounter); // Changing the value does not trigger the event. // The event only happens for metadata, not data. // If you want to catch that, use DirtyListener. p1.setValue(20F); assertEquals(2, l.parameterCounter); test.removeParameter("parameter1"); assertEquals(3, l.parameterCounter); }
public void doCall(String method, Object value) throws Exception { Call call = new Call(); call.setTargetObjectURI("http://soapinterop.org/"); call.setMethodName(method); call.setEncodingStyleURI(encodingStyleURI); Vector params = new Vector(); params.addElement(new Parameter("in", value.getClass(), value, null)); call.setParams(params); // make the call: note that the action URI is empty because the // XML-SOAP rpc router does not need this. This may change in the // future. Response resp = call.invoke(url, ""); // Check the response. if (resp.generatedFault()) { Fault fault = resp.getFault(); System.out.println("Ouch, the call failed: "); System.out.println(" Fault Code = " + fault.getFaultCode()); System.out.println(" Fault String = " + fault.getFaultString()); } else { Parameter result = resp.getReturnValue(); System.out.println("Call succeeded: "); System.out.println("Result = " + result.getValue()); } }
public Parameter createOrLookupParam( boolean definition, String name, Type type, Exp defaultExp, String description) { final SchemaReader schemaReader = getQuery().getSchemaReader(false); Parameter param = schemaReader.getParameter(name); if (definition) { if (param != null) { if (param.getScope() == Parameter.Scope.Statement) { ParameterImpl paramImpl = (ParameterImpl) param; paramImpl.setDescription(description); paramImpl.setDefaultExp(defaultExp); paramImpl.setType(type); } return param; } param = new ParameterImpl(name, defaultExp, description, type); // Append it to the list of known parameters. defineParameter(param); return param; } else { if (param != null) { return param; } throw MondrianResource.instance().UnknownParameter.ex(name); } }
/* (non-Javadoc) * @see java.lang.Object#clone() */ @Override public Parameters clone() throws CloneNotSupportedException { Parameters newParams = new Parameters(); for (Parameter param : getParameters()) { newParams.addParameter(param.clone()); } return newParams; }
public void visit(Parameter n, Object arg) { printAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); n.getType().accept(this, arg); if (n.isVarArgs()) {} n.getId().accept(this, arg); }
/* (non-Javadoc) * @see java.lang.Object#clone() */ @Override public Parameter clone() throws CloneNotSupportedException { Parameter param = new Parameter(name); param.setValue(value); param.setHelp(help); param.setReadOnly(readOnly); return param; }
/** * construct an instance of a parameter type that has a name. the value of {@code params} should * not contain a <em>null</em> instance, which is not a valid input when creating a {@link * Parameter}. * * @param name name of the parameter. * @param params parameters that will compose the parameters. * @return a new {@code Parameter} instance. */ public static Parameter makeNamedParameter(String name, Object... params) { final Parameter param = new SingleValueParameter(name); for (Object each : params) { param.setParameterValue(each, discoverClass(each)); } return param; }
/** * Generate PPD mutants * * @param p * @param parent */ public void generateMutant(Parameter p, String parent) { String declared_type = p.getTypeSpecifier().getName(); if (hasHidingVariable(declared_type, parent)) { Parameter mutant = (Parameter) p.makeRecursiveCopy(); mutant.setTypeSpecifier(new TypeName(parent)); outputToFile(p, mutant); } }