public void setType(String type) { try { this.type = Type.valueOf(type.toUpperCase()); } catch (IllegalArgumentException e) { throw new BuildException("the type attribute value may only be 'file' or 'string'"); } }
private Object read( DataInput objBuffer, Type propertyType, boolean array, UnrealPackageReadOnly.ExportEntry arrayInner, String structName, UnrealPackageReadOnly up) throws IOException { switch (propertyType) { case NONE: return null; case BYTE: return objBuffer.readUnsignedByte(); case INT: return objBuffer.readInt(); case BOOL: return array; case FLOAT: return objBuffer.readFloat(); case OBJECT: return objBuffer.readCompactInt(); case NAME: return objBuffer.readCompactInt(); case ARRAY: int arraySize = objBuffer.readCompactInt(); List<Object> arrayList = new ArrayList<>(arraySize); String a = arrayInner.getObjectClass().getObjectName().getName(); Property f = unrealClassLoader.getProperty(arrayInner.getObjectFullName()); array = false; arrayInner = null; structName = null; propertyType = Type.valueOf(a.replace("Property", "").toUpperCase()); if (propertyType == Type.STRUCT) { StructProperty structProperty = (StructProperty) f; structName = structProperty.getStructType().getObjectFullName(); } if (propertyType == Type.ARRAY) { array = true; ArrayProperty arrayProperty = (ArrayProperty) f; arrayInner = (UnrealPackageReadOnly.ExportEntry) arrayProperty.getInner(); } for (int i = 0; i < arraySize; i++) { arrayList.add(read(objBuffer, propertyType, array, arrayInner, structName, up)); } return arrayList; case STRUCT: return readStruct(objBuffer, structName, up); /*case VECTOR: return readStruct(objBuffer, "Vector", up); case ROTATOR: return readStruct(objBuffer, "Rotator", up);*/ case STR: return objBuffer.readLine(); default: throw new IllegalStateException("Unk type(" + structName + "): " + propertyType); } }
private void initType() { Bundle bundle = getArguments(); if (bundle.containsKey(KEY)) { mType = Type.valueOf(bundle.getString(KEY)); createSelection(); } }
@RequestMapping(value = "/upload", method = RequestMethod.POST) public @ResponseBody void uploadProduct( @RequestParam(value = "pic", required = false) MultipartFile pic, @RequestParam(value = "id", required = false) Integer id, @RequestParam("name") String name, @RequestParam("description") String description, @RequestParam("type") String type, @RequestParam("category") String category, @RequestParam("price") double price, @RequestParam("unit") String unit, HttpServletResponse response) { if (type == null || name == null || pic == null || description == null || category == null || price == 0 || unit == null) { response.setStatus(HttpStatus.NOT_ACCEPTABLE.value()); return; } Product product; if (id != null) { product = productService.getById(id); } else { product = new Product(); } product.setName(name); product.setDescription(description); product.setType(Type.valueOf(type)); product.setCategory(Category.valueOf(category)); product.setPrice(price); product.setUnit(unit); // for Linux String dstFilePath = "/" + PathUtil.getWebInfPath() + "/product_images/" + product.generatePicurlHash() + ".jpg"; // for Windows // String dstFilePath = PathUtil.getWebInfPath() + "/product_images/" + // product.generatePicurlHash() + ".jpg"; System.out.println("dstFilePath =" + dstFilePath); if (pic != null) { product.setPicurl("product_images/" + product.generatePicurlHash() + ".jpg"); File picFile = new File(dstFilePath); try { pic.transferTo(picFile); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } product.setDataChangeLastTime(new Timestamp(System.currentTimeMillis())); if (id != null) { productService.update(product); } else { productService.save(product); } }
public String evaluate(Program pgm, Variables vars, Instruction inst) throws Exception { Object[] objs = Bit.getObjects(pgm, vars, inst, 1); String type = objs[0].toString(); String msg = ""; for (int i = 1; i < objs.length; i++) { msg += objs[i].toString(); } Type t = null; try { t = Type.valueOf(type); } catch (Exception e) { Bit.error(inst, "Invalid type, first parameter must be the type"); } if (t == null) Bit.error(inst, "First parameter must be the type"); String i; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.print(msg); i = br.readLine(); while (!t.isValidValue(i)) { System.out.println("The value must be a valid " + t.name()); System.out.print(msg); i = br.readLine(); } Reference ref = new Reference(); ref.type = t; ref.value = t.getObject(i, null); return pgm.getReferences().newReference(ref); }
public void setType(String type) { if ("node down".equals(type)) { this.type = Type.node_down; } else { this.type = Type.valueOf(type); } }
private void generateIndex() { if (this.indexClass.isAssignableFrom(Neo4jVertex.class)) this.rawIndex = (org.neo4j.graphdb.index.Index<S>) graph.getRawGraph().index().forNodes(this.indexName); else this.rawIndex = (org.neo4j.graphdb.index.Index<S>) graph.getRawGraph().index().forRelationships(this.indexName); IndexManager manager = this.getIndexManager(); String storedType = manager.getConfiguration(this.rawIndex).get(Neo4jTokens.BLUEPRINTS_TYPE); if (null == storedType) { if (this instanceof AutomaticIndex) { this.getIndexManager() .setConfiguration( this.rawIndex, Neo4jTokens.BLUEPRINTS_TYPE, Type.AUTOMATIC.toString()); } else { this.getIndexManager() .setConfiguration(this.rawIndex, Neo4jTokens.BLUEPRINTS_TYPE, Type.MANUAL.toString()); } } else if (this.getIndexType() != Type.valueOf(storedType)) throw new RuntimeException( "Stored index is " + storedType + " and is being loaded as a " + this.getIndexType() + " index"); }
@Override public boolean check(RequirementsContext context, List<String> args) throws RequirementCheckException { boolean outcome = false; String name = null; String value = "true"; String index = ""; Type type = Type.PLAYER; for (String arg : args) { if (aH.matchesArg("GLOBAL, NPC, DENIZEN, GLOBAL", arg)) type = Type.valueOf(arg.toUpperCase().replace("DENIZEN", "NPC")); else if (arg.split(":", 2).length > 1) { String[] flagArgs = arg.split(":"); value = flagArgs[1].toUpperCase(); if (flagArgs[0].contains("[")) { name = flagArgs[0].split("\\[", 2)[0].trim(); index = flagArgs[0].split("\\[", 2)[1].split("\\]", 2)[0].trim(); } else { name = flagArgs[0].toUpperCase(); } } else name = arg.toUpperCase(); } FlagManager flagMng = DenizenAPI.getCurrentInstance().flagManager(); FlagManager.Flag flag = null; String player = context.getPlayer().getName(); switch (type) { case NPC: flag = flagMng.getNPCFlag(context.getNPC().getId(), name); break; case PLAYER: flag = flagMng.getPlayerFlag(player, name); break; case GLOBAL: flag = flagMng.getGlobalFlag(name); break; } if (index.length() == 0) { if (flag.getLast().asString().equalsIgnoreCase(value)) outcome = true; else dB.echoDebug( context.getScriptContainer(), "... does not match '" + flag.getLast().asString() + "'."); } else if (index.matches("\\d+")) { if (flag.get(Integer.parseInt(index)).asString().equalsIgnoreCase(value)) outcome = true; else dB.echoDebug( context.getScriptContainer(), "... does not match '" + flag.get(Integer.parseInt(index)).asString() + "'."); } return outcome; }
/** * An IM application SHOULD support all of the foregoing message types; if an application receives * a message with no 'type' attribute or the application does not understand the value of the * 'type' attribute provided, it MUST consider the message to be of type "normal" (i.e., "normal" * is the default). The "error" type MUST be generated only in response to an error related to a * message received from another entity. * * @see http://www.xmpp.org/rfcs/rfc3921.html#stanzas-message-type * @return */ public Type getType() { final String type = getAttribute(TYPE); try { return type != null ? Type.valueOf(type) : Type.normal; } catch (final IllegalArgumentException e) { return Type.normal; } }
/** * Return the file type or <tt>null</tt>. * * @param path the path to test * @return the file type */ protected final Type getType(JailedResourcePath path) { GridFSDBFile file = getGridFSDBFile(path, false); if (file == null) { return null; } Type type = Type.valueOf((String) file.get(RESOURCE_TYPE)); return type; }
/** Returns the type constant associated with the String value. */ protected static PrivacyRule fromString(String value) { if (value == null) { return null; } PrivacyRule rule = new PrivacyRule(); rule.setType(Type.valueOf(value.toLowerCase())); return rule; }
protected void read(DataInputStream s) { try { ref = new WeakReference<DataBuffer>(this, Nd4j.bufferRefQueue()); referencing = Collections.synchronizedSet(new HashSet<String>()); dirty = new AtomicBoolean(false); allocationMode = AllocationMode.valueOf(s.readUTF()); length = s.readInt(); Type t = Type.valueOf(s.readUTF()); if (t == Type.DOUBLE) { if (allocationMode == AllocationMode.HEAP) { if (this.dataType() == Type.FLOAT) { // DataBuffer type // double -> float floatData = new float[length()]; } else if (this.dataType() == Type.DOUBLE) { // double -> double doubleData = new double[length()]; } else { // double -> int intData = new int[length()]; } for (int i = 0; i < length(); i++) { put(i, s.readDouble()); } } else { wrappedBuffer = ByteBuffer.allocateDirect(length() * getElementSize()); wrappedBuffer.order(ByteOrder.nativeOrder()); for (int i = 0; i < length(); i++) { put(i, s.readDouble()); } } } else { if (allocationMode == AllocationMode.HEAP) { if (this.dataType() == Type.FLOAT) { // DataBuffer type // float -> float floatData = new float[length()]; } else if (this.dataType() == Type.DOUBLE) { // float -> double doubleData = new double[length()]; } else { // float-> int intData = new int[length()]; } for (int i = 0; i < length(); i++) { put(i, s.readFloat()); } } else { wrappedBuffer = ByteBuffer.allocateDirect(length() * getElementSize()); wrappedBuffer.order(ByteOrder.nativeOrder()); for (int i = 0; i < length(); i++) { put(i, s.readFloat()); } } } } catch (Exception e) { throw new RuntimeException(e); } }
public Type getType() { try { // TODO: make this a psf return tokenType != null ? Type.valueOf(tokenType) : Type.NPC; } catch (IllegalArgumentException iae) { tokenType = Type.NPC.name(); return Type.NPC; } }
private static List<Field> generateFields() { List<Field> fields = new ArrayList<Field>(); for (int i = 0; i < FIELD_NAMES.length; i++) { String name = FIELD_NAMES[i]; Type type = Type.valueOf(FIELD_TYPES[i]); int size = FIELD_SIZES[i]; fields.add(new Field(name, type, size, true)); } return fields; }
public static Type parse(String type) { if (Strings.isNullOrEmpty(type)) { return SOFT_CONCURRENT; } try { return Type.valueOf(type.toUpperCase(Locale.ROOT)); } catch (IllegalArgumentException e) { throw new ElasticsearchIllegalArgumentException("no type support [" + type + "]"); } }
@Override public void execute(ScriptEntry scriptEntry) throws CommandExecutionException { Element message = scriptEntry.getElement("message"); Element fileName = scriptEntry.getElement("file"); Element typeElement = scriptEntry.getElement("type"); dB.report(scriptEntry, getName(), message.debug() + fileName.debug() + typeElement.debug()); Type type = Type.valueOf(typeElement.asString().toUpperCase()); String directory = URLDecoder.decode(System.getProperty("user.dir")); File file = new File(directory, fileName.asString()); if (type == Type.NONE) { try { file.getParentFile().mkdirs(); FileWriter fw = new FileWriter(file, true); fw.write(message + "\n"); fw.close(); } catch (IOException e) { dB.echoError("Error logging to file..."); dB.echoError(e); } return; } DebugLog log = new DebugLog("Denizen-ScriptLog-" + fileName, file.getAbsolutePath()); switch (type) { case SEVERE: log.severe(message.asString()); break; case INFO: log.info(message.asString()); break; case WARNING: log.warning(message.asString()); break; case FINE: log.fine(message.asString()); break; case FINER: log.finer(message.asString()); break; case FINEST: log.finest(message.asString()); } log.close(); }
public static Type fromString(String processorTag, String propertyName, String type) { try { return Type.valueOf(type.toUpperCase(Locale.ROOT)); } catch (IllegalArgumentException e) { throw newConfigurationException( TYPE, processorTag, propertyName, "type [" + type + "] not supported, cannot convert field."); } }
public static boolean doTest(Type testType) { Type value = null; try { value = Type.valueOf(System.getProperty("testType")); } catch (IllegalArgumentException | NullPointerException e) { value = Type.AGGRESSIVE; } return testType.equals(value); }
/** * Generate a Type from a string. * * @param value string value * @return generated Type */ @JsonCreator public static Type forValue(final String value) { String normalized = value.replace("-", "_").toUpperCase(); try { return Type.valueOf(normalized); } catch (RuntimeException e) { // Don't blow up of value does not exist return null; } }
public Type getType() { String tmp = getAtribute("type"); if (tmp != null) { try { return Type.valueOf(tmp); } catch (Exception e) { return null; } } else { return null; } }
public Entity(Parcel parcel) { this.entityID = parcel.readString(); this.entityType = Type.valueOf(parcel.readString()); this.distanceRange = DistanceRange.valueOf(parcel.readString()); JSONParser parser = new JSONParser(); try { this.properties = (JSONObject) parser.parse(parcel.readString()); } catch (ParseException e) { e.printStackTrace(); } }
// TODO: how to handle numImages? public static List<WebResource> loadResources(Place p, int numLinks, int numImages) { List<WebResource> resources = new ArrayList<WebResource>(); Connection c = null; PreparedStatement s = null; ResultSet rs = null; try { c = Utils.getConnection(); s = c.prepareStatement( "SELECT DISTINCT `place`,`tweeted`,`url`,`type`,`title`,`mediaUrl` FROM `urls` WHERE `place`=? ORDER BY `tweeted` DESC LIMIT ?;"); s.setInt(1, p.id); s.setInt(2, numLinks); rs = s.executeQuery(); while (rs.next()) { try { WebResource wr = new WebResource( rs.getInt("place"), Utils.sqlDateTimeFormat.parse(rs.getString("tweeted")), rs.getString("url"), Type.valueOf(rs.getString("type")), rs.getString("title"), rs.getString("mediaUrl")); resources.add(wr); } catch (ParseException e) { log.warn(e); } } } catch (SQLException e) { log.warn("Failed to run statement", e); } finally { try { rs.close(); } catch (SQLException e) { log.warn("Failed to clean up after statement", e); } try { s.close(); } catch (SQLException e) { log.warn("Failed to clean up after statement", e); } try { c.close(); } catch (SQLException e) { log.warn("Failed to clean up after statement", e); } } return resources; }
public void writeProperties(DataOutput buffer, List<L2Property> list, UnrealPackageReadOnly up) throws UnrealException { try { for (L2Property property : list) { Property template = property.getTemplate(); for (int i = 0; i < property.getSize(); i++) { Object obj = property.getAt(i); if (obj == null) continue; ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutput objBuffer = new DataOutputStream(baos, buffer.getCharset()); AtomicBoolean array = new AtomicBoolean(i > 0); AtomicReference<String> structName = new AtomicReference<>(); AtomicReference<Type> type = new AtomicReference<>( Type.valueOf( template.getClass().getSimpleName().replace("Property", "").toUpperCase())); write(objBuffer, template, obj, array, structName, type, up); byte[] bytes = baos.toByteArray(); int size = getPropertySize(bytes.length); int ord = type.get().ordinal(); if (ord == 8) // FIXME ord = 5; int info = (array.get() ? 1 << 7 : 0) | (size << 4) | ord; buffer.writeCompactInt(up.nameReference(template.getEntry().getObjectName().getName())); buffer.writeByte(info); if (type.get() == Type.STRUCT) buffer.writeCompactInt(up.nameReference(structName.get())); switch (size) { case 5: buffer.writeByte(bytes.length); break; case 6: buffer.writeShort(bytes.length); break; case 7: buffer.writeInt(bytes.length); break; } if (i > 0) buffer.writeByte(i); buffer.write(bytes); } } buffer.writeCompactInt(up.nameReference("None")); } catch (IOException e) { throw new UnrealException(e); } }
/** * Find modification type by name with case-insensitive. * * @param name SHOULD not be empty. * @return If not find, return null value. */ public static Type findType(String name) { if (MZTabUtils.isEmpty(name)) { throw new IllegalArgumentException("Modification type name should not be empty!"); } Type type; try { type = Type.valueOf(name.trim().toUpperCase()); } catch (IllegalArgumentException e) { type = null; } return type; }
public static Type findType(String name) { if (name == null) { return null; } Type type; try { type = Type.valueOf(name.trim().toUpperCase()); } catch (IllegalArgumentException e) { type = null; } return type; }
/** * Detect notification type based on the xml root name. * * @param payload * @return notification type or null if root name is not found or if there is no type * corresponding to the root name */ public static Type detect(String payload) { Matcher m = ROOT_NAME.matcher(payload); if (m.find() && m.groupCount() >= 1) { String root = m.group(1); try { return Type.valueOf(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, root)); } catch (IllegalArgumentException e) { log.warn("Enable to detect notification type, no type for {}", root); return null; } } log.warn("Enable to detect notification type"); return null; }
public String evaluate(Program pgm, Variables vars, Instruction inst) throws Exception { Object[] objs = Bit.getObjects(pgm, vars, inst, 1); String title = objs[0].toString(); String msg = objs[1].toString(); String btnlabel = objs[2].toString(); int width = Integer.parseInt(objs[3].toString()); String type = objs[4].toString(); Type t = Type.valueOf(type); if (t == null) Bit.error(inst, "Fifth parameter must be the type"); RequestInput ri = pgm.getInput(); Reference ref = ri.getInput(title, msg, width, btnlabel, t); ref.value = ref.value; return pgm.getReferences().newReference(ref); }
private static ControlInfo valueOf(String string) throws ArgumentFormatException { try { PArray arr = PArray.valueOf(string); Type type = Type.valueOf(arr.get(0).toString()); switch (type) { case Function: return parseFunction(string, arr); case Action: return parseAction(string, arr); default: return parseProperty(string, type, arr); } } catch (Exception ex) { throw new ArgumentFormatException(ex); } }
@Override public StarClass parse(String string) { // subdwarf (luminosity class VI) if (string.startsWith("sd") && string.length() > 2) { // Format is: type (one of O, B, A, F, G, K, M, L, T), optionally followed by sub-type (0-9) Type t = Type.valueOf(string.substring(2, 3)); if (t.mainSequence) { int subType = 5; if (string.length() > 3) { subType = Integer.parseInt(string.substring(3, 4)); } return new Main(t, subType, LuminosityClass.SUBDWARF); } } return null; }
public Builder cursor(Cursor cursor) { int index; index = cursor.getColumnIndex(PrinterContract.DeviceCategories.UUID); if (index != -1) { uuid(cursor.getString(index)); } if (uuid == null) { index = cursor.getColumnIndex(PrinterContract.DeviceCategories.DEVICE_UUID); if (index != -1) { uuid(cursor.getString(index)); } } index = cursor.getColumnIndex(PrinterContract.DeviceCategories.TYPE); if (index != -1) { String t = cursor.getString(index); type(Type.valueOf(t)); } index = cursor.getColumnIndex(PrinterContract.DeviceCategories.NAME); if (index != -1) { name(cursor.getString(index)); } index = cursor.getColumnIndex(PrinterContract.DeviceCategories.MAC); if (index != -1) { mac(cursor.getString(index)); } index = cursor.getColumnIndex(PrinterContract.DeviceCategories.IP); if (index != -1) { ip(cursor.getString(index)); } index = cursor.getColumnIndex(PrinterContract.DeviceCategories.CATEGORY); if (index != -1) { String c = cursor.getString(index); category(Category.valueOf(c)); } return this; }