public void displayPartMenu(String type) throws DataException { ArrayList<Part> list = partCtrl.retrieveAvailablePartsByType(type); System.out.println(); System.out.println("== BattleStations :: Le Part :: " + type + " =="); for (int i = 0; i < list.size(); i++) { Part p = list.get(i); System.out.println((i + 1) + ". " + p.getName() + " (min: L" + p.getLvlReq() + ")"); } System.out.print("[R]eturn to main | Enter number > "); }
public void displayBuyMenu(Part p) throws DataException { System.out.println(); System.out.println("== BattleStations :: Le Part :: Details =="); System.out.println("Part: " + p.getName()); System.out.println(); System.out.println("Speed: " + p.getSpeed()); System.out.println("HP: " + p.getHP()); System.out.println("Capacity: " + p.getCapacity()); System.out.println("Weight: " + p.getWeight()); System.out.println("Level Required: " + p.getLvlReq()); System.out.println(); System.out.println( "Gold: " + p.getGoldReq() + " | Wood: " + p.getWoodReq() + " | Ore: " + p.getOreReq() + " | Prock: " + p.getPlasmaRockReq()); System.out.println(); System.out.print("[R]eturn to main | [B]uy it > "); }
/** * Constructs a new MultipartRequest to handle the specified request, saving any uploaded files to * the given directory, and limiting the upload size to the specified length. If the content is * too large, an IOException is thrown. This constructor actually parses the * <tt>multipart/form-data</tt> and throws an IOException if there's any problem reading or * parsing the request. * * <p>To avoid file collisions, this constructor takes an implementation of the FileRenamePolicy * interface to allow a pluggable rename policy. * * @param request the servlet request. * @param saveDirectory the directory in which to save any uploaded files. * @param maxPostSize the maximum size of the POST content. * @param encoding the encoding of the response, such as ISO-8859-1 * @param policy a pluggable file rename policy * @exception IOException if the uploaded content is larger than <tt>maxPostSize</tt> or there's a * problem reading or parsing the request. */ public CosMultipartRequest( HttpServletRequest request, String saveDirectory, int maxPostSize, String encoding, FileRenamePolicy policy) throws IOException { // Sanity check values if (request == null) throw new IllegalArgumentException("request cannot be null"); if (saveDirectory == null) throw new IllegalArgumentException("saveDirectory cannot be null"); if (maxPostSize <= 0) { throw new IllegalArgumentException("maxPostSize must be positive"); } // Save the dir File dir = new File(saveDirectory); // Check saveDirectory is truly a directory if (!dir.isDirectory()) throw new IllegalArgumentException("Not a directory: " + saveDirectory); // Check saveDirectory is writable if (!dir.canWrite()) throw new IllegalArgumentException("Not writable: " + saveDirectory); // Parse the incoming multipart, storing files in the dir provided, // and populate the meta objects which describe what we found MultipartParser parser = new MultipartParser(request, maxPostSize, true, true, encoding); // Some people like to fetch query string parameters from // MultipartRequest, so here we make that possible. Thanks to // Ben Johnson, [email protected], for the idea. if (request.getQueryString() != null) { // Let HttpUtils create a name->String[] structure Map<String, String[]> queryParameters = RequestUtils.parseQueryString(request.getQueryString()); // For our own use, name it a name->Vector structure for (Entry<String, String[]> entry : queryParameters.entrySet()) { parameters.put(entry.getKey(), Arrays.asList(entry.getValue())); } } Part part; while ((part = parser.readNextPart()) != null) { String name = part.getName(); if (name == null) { throw new IOException("Malformed input: parameter name missing (known Opera 7 bug)"); } if (part.isParam()) { // It's a parameter part, add it to the vector of values ParamPart paramPart = (ParamPart) part; String value = paramPart.getStringValue(); List<String> existingValues = parameters.get(name); if (existingValues == null) { existingValues = new ArrayList<String>(); parameters.put(name, existingValues); } existingValues.add(value); } else if (part.isFile()) { // It's a file part FilePart filePart = (FilePart) part; String fileName = filePart.getFileName(); if (fileName != null) { filePart.setRenamePolicy(policy); // null policy is OK // The part actually contained a file filePart.writeTo(dir); files.put( name, new UploadedFile( dir.toString(), filePart.getFileName(), fileName, filePart.getContentType())); } else { // The field did not contain a file files.put(name, new UploadedFile(null, null, null, null)); } } } }
/** Generation of new BioBricks primers for parts * */ public static String[] generatePartPrimers( RNode node, Collector coll, Double meltingTemp, Integer targetLength, Integer minPCRLength, Integer maxPrimerLength) { // initialize primer parameters String[] oligos = new String[2]; String partPrimerPrefix = "gaattcgcggccgcttctagag"; String partPrimerSuffix = "tactagtagcggccgctgcag"; String partPrimerPrefixAlt = "gaattcgcggccgcttctag"; String forwardOligoSequence; String reverseOligoSequence; Part currentPart = coll.getPart(node.getUUID(), true); String seq = currentPart.getSeq(); ArrayList<String> type = node.getType(); String fwdHomology; String revHomology; // If the part is sufficiently large if (seq.length() > minPCRLength) { // Special case primers for coding sequences if (type.get(0).equals("gene") || type.get(0).equals("reporter")) { fwdHomology = seq.substring( 0, Math.min( seq.length(), PrimerDesign.getPrimerHomologyLength( meltingTemp, targetLength, maxPrimerLength - 20, minPCRLength, seq, true))); revHomology = seq.substring( Math.max( 0, currentPart.getSeq().length() - PrimerDesign.getPrimerHomologyLength( meltingTemp, targetLength, maxPrimerLength - 21, minPCRLength, PrimerDesign.reverseComplement(seq), true))); forwardOligoSequence = partPrimerPrefixAlt + fwdHomology; reverseOligoSequence = PrimerDesign.reverseComplement(revHomology + partPrimerSuffix); } else { if (seq.equals("")) { fwdHomology = "[ PART " + currentPart.getName() + " HOMOLOGY REGION ]"; revHomology = "[ PART " + currentPart.getName() + " HOMOLOGY REGION ]"; } else { fwdHomology = seq.substring( 0, Math.min( seq.length(), PrimerDesign.getPrimerHomologyLength( meltingTemp, targetLength, maxPrimerLength - 22, minPCRLength, seq, true))); revHomology = seq.substring( Math.max( 0, currentPart.getSeq().length() - PrimerDesign.getPrimerHomologyLength( meltingTemp, targetLength, maxPrimerLength - 21, minPCRLength, PrimerDesign.reverseComplement(seq), true))); } forwardOligoSequence = partPrimerPrefix + fwdHomology; reverseOligoSequence = PrimerDesign.reverseComplement(revHomology + partPrimerSuffix); } // Otherwise make annealing primers or synthesize } else { if (type.get(0).equals("gene") || type.get(0).equals("reporter")) { if (seq.equals("")) { fwdHomology = "[ PART " + currentPart.getName() + " HOMOLOGY REGION ]"; revHomology = "[ PART " + currentPart.getName() + " HOMOLOGY REGION ]"; forwardOligoSequence = partPrimerPrefixAlt + fwdHomology; reverseOligoSequence = PrimerDesign.reverseComplement(partPrimerSuffix) + revHomology; } else { fwdHomology = seq; forwardOligoSequence = partPrimerPrefixAlt + fwdHomology + partPrimerSuffix; reverseOligoSequence = PrimerDesign.reverseComplement(forwardOligoSequence); } } else { if (seq.equals("")) { fwdHomology = "[ PART " + currentPart.getName() + " HOMOLOGY REGION ]"; revHomology = "[ PART " + currentPart.getName() + " HOMOLOGY REGION ]"; forwardOligoSequence = partPrimerPrefix + fwdHomology; reverseOligoSequence = PrimerDesign.reverseComplement(partPrimerSuffix) + revHomology; } else { fwdHomology = seq; forwardOligoSequence = partPrimerPrefix + fwdHomology + partPrimerSuffix; reverseOligoSequence = PrimerDesign.reverseComplement(forwardOligoSequence); } } } oligos[0] = forwardOligoSequence; oligos[1] = reverseOligoSequence; return oligos; }