List of usage examples for org.apache.commons.lang3 StringUtils removeStart
public static String removeStart(final String str, final String remove)
Removes a substring only if it is at the beginning of a source string, otherwise returns the source string.
A null source string will return null .
From source file:tds.itemrenderer.processing.ITSUrlResolver.java
/** * If the path is an absolute url, returns the path. * Otherwise, create a relative path given this webapp's context. * @see javax.servlet.ServletContext#getContextPath * * note: sanitizing path which may contain a leading tilda *//*from ww w . j a v a 2 s . co m*/ private static String resolveUrl(final String contextPath, final String path) { try { final URI uri = new URI(path); if (uri.isAbsolute()) { return path; } } catch (URISyntaxException e) { } if (StringUtils.isBlank(path)) { return String.format("%s/", contextPath); } else { String relativePath = StringUtils.removeStart(path, "~/"); relativePath = StringUtils.removeStart(relativePath, "/"); return String.format("%s/%s", contextPath, relativePath); } }
From source file:tectonicus.blockTypes.BlockRegistry.java
public BlockModel loadModel(String modelPath, ZipStack zips, Map<String, String> textureMap) throws Exception { ZipStackEntry modelFile = zips.getEntry("assets/minecraft/models/" + modelPath + ".json"); JSONObject obj = new JSONObject(FileUtils.loadJSON(modelFile.getInputStream())); String parent = ""; if (obj.has("parent")) // Get texture information and then load parent file {//from w ww . j a v a2s. c o m parent = obj.getString("parent"); return loadModel(parent, zips, populateTextureMap(textureMap, obj.getJSONObject("textures"))); } else //Load all elements { Map<String, String> combineMap = new HashMap<>(textureMap); if (obj.has("textures")) { combineMap.putAll(populateTextureMap(textureMap, obj.getJSONObject("textures"))); } List<BlockElement> elementsList = new ArrayList<>(); boolean ao = true; if (obj.has("ambientocclusion")) ao = false; JSONArray elements = obj.getJSONArray("elements"); for (int i = 0; i < elements.length(); i++) { Map<String, ElementFace> elementFaces = new HashMap<>(); JSONObject element = elements.getJSONObject(i); JSONArray from = element.getJSONArray("from"); Vector3f fromVector = new Vector3f((float) from.getDouble(0), (float) from.getDouble(1), (float) from.getDouble(2)); JSONArray to = element.getJSONArray("to"); Vector3f toVector = new Vector3f((float) to.getDouble(0), (float) to.getDouble(1), (float) to.getDouble(2)); Vector3f rotationOrigin = new Vector3f(8.0f, 8.0f, 8.0f); String rotationAxis = "y"; float rotationAngle = 0; boolean rotationScale = false; if (element.has("rotation")) { JSONObject rot = element.getJSONObject("rotation"); JSONArray rotOrigin = rot.getJSONArray("origin"); rotationOrigin = new Vector3f((float) rotOrigin.getDouble(0), (float) rotOrigin.getDouble(1), (float) rotOrigin.getDouble(2)); rotationAxis = rot.getString("axis"); rotationAngle = (float) rot.getDouble("angle"); if (element.has("rescale")) rotationScale = true; } boolean shaded = true; if (element.has("shade")) shaded = false; JSONObject faces = element.getJSONObject("faces"); Iterator<?> keys = faces.keys(); while (keys.hasNext()) { String key = (String) keys.next(); JSONObject face = (JSONObject) faces.get(key); float u0 = fromVector.x(); float v0 = fromVector.y(); float u1 = toVector.x(); float v1 = toVector.y(); int rotation = 0; if (face.has("rotation")) rotation = face.getInt("rotation"); //System.out.println("u0="+u0+" v0="+v0+" u1="+u1+" v1="+v1); // TODO: Need to test more texture packs SubTexture subTexture = new SubTexture(null, u0 * (1.0f / 16.0f), v0 * (1.0f / 16.0f), u1 * (1.0f / 16.0f), v1 * (1.0f / 16.0f)); StringBuilder tex = new StringBuilder(face.getString("texture")); if (tex.charAt(0) == '#') { String texture = tex.deleteCharAt(0).toString(); SubTexture te = texturePack .findTexture(StringUtils.removeStart(combineMap.get(texture), "blocks/") + ".png"); final float texHeight = te.texture.getHeight(); final float texWidth = te.texture.getWidth(); final int numTiles = te.texture.getHeight() / te.texture.getWidth(); u0 = fromVector.x() / texWidth; v0 = fromVector.y() / texWidth; u1 = toVector.x() / texWidth; v1 = toVector.y() / texWidth; if (face.has("uv")) { //System.out.println("Before: u0="+u0+" v0="+v0+" u1="+u1+" v1="+v1); JSONArray uv = face.getJSONArray("uv"); u0 = (float) (uv.getDouble(0) / 16.0f); v0 = (float) (uv.getDouble(1) / 16.0f) / numTiles; u1 = (float) (uv.getDouble(2) / 16.0f); v1 = (float) (uv.getDouble(3) / 16.0f) / numTiles; } System.out.println(texWidth + " x " + texHeight); int frame = 1; if (numTiles > 1) { Random rand = new Random(); frame = rand.nextInt(numTiles) + 1; } subTexture = new SubTexture(te.texture, u0, v0 + (float) (frame - 1) * (texWidth / texHeight), u1, v1 + (float) (frame - 1) * (texWidth / texHeight)); //subTexture = new SubTexture(test, u0, v0, u1, v1); //System.out.println("u0="+subTexture.u0+" v0="+subTexture.v0+" u1="+subTexture.u1+" v1="+subTexture.v1); } boolean cullFace = false; if (face.has("cullface")) cullFace = true; boolean tintIndex = false; if (face.has("tintindex")) tintIndex = true; ElementFace ef = new ElementFace(subTexture, cullFace, rotation, tintIndex); elementFaces.put(key, ef); } BlockElement be = new BlockElement(fromVector, toVector, rotationOrigin, rotationAxis, rotationAngle, rotationScale, shaded, elementFaces); elementsList.add(be); } return new BlockModel(modelPath, ao, elementsList); } }
From source file:ubic.gemma.core.loader.genome.FastaParser.java
/** * <pre>//from w ww.j a v a2 s .co m * Affymetrix targets or collapsed sequence target:array:probeset; * Affymetrix "style" file target:probename * Affymetrix probe probe:array:probeset:xcoord:ycoord; Interrogation_Position=XXXX; Antisense; * Affymetrix consensus/exemplar exemplar:array:probeset; gb|accession; gb:accession /DEF=Homo sapiens metalloprotease-like, disintegrin-like, cysteine-rich protein 2 delta (ADAM22) mRNA, alternative splice product, complete cds. /FEA=mRNA /GEN=ADAM22 /PROD=metalloprotease-like, * Affymetrix-like format array:probe or other string containing ':'. * </pre> * * @param bioSequence BA * @param header header * @return boolean always true */ @SuppressWarnings("SameReturnValue") // Consistency with other similar methods private boolean parseAffyHeader(BioSequence bioSequence, String header) { // affymetrix format String[] split = StringUtils.split(header, ":;"); String firstTag = StringUtils.removeStart(split[0], ">"); switch (firstTag) { case "probe": bioSequence.setName(split[1] + ":" + split[2] + ":" + split[3] + ":" + split[4]); break; case "target": // split[1] = array name or probe name // split[2] = probe name if (split.length > 2) { bioSequence.setName(split[2]); } else { bioSequence.setName(split[1]); } break; case "exemplar": bioSequence.setName(split[1] + ":" + split[2]); bioSequence.setDescription(split[3]); break; default: // This is the case if the xxxx:xxxx format is used on non-affy bioSequence.setName(StringUtils.removeStart(header, ">")); return true; } for (String string : split) { string = StringUtils.strip(string); // fill in the sequence database entry if (string.startsWith("gb|") || string.startsWith("gb:")) { String[] splits = StringUtils.split(string, ":|"); String genbankAcc = splits[1]; DatabaseEntry genbank = ExternalDatabaseUtils.getGenbankAccession(genbankAcc); bioSequence.setName(genbank.getAccession()); bioSequence.setSequenceDatabaseEntry(genbank); if (RecordParser.log.isDebugEnabled()) RecordParser.log.debug("Got genbank accession " + genbankAcc + " for " + bioSequence.getName()); break; } } return true; }
From source file:ubic.gemma.core.loader.genome.FastaParser.java
/** * The following formats are supported/*from www. ja va 2 s .c om*/ * <ul> * <li>GenBank: gi|gi-number|gb|accession|locus * <li>EMBL Data Library : gi|gi-number|emb|accession|locus * <li>DDBJ, DNA Database of Japan : gi|gi-number|dbj|accession|locus * <li>NBRF PIR : pir||entry * <li>Protein Research Foundation : prf||name * <li>SWISS-PROT : sp|accession|name * <li>Brookhaven Protein Data Bank (1) : pdb|entry|chain * <li>Brookhaven Protein Data Bank (2) : entry:chain|PDBID|CHAIN|SEQUENCE * <li>Patents : pat|country|number * <li>GenInfo Backbone Id bbs|number * <li>General database identifier : gnl|database|identifier * <li>NCBI Reference Sequence : ref|accession|locus * <li>Local Sequence identifier : lcl|identifier * <li>NIA 15k and 7k sets : H[0-9A-Z]{1-9}-\d | alternate (example: >H4002F12-5 ) * <li>Generic: probeid * </ul> * * @param bioSequence BA * @param header header * @return boolean */ private boolean parseDeflineHeader(BioSequence bioSequence, String header) { // one of the genbank formats. String[] split = StringUtils.splitPreserveAllTokens(header, "|;"); String firstTag = split[0]; // assert firstTag.startsWith( ">" ); // assert firstTag.length() > 1; firstTag = StringUtils.removeStart(firstTag, ">"); if (firstTag.equals("gi")) { bioSequence.setDescription(split[4]); String genbankAcc = split[3]; // with version number, possibly DatabaseEntry genbank = ExternalDatabaseUtils.getGenbankAccession(genbankAcc); bioSequence.setName(genbank.getAccession()); // without version number. bioSequence.setSequenceDatabaseEntry(genbank); } else if (firstTag.equals("pir")) { bioSequence.setName(split[1]); } else if (firstTag.equals("sp")) { bioSequence.setName(split[1]); bioSequence.setDescription(split[2]); } else if (firstTag.equals("ref")) { bioSequence.setName(split[1]); bioSequence.setDescription(split[2]); } else if (firstTag.equals("lcl")) { bioSequence.setName(split[1]); } else if (firstTag.equals("pdb")) { bioSequence.setName(split[1]); bioSequence.setDescription(split[2]); } else if (firstTag.equals("gnl")) { bioSequence.setName(split[2]); } else if (firstTag.equals("entry:chain")) { bioSequence.setName(split[1]); } else if (firstTag.matches(FastaParser.NIA_HEADER_REGEX)) { return this.parseNIA(bioSequence, header); } else { // generic. bioSequence.setName(split[0]); if (split.length > 1) bioSequence.setDescription(split[1]); // log.warn( "Defline-style FASTA header in unrecognized format, started with " + firstTag ); // return false; } return true; }
From source file:ubic.gemma.core.loader.genome.FastaParser.java
/** * This is a special case, but these are used on microarrays. * * @param bioSequence BA/*from w w w . java2 s .c o m*/ * @param header header * @return boolean */ private boolean parseNIA(BioSequence bioSequence, String header) { String firstTag = StringUtils.removeStart(header, ">"); if (firstTag.contains("alternate")) { RecordParser.log.info(header + ": alternate sequence, skipping"); return false; } String[] subFields = firstTag.split("-"); bioSequence.setName(subFields[0]); bioSequence.setDescription("NIA sequence"); bioSequence.setType(SequenceType.EST); return true; }
From source file:uk.gov.gchq.koryphe.impl.binaryoperator.StringDeduplicateConcat.java
@Override protected String _apply(final String a, final String b) { final Set<String> set = new LinkedHashSet<>(); Collections.addAll(set, p.split(StringUtils.removeStart(a, separator))); Collections.addAll(set, p.split(StringUtils.removeStart(b, separator))); return StringUtils.join(set, separator); }