List of usage examples for java.lang Character toLowerCase
public static int toLowerCase(int codePoint)
From source file:org.disit.servicemap.api.ServiceMapApi.java
public void queryLatLngServices(JspWriter out, RepositoryConnection con, String[] coords, String categorie, String textToSearch, String raggioBus, String raggioSensori, String raggioServizi, String risultatiBus, String risultatiSensori, String risultatiServizi) throws Exception { Configuration conf = Configuration.getInstance(); String sparqlType = conf.get("sparqlType", "virtuoso"); String km4cVersion = conf.get("km4cVersion", "new"); List<String> listaCategorieServizi = new ArrayList<String>(); if (categorie != null) { String[] arrayCategorie = categorie.split(";"); // GESTIONE CATEGORIE listaCategorieServizi = Arrays.asList(arrayCategorie); }// w w w .ja v a 2s.c o m String fc = ""; try { fc = ServiceMap.filterServices(listaCategorieServizi); } catch (Exception e) { } int i = 0; int numeroBus = 0; //if (listaCategorieServizi.contains("NearBusStops")) { if (listaCategorieServizi.contains("BusStop")) { String queryStringNearBusStop = "PREFIX km4c:<http://www.disit.org/km4city/schema#>\n" + "PREFIX km4cr:<http://www.disit.org/km4city/resource#>\n" + "PREFIX schema:<http://schema.org/#>\n" + "PREFIX geo:<http://www.w3.org/2003/01/geo/wgs84_pos#>\n" + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n" + "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX omgeo:<http://www.ontotext.com/owlim/geo#>\n" + "PREFIX foaf:<http://xmlns.com/foaf/0.1/>\n" + "PREFIX skos:<http://www.w3.org/2004/02/skos/core#>\n" + "PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>\n" + "SELECT DISTINCT ?bs (STR(?nome) AS ?nomeFermata) ?bslat ?bslong ?x WHERE {\n" + " ?bs geo:lat ?bslat.\n" + " ?bs geo:long ?bslong.\n" + ServiceMap.geoSearchQueryFragment("?bs", coords, raggioBus) + " ?bs rdf:type km4c:BusStop.\n" + " ?bs foaf:name ?nome.\n" + ServiceMap.textSearchQueryFragment("?bs", "foaf:name", textToSearch) + (km4cVersion.equals("old") ? " FILTER ( datatype(?bslat ) = xsd:float )\n" + " FILTER ( datatype(?bslong ) = xsd:float )\n" : "") + "} ORDER BY ?dist"; if (!risultatiBus.equals("0")) { queryStringNearBusStop += " LIMIT " + risultatiBus; } TupleQuery tupleQueryNearBusStop = con.prepareTupleQuery(QueryLanguage.SPARQL, queryStringNearBusStop); TupleQueryResult resultNearBS = tupleQueryNearBusStop.evaluate(); out.println("{\"Fermate\": "); out.println("{ " + "\"type\": \"FeatureCollection\", " + "\"features\": [ "); int s = 0; while (resultNearBS.hasNext()) { BindingSet bindingSetNearBS = resultNearBS.next(); String valueOfBS = bindingSetNearBS.getValue("bs").stringValue(); String valueOfNomeFermata = bindingSetNearBS.getValue("nomeFermata").stringValue(); String valueOfBSLat = bindingSetNearBS.getValue("bslat").stringValue(); String valueOfBSLong = bindingSetNearBS.getValue("bslong").stringValue(); /*String queryForLinee = "PREFIX km4c:<http://www.disit.org/km4city/schema#>" + "PREFIX km4cr:<http://www.disit.org/km4city/resource/>" + "PREFIX schema:<http://schema.org/>" + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>" + "PREFIX geo:<http://www.w3.org/2003/01/geo/wgs84_pos#>" + "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>" + "PREFIX vcard:<http://www.w3.org/2006/vcard/ns#>" + "PREFIX foaf:<http://xmlns.com/foaf/0.1/>" + "PREFIX dcterms:<http://purl.org/dc/terms/>" + "SELECT DISTINCT ?id WHERE {" + " ?tpll rdf:type km4c:PublicTransportLine." + " ?tpll dcterms:identifier ?id." + " ?tpll km4c:hasRoute ?route." + " ?route km4c:hasSection ?rs." + " ?rs km4c:endsAtStop ?bs1." + " ?rs km4c:startsAtStop ?bs2." + " { ?bs1 foaf:name \"" + valueOfNomeFermata + "\"." + " }UNION " + " {?bs2 foaf:name \"" + valueOfNomeFermata + "\" . " + " } " + "} ORDER BY ?id "; TupleQuery tupleQueryForLinee = con.prepareTupleQuery(QueryLanguage.SPARQL, queryForLinee);*/ TupleQueryResult resultLinee = queryBusLines(valueOfNomeFermata, con); String valueOfLinee = ""; if (resultLinee != null) { while (resultLinee.hasNext()) { BindingSet bindingSetLinee = resultLinee.next(); String idLinee = bindingSetLinee.getValue("id").stringValue(); valueOfLinee = valueOfLinee + " - " + idLinee; } } if (s != 0) { out.println(", "); } out.println("{ " + " \"geometry\": { " + " \"type\": \"Point\", " + " \"coordinates\": [ " + " " + valueOfBSLong + ", " + " " + valueOfBSLat + " " + " ] " + "}, " + "\"type\": \"Feature\", " + "\"properties\": { " + " \"nome\": \"" + escapeJSON(valueOfNomeFermata) + "\", " + " \"tipo\": \"fermata\", " // *** INSERIMENTO serviceType + " \"serviceType\": \"NearBusStop\", " + " \"linee\": \"" + valueOfLinee.substring(3) + "\", " // ********************************************** + " \"serviceUri\": \"" + valueOfBS + "\" " + "}, " + "\"id\": " + Integer.toString(s + 1) + " " + "}"); s++; numeroBus++; } out.println("]}"); //if (categorie.equals("NearBusStops")) { if (categorie.equals("BusStop")) { out.println("}"); } } int numeroSensori = 0; //if (listaCategorieServizi.contains("RoadSensor")) { if (listaCategorieServizi.contains("SensorSite")) { String queryStringNearSensori = "PREFIX km4c:<http://www.disit.org/km4city/schema#>\n" + "PREFIX km4cr:<http://www.disit.org/km4city/resource#>\n" + "PREFIX geo:<http://www.w3.org/2003/01/geo/wgs84_pos#>\n" + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n" + "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX schema:<http://schema.org/>\n" + "PREFIX dcterms:<http://purl.org/dc/terms/>\n" + "PREFIX dct:<http://purl.org/dc/terms/#>\n" + "PREFIX omgeo:<http://www.ontotext.com/owlim/geo#>\n" + "PREFIX foaf:<http://xmlns.com/foaf/0.1/>\n" + "PREFIX skos:<http://www.w3.org/2004/02/skos/core#>\n" + "PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>\n" + "SELECT DISTINCT ?sensor ?idSensore ?lat ?long ?address ?x WHERE {\n" + " ?sensor rdf:type km4c:SensorSite.\n" + " ?sensor geo:lat ?lat.\n" + " ?sensor geo:long ?long.\n" + " ?sensor dcterms:identifier ?idSensore.\n" + ServiceMap.textSearchQueryFragment("?sensor", "?p", textToSearch) + ServiceMap.geoSearchQueryFragment("?sensor", coords, raggioBus) + " ?sensor schema:streetAddress ?address.\n" + "} ORDER BY ?dist"; if (!risultatiSensori.equals("0")) { queryStringNearSensori += " LIMIT " + risultatiSensori; } TupleQuery tupleQuerySensori = con.prepareTupleQuery(QueryLanguage.SPARQL, queryStringNearSensori); TupleQueryResult resultNearSensori = tupleQuerySensori.evaluate(); //if (!listaCategorieServizi.contains("NearBusStops")) { if (!listaCategorieServizi.contains("BusStop")) { out.println("{\"Sensori\": "); } else { out.println(", \"Sensori\": "); } out.println("{ " + "\"type\": \"FeatureCollection\", " + "\"features\": [ "); while (resultNearSensori.hasNext()) { // out.println(result); BindingSet bindingSetNearSensori = resultNearSensori.next(); String valueOfId = bindingSetNearSensori.getValue("idSensore").stringValue(); String valueOfIdService = bindingSetNearSensori.getValue("sensor").stringValue(); String valueOfLat = bindingSetNearSensori.getValue("lat").stringValue(); String valueOfLong = bindingSetNearSensori.getValue("long").stringValue(); String valueOfAddress = bindingSetNearSensori.getValue("address").stringValue(); if (i != 0) { out.println(", "); } out.println("{ " + " \"geometry\": { " + " \"type\": \"Point\", " + " \"coordinates\": [ " + " " + valueOfLong + ", " + " " + valueOfLat + " " + " ] " + "}, " + "\"type\": \"Feature\", " + "\"properties\": { " + " \"nome\": \"" + escapeJSON(valueOfId) + "\", " + " \"tipo\": \"sensore\", " // *** INSERIMENTO serviceType + " \"serviceType\": \"RoadSensor\", " // ********************************************** + " \"serviceUri\": \"" + valueOfIdService + "\", " + " \"indirizzo\": \"" + escapeJSON(valueOfAddress) + "\" " + "}, " + "\"id\": " + Integer.toString(i + 1) + " " + "}"); i++; numeroSensori++; } out.println("]}"); //if (categorie.equals("RoadSensor")) { if (categorie.equals("SensorSite")) { out.println("}"); } } int numeroServizi = 0; //if (!categorie.equals("NearBusStops") && !categorie.equals("RoadSensor") && !categorie.equals("RoadSensor;NearBusStops") && !categorie.equals("NearBusStops;RoadSensor")) { if (!categorie.equals("BusStop") && !categorie.equals("SensorSite") && !categorie.equals("SensorSite;BusStop") && !categorie.equals("BusStop;SensorSite")) { String queryStringServiceNear = "PREFIX km4c:<http://www.disit.org/km4city/schema#>\n" + "PREFIX km4cr:<http://www.disit.org/km4city/resource#>\n" + "PREFIX schema:<http://schema.org/>\n" + "PREFIX geo:<http://www.w3.org/2003/01/geo/wgs84_pos#>\n" + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n" + "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX omgeo:<http://www.ontotext.com/owlim/geo#>\n" + "PREFIX foaf:<http://xmlns.com/foaf/0.1/>\n" + "PREFIX skos:<http://www.w3.org/2004/02/skos/core#>\n" + "PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>\n" + "PREFIX dc:<http://purl.org/dc/elements/1.1/>\n" + "SELECT distinct ?ser ?serAddress ?elat ?elong ?sType ?sCategory ?sTypeIta ?sName ?email ?note ?multimedia ?description ?x WHERE {\n" + " ?ser rdf:type km4c:Service" + (sparqlType.equals("virtuoso") ? " OPTION (inference \"urn:ontology\")" : "") + ".\n" + " OPTIONAL {?ser <http://schema.org/name> ?sName}\n" + " ?ser <http://schema.org/streetAddress> ?serAddress.\n" + " OPTIONAL {?ser skos:note ?note}\n" + " OPTIONAL {?ser dc:description ?description" + " FILTER(LANG(?description) = \"it\")" + " }\n" + " OPTIONAL {?ser km4c:multimediaResource ?multimedia}\n" + " OPTIONAL {?ser schema:email ?email }\n" + ServiceMap.textSearchQueryFragment("?ser", "?p", textToSearch) + " {\n" + " ?ser km4c:hasAccess ?entry.\n" + " ?entry geo:lat ?elat.\n" + " ?entry geo:long ?elong.\n" + ServiceMap.geoSearchQueryFragment("?entry", coords, raggioServizi) + " } UNION {\n" + " ?ser geo:lat ?elat.\n" + " ?ser geo:long ?elong.\n" + ServiceMap.geoSearchQueryFragment("?ser", coords, raggioServizi) + " }\n" + fc + (!km4cVersion.equals("old") ? " graph ?g {?ser a ?sType. FILTER(?sType!=km4c:RegularService && ?sType!=km4c:Service && ?sType!=km4c:DigitalLocation && ?sType!=km4c:TransverseService)}\n" + " ?sType rdfs:subClassOf ?sCategory. FILTER(?sCategory != <http://www.w3.org/2003/01/geo/wgs84_pos#SpatialThing>) " + " ?sType rdfs:label ?sTypeIta. FILTER(LANG(?sTypeIta)=\"it\")\n" : "") + "} ORDER BY ?dist"; if (!risultatiServizi.equals("0")) { queryStringServiceNear += " LIMIT " + risultatiServizi; } TupleQuery tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, queryStringServiceNear); TupleQueryResult result = tupleQuery.evaluate(); //if (!listaCategorieServizi.contains("NearBusStops") && !listaCategorieServizi.contains("RoadSensor")) { if (!listaCategorieServizi.contains("BusStop") && !listaCategorieServizi.contains("SensorSite")) { out.println("{\"Servizi\": "); } else { out.println(", \"Servizi\": "); } out.println("{ " + "\"type\": \"FeatureCollection\", " + "\"features\": [ "); int w = 0; while (result.hasNext()) { BindingSet bindingSet = result.next(); String valueOfSer = bindingSet.getValue("ser").stringValue(); String valueOfSerAddress = ""; if (bindingSet.getValue("serAddress") != null) { valueOfSerAddress = bindingSet.getValue("serAddress").stringValue(); } String valueOfSType = ""; if (bindingSet.getValue("sType") != null) { valueOfSType = bindingSet.getValue("sType").stringValue(); } String valueOfSTypeIta = ""; if (bindingSet.getValue("sTypeIta") != null) { valueOfSTypeIta = bindingSet.getValue("sTypeIta").stringValue(); //valueOfSTypeIta = Character.toLowerCase(valueOfSTypeIta.charAt(0)) + valueOfSTypeIta.substring(1); valueOfSTypeIta = valueOfSTypeIta.replace(" ", "_"); valueOfSTypeIta = valueOfSTypeIta.replace("'", ""); } // DICHIARAZIONE VARIABILI serviceType e serviceCategory per ICONA String subCategory = ""; if (bindingSet.getValue("sType") != null) { subCategory = bindingSet.getValue("sType").stringValue(); subCategory = subCategory.replace("http://www.disit.org/km4city/schema#", ""); subCategory = Character.toLowerCase(subCategory.charAt(0)) + subCategory.substring(1); subCategory = subCategory.replace(" ", "_"); } String category = ""; if (bindingSet.getValue("sCategory") != null) { category = bindingSet.getValue("sCategory").stringValue(); category = category.replace("http://www.disit.org/km4city/schema#", ""); category = Character.toLowerCase(category.charAt(0)) + category.substring(1); category = category.replace(" ", "_"); } String serviceType = category + "_" + subCategory; String valueOfSName = ""; if (bindingSet.getValue("sName") != null) { valueOfSName = bindingSet.getValue("sName").stringValue(); } else { valueOfSName = subCategory.replace("_", " ").toUpperCase(); } String valueOfELat = bindingSet.getValue("elat").stringValue(); String valueOfELong = bindingSet.getValue("elong").stringValue(); String valueOfNote = ""; if (bindingSet.getValue("note") != null) { valueOfNote = bindingSet.getValue("note").stringValue(); } String valueOfEmail = ""; if (bindingSet.getValue("email") != null) { valueOfEmail = bindingSet.getValue("email").stringValue(); } Normalizer.normalize(valueOfNote, Normalizer.Form.NFD).replaceAll("[^\\p{ASCII}]", ""); valueOfNote = valueOfNote.replaceAll("[^A-Za-z0-9 ]+", ""); if (w != 0) { out.println(", "); } out.println("{ " + " \"geometry\": { " + " \"type\": \"Point\", " + " \"coordinates\": [ " + " " + valueOfELong + ", " + " " + valueOfELat + " " + " ] " + "}, " + "\"type\": \"Feature\", " + "\"properties\": { " + " \"nome\": \"" + escapeJSON(valueOfSName) + "\", " + " \"tipo\": \"" + escapeJSON(valueOfSTypeIta) + "\", " // *** INSERIMENTO serviceType + " \"serviceType\": \"" + escapeJSON(mapServiceType(serviceType)) + "\", " // ********************************************** + " \"email\": \"" + escapeJSON(valueOfEmail) + "\", " + " \"note\": \"" + escapeJSON(valueOfNote) + "\", " + " \"serviceUri\": \"" + escapeJSON(valueOfSer) + "\", " + " \"indirizzo\": \"" + escapeJSON(valueOfSerAddress) + "\" " + "}, " + "\"id\": " + Integer.toString(w + 1) + " " + "}"); w++; numeroServizi++; } out.println("]}}"); } else { if (categorie.equals("SensorSite;BusStop") || categorie.equals("BusStop;SensorSite")) { out.println("}"); } } }
From source file:de.uni_koblenz.jgralab.utilities.rsa.Rsa2Tg.java
private void convertToIncidenceClass(EdgeClass oldEdgeClass, de.uni_koblenz.jgralab.Direction direction, AttributedElementClass oldVertexClass, EdgeClass newEdgeClass) { assert oldEdgeClass.getDegree(ConnectsToEdgeClass_connectedEdgeClass.class) <= 2; IncidenceClass from = null;// w w w. j a v a2 s . co m IncidenceClass to = null; Edge containsGraphElementClass = null; for (Edge edge : oldEdgeClass.getIncidentEdges()) { if (ConnectsToEdgeClass.class.isInstance(edge)) { IncidenceClass ic = (IncidenceClass) ((ConnectsToEdgeClass) edge).getAlpha(); if (ic.get_direction() == de.uni_koblenz.jgralab.grumlschema.structure.Direction.VERTEX_TO_EDGE) { from = ic; } else { to = ic; } } else if (ContainsGraphElementClass.class.isInstance(edge)) { containsGraphElementClass = edge; } else { throw new ProcessingException(getParser(), getFileName(), "The UML association '" + oldEdgeClass.get_qualifiedName() + "' must not have an incident edge of type '" + edge.getType().getQualifiedName() + "'."); } } containsGraphElementClass.delete(); assert from != null && to != null : currentClassId; de.uni_koblenz.jgralab.grumlschema.structure.Direction directionOfNewIncidence = extractDirection(from, oldVertexClass); IncidenceClass atVertex = directionOfNewIncidence == de.uni_koblenz.jgralab.grumlschema.structure.Direction.VERTEX_TO_EDGE ? from : to; IncidenceClass atEdge = atVertex == from ? to : from; // create a new IncidenceClass and set its attributes IncidenceClass newIncidenceClass = sg.createIncidenceClass(); newIncidenceClass.set_abstract(oldEdgeClass.is_abstract()); newIncidenceClass.set_direction(directionOfNewIncidence); // store the IncidenceType at the wrong IncidenceClass // @see convertToEdgeClasses() newIncidenceClass.set_incidenceType(atEdge.get_incidenceType()); newIncidenceClass.set_maxEdgesAtVertex(atVertex.get_maxEdgesAtVertex()); newIncidenceClass.set_maxVerticesAtEdge(atEdge.get_maxEdgesAtVertex()); newIncidenceClass.set_minEdgesAtVertex(atVertex.get_minEdgesAtVertex()); newIncidenceClass.set_minVerticesAtEdge(atEdge.get_minEdgesAtVertex()); String roleName = extractSimpleName(oldEdgeClass.get_qualifiedName()); newIncidenceClass.set_roleName( Character.toLowerCase(roleName.charAt(0)) + (roleName.length() > 1 ? roleName.substring(1) : "")); if (isNestingIncidenceOrEdgeClass.isMarked(oldEdgeClass)) { isNestingIncidenceOrEdgeClass.mark(newIncidenceClass); isNestingIncidenceOrEdgeClass.removeMark(oldEdgeClass); } else if (atVertex.get_incidenceType() != IncidenceType.EDGE) { throw new ProcessingException(getFileName(), "The IncidenceType " + atVertex.get_incidenceType() + " of the modelled association '" + newIncidenceClass.get_roleName() + "' must be defined at the other incidence." + (atVertex.get_incidenceType() == IncidenceType.COMPOSITION ? " If you wandet to medel a nesting relation with this composition, you have to define the stereotype <<nested>>." : "")); } // set specializations if (generalizations.isMarked(oldEdgeClass)) { generalizations.mark(newIncidenceClass, generalizations.getMark(oldEdgeClass)); generalizations.removeMark(oldEdgeClass); } // set redefines if (redefinesAtVertex.isMarked(from)) { redefinesAtVertex.mark(newIncidenceClass, redefinesAtVertex.getMark(from)); redefinesAtVertex.removeMark(from); } if (redefinesAtVertex.isMarked(to)) { redefinesAtEdge.mark(newIncidenceClass, redefinesAtVertex.getMark(to)); redefinesAtVertex.removeMark(to); } // set subsets if (subsets.isMarked(from)) { subsets.mark(newIncidenceClass, subsets.getMark(from)); subsets.removeMark(from); } if (subsets.isMarked(to)) { subsets.mark(newIncidenceClass, subsets.getMark(to)); subsets.removeMark(to); } // connect IncidenceClass with new EdgeClass and original VertexClass sg.createConnectsToVertexClass(newIncidenceClass, (VertexClass) ((BinaryEdge) atVertex .getFirstIncidence(ConnectsToVertexClass_incidenceClassAtVertex.class).getEdge()) .getOmega()); sg.createConnectsToEdgeClass(newIncidenceClass, newEdgeClass); // find xmi ids of the old classes String xmiIdOldEdgeClass = null; String xmiIdOldVertexClass = null; String xmiIdOldAtVertexIncidenceClass = null; String xmiIdOldAtEdgeIncidenceClass = null; for (Entry<String, Vertex> entry : idMap.entrySet()) { if (entry.getValue() == oldEdgeClass) { xmiIdOldEdgeClass = entry.getKey(); } else if (entry.getValue() == oldVertexClass) { xmiIdOldVertexClass = entry.getKey(); } else if (entry.getValue() == atVertex) { xmiIdOldAtVertexIncidenceClass = entry.getKey(); } else if (entry.getValue() == atEdge) { xmiIdOldAtEdgeIncidenceClass = entry.getKey(); } } idMap.put(xmiIdOldVertexClass, newEdgeClass); idMap.put(xmiIdOldEdgeClass, newIncidenceClass); idMap.put(xmiIdOldAtEdgeIncidenceClass, newIncidenceClass); idMap.put(xmiIdOldAtVertexIncidenceClass, newIncidenceClass); // store the id of the old IncidenceClass which is connected to the // replaces old VertexClass, which is now an EdgeClass // @see #idsOfOldIncidenceclassAtNewEdgeClass idsOfOldIncidenceclassAtNewEdgeClass.add(xmiIdOldAtEdgeIncidenceClass); // delete old EdgeClass oldEdgeClass.delete(); atVertex.delete(); atEdge.delete(); }
From source file:de.innovationgate.utils.WGUtils.java
/** * Removes all characters from a string that are not legal as JavaScript identifier * Interprets an underscore as the next character being forced to upper case. * The upper case rules, that are enforced when param enforceUpperCaseRules is true are: * <ul>//from www . j a v a 2 s. co m * <li>Non-alphabetic characters at the beginning are stripped off * <li>The first alphabetic character is uppercase * <li>An alphabetic character preceded by an underscore (which is removed) will also be uppercase * <li>All other alphabetic characters are lowercase * </ul> * @param txt The string * @param enforceUpperCaseRules If true enforces the upper case rules described above, meant to transfor, a lowercase design reference to an Object Identifier with cases in an reversible way. * In that case the created string can be reverted to the original by using {@link #fromJSIdentifier(String)}. * @return The string converted to a valid JS identifier */ public static String toJSIdentifier(String txt, boolean enforceUpperCaseRules) { StringBuilder out = new StringBuilder(); // Flags for enforceUpperCaseRules boolean upperCase = true; // First character is uppercase boolean startCharacter = true; for (int i = 0; i < txt.length(); i++) { Character c = txt.charAt(i); if (enforceUpperCaseRules) { // Must start with a letter if (startCharacter && !Character.isLetter(c)) { continue; } // Convert letters to uppercase, depending on flag if (Character.isLetter(c)) { if (upperCase) { c = Character.toUpperCase(c); upperCase = false; } else { c = Character.toLowerCase(c); } } // Trigger the next letter to be uppercase else if (c == '_') { upperCase = true; continue; } } Pattern p = (startCharacter ? JS_IDENTIFIER_FIRSTCHARS : JS_IDENTIFIER_CHARS); if (p.matcher(c.toString()).matches()) { out.append(c); startCharacter = false; } else if (enforceUpperCaseRules) { throw new IllegalArgumentException( "This string cannot be transformed to a reversible JS identifier because it contains invalid characters: " + txt); } } return out.toString(); }
From source file:org.eclipse.swt.examples.accessibility.CTable.java
void onKeyDown(Event event) { if (ignoreKey) { ignoreKey = false;/* ww w. j a v a 2 s . c om*/ return; } ignoreKey = true; notifyListeners(event.type, event); event.type = SWT.None; if (!event.doit) return; if (focusItem == null) return; if ((event.stateMask & SWT.SHIFT) == 0 && event.keyCode != SWT.SHIFT) { anchorItem = null; } switch (event.keyCode) { case SWT.ARROW_UP: onArrowUp(event.stateMask); return; case SWT.ARROW_DOWN: onArrowDown(event.stateMask); return; case SWT.ARROW_LEFT: onArrowLeft(event.stateMask); return; case SWT.ARROW_RIGHT: onArrowRight(event.stateMask); return; case SWT.PAGE_UP: onPageUp(event.stateMask); return; case SWT.PAGE_DOWN: onPageDown(event.stateMask); return; case SWT.HOME: onHome(event.stateMask); return; case SWT.END: onEnd(event.stateMask); return; } if (event.character == ' ') { onSpace(); return; } if (event.character == SWT.CR) { onCR(); return; } if ((event.stateMask & SWT.CTRL) != 0) return; int initialIndex = focusItem.index; char character = Character.toLowerCase(event.character); /* check available items from current focus item to bottom */ for (int i = initialIndex + 1; i < itemsCount; i++) { CTableItem item = items[i]; String text = item.getText(0, false); if (text.length() > 0) { if (Character.toLowerCase(text.charAt(0)) == character) { selectItem(item, false); setFocusItem(item, true); redrawItem(i, true); showItem(item); Event newEvent = new Event(); newEvent.item = item; notifyListeners(SWT.Selection, newEvent); return; } } } /* check available items from top to current focus item */ for (int i = 0; i < initialIndex; i++) { CTableItem item = items[i]; String text = item.getText(0, false); if (text.length() > 0) { if (Character.toLowerCase(text.charAt(0)) == character) { selectItem(item, false); setFocusItem(item, true); redrawItem(i, true); showItem(item); Event newEvent = new Event(); newEvent.item = item; notifyListeners(SWT.Selection, newEvent); return; } } } }
From source file:de.innovationgate.utils.WGUtils.java
/** * Reconstructs the original string from the output of {@link #toJSIdentifier(String, boolean)} with enforced upper case rules. * @param txt A string created by {@link #toJSIdentifier(String)} with enforced upper case rules * @return The original string/* w w w.j a v a 2s . c o m*/ */ public static String fromJSIdentifier(String txt) { StringBuilder out = new StringBuilder(); int newWordIdx = -1; for (int i = 0; i < txt.length(); i++) { Character c = txt.charAt(i); newWordIdx++; if (Character.isUpperCase(c)) { if (newWordIdx != 0) { out.append("_"); } c = Character.toLowerCase(c); } else if (c == '.') { newWordIdx = -1; } out.append(c); } return out.toString(); }
From source file:com.quinsoft.epamms.ZGlobal1_Operation.java
public void SetFirstCharacterCase(StringBuilder sbTarget, int bUpper) { if (sbTarget.length() > 0) { char ch;//from w ww . jav a 2 s . c o m if (bUpper != 0) { ch = Character.toUpperCase(sbTarget.charAt(0)); } else { ch = Character.toLowerCase(sbTarget.charAt(0)); } sbTarget.setCharAt(0, ch); } }
From source file:base.BasePlayer.FileRead.java
java.util.ArrayList<java.util.Map.Entry<Integer, Byte>> getMismatches(SAMRecord samRecord, Reads readClass, double[][] coverageArray, SplitClass split) { if (readClass == null) { sample.resetreadHash();//from w w w.j a va 2s . c om } java.util.ArrayList<java.util.Map.Entry<Integer, Byte>> mismatches = null; String MD = samRecord.getStringAttribute("MD"); String SA = samRecord.getStringAttribute("SA"); if (samRecord.getReadBases().length == 0) { return null; } try { if (MD == null) { if (readClass.sample.MD) { readClass.sample.MD = false; } } if ((readClass.sample.MD || MD != null) && (samRecord.getCigarString().contains("S") && Settings.softClips == 0)/* && ((!samRecord.getCigarString().contains("S") && SA == null) || SA !=null)*/) { if (!readClass.sample.MD) { readClass.sample.MD = true; } java.util.ArrayList<java.util.Map.Entry<Integer, Integer>> insertions = null; int softstart = 0; if (samRecord.getCigarLength() > 1) { readstart = samRecord.getUnclippedStart(); if (readClass.getCoverageStart() > readstart) { return null; } readpos = 0; for (int i = 0; i < samRecord.getCigarLength(); i++) { element = samRecord.getCigar().getCigarElement(i); if (element.getOperator().compareTo(CigarOperator.MATCH_OR_MISMATCH) == 0) { for (int r = readpos; r < readpos + element.getLength(); r++) { try { coverageArray[((readstart + r) - readClass.getCoverageStart())][0]++; } catch (Exception e) { //TODO } try { if (coverageArray[((readstart + r) - readClass.getCoverageStart())][0] > readClass.getMaxcoverage()) { readClass.setMaxcoverage( coverageArray[((readstart + r) - readClass.getCoverageStart())][0]); } } catch (Exception e) { //TODO } mispos++; } readpos += element.getLength(); } else if (element.getOperator().compareTo(CigarOperator.DELETION) == 0) { for (int d = 0; d < element.getLength(); d++) { readClass.getCoverages()[(readstart + readpos + d) - readClass.getCoverageStart()][Main.baseMap.get((byte) 'D')]++; } readpos += element.getLength(); } else if (element.getOperator().compareTo(CigarOperator.INSERTION) == 0) { if (insertions == null) { insertions = new java.util.ArrayList<java.util.Map.Entry<Integer, Integer>>(); } java.util.Map.Entry<Integer, Integer> ins = new java.util.AbstractMap.SimpleEntry<>( readpos, element.getLength()); insertions.add(ins); readClass.getCoverages()[(readstart + readpos) - readClass.getCoverageStart()][Main.baseMap.get((byte) 'I')]++; mispos += element.getLength(); } else if (element.getOperator().compareTo(CigarOperator.SOFT_CLIP) == 0) { if (i == 0 && SA == null) { softstart = element.getLength(); } if (Settings.softClips == 1) { for (int r = readpos; r < readpos + element.getLength(); r++) { if (SA == null) { coverageArray[((readstart + r) - readClass.getCoverageStart())][0]++; } mispos++; } readpos += element.getLength(); } else { if (i == 0) { readstart = samRecord.getAlignmentStart(); mispos += element.getLength(); } } } else if (element.getOperator().compareTo(CigarOperator.HARD_CLIP) == 0) { if (i == 0) { readstart = samRecord.getAlignmentStart(); } } else if (element.getOperator().compareTo(CigarOperator.SKIPPED_REGION) == 0) { readpos += element.getLength(); } } } else { readstart = samRecord.getUnclippedStart(); for (int i = 0; i < samRecord.getReadLength(); i++) { try { if (readClass.getCoverageStart() > readstart) { break; } coverageArray[(readstart + i) - readClass.getCoverageStart()][0]++; if (coverageArray[(samRecord.getUnclippedStart() - readClass.getCoverageStart()) + i][0] > readClass.getMaxcoverage()) { readClass.setMaxcoverage( coverageArray[(samRecord.getUnclippedStart() - readClass.getCoverageStart()) + i][0]); } } catch (Exception e) { ErrorLog.addError(e.getStackTrace()); e.printStackTrace(); FileRead.cancelreadread = true; break; } } } if (MD != null) { try { Integer.parseInt(MD); return null; } catch (Exception ex) { readstart = samRecord.getAlignmentStart() - softstart; char[] chars = MD.toCharArray(); String bases = samRecord.getReadString(); String qualities = samRecord.getBaseQualityString(); if (SA == null) { softstart = 0; } int readpos = softstart; int mispos = softstart; int add = 0; int digitpointer = 0, insertionpointer = 0; boolean first = true; for (int i = 0; i < chars.length; i++) { try { if (insertions != null) { if (insertionpointer < insertions.size() && insertions.get(insertionpointer).getKey() <= readpos) { while (insertionpointer < insertions.size() && insertions.get(insertionpointer).getKey() <= readpos) { mispos += insertions.get(insertionpointer).getValue(); insertionpointer++; } } } if (Character.isDigit(chars[i])) { digitpointer = i + 1; while (digitpointer < chars.length && Character.isDigit(chars[digitpointer])) { digitpointer++; } if (digitpointer == chars.length) { if ((mispos + Integer.parseInt(MD.substring(i, digitpointer))) > samRecord .getReadLength()) { if (!first) { break; } first = false; readpos = 0; mispos = 0; i = -1; digitpointer = 0; insertionpointer = 0; mismatches.clear(); continue; } break; } else { add = Integer.parseInt(MD.substring(i, digitpointer)); readpos += add; mispos += add; } i = digitpointer - 1; } else if (chars[i] != '^') { if (mismatches == null) { mismatches = new java.util.ArrayList<java.util.Map.Entry<Integer, Byte>>(); } readClass.getCoverages()[(readstart + readpos) - readClass.getCoverageStart()][Main.baseMap .get((byte) bases.charAt(mispos))]++; if (samRecord.getBaseQualityString().length() != 1 && (int) qualities.charAt(mispos) - readClass.sample.phred < Settings.baseQ) { java.util.Map.Entry<Integer, Byte> mismatch = new java.util.AbstractMap.SimpleEntry<>( readpos, (byte) Character.toLowerCase(bases.charAt(mispos))); mismatches.add(mismatch); } else { java.util.Map.Entry<Integer, Byte> mismatch = new java.util.AbstractMap.SimpleEntry<>( readpos, (byte) bases.charAt(mispos)); mismatches.add(mismatch); } mispos++; readpos++; } else { digitpointer = i + 1; while (!Character.isDigit(chars[digitpointer])) { digitpointer++; readpos++; } i = digitpointer - 1; } } catch (Exception exc) { if (!first) { break; } first = false; readpos = 0; mispos = 0; i = -1; digitpointer = 0; insertionpointer = 0; mismatches.clear(); } } } } } else { /*if(split.getReference() == null) { readClass.setReference(new ReferenceSeq(splitIndex.chrom,start-500, end+500, Main.referenceFile)); }*/ //timecounter = 0; /*while(splitIndex.getReadReference() == null) { Thread.sleep(100); timecounter++; if(timecounter > 20) { break; } } Thread.sleep(0); */ // if(splitIndex.getReadReference() == null) { //splitIndex.setReference(new ReferenceSeq(splitIndex.chrom,startpos-searchwindow-1, endpos+searchwindow +200, Main.referenceFile)); // return null; //} if (samRecord.getCigarLength() > 1) { readstart = samRecord.getUnclippedStart(); readpos = 0; mispos = 0; /*if(readClass.getCoverageStart()>readstart) { return null; }*/ if (mismatches == null) { mismatches = new java.util.ArrayList<java.util.Map.Entry<Integer, Byte>>(); } for (int i = 0; i < samRecord.getCigarLength(); i++) { element = samRecord.getCigar().getCigarElement(i); if (element.getOperator().compareTo(CigarOperator.MATCH_OR_MISMATCH) == 0) { for (int r = readpos; r < readpos + element.getLength(); r++) { if (((readstart + r) - split.getReadReference().getStartPos() - 1) > split.getReadReference().getSeq().length - 1) { split.getReadReference().append(samRecord.getUnclippedEnd() + 1000); } if (((readstart + r) - split.getReadReference().getStartPos() - 1) < 0) { split.getReadReference().appendToStart(samRecord.getUnclippedStart() - 1000); } try { if (samRecord.getReadBases()[mispos] != split.getReadReference() .getSeq()[((readstart + r) - split.getReadReference().getStartPos() - 1)]) { readClass.getCoverages()[(readstart + r) - readClass.getCoverageStart()][Main.baseMap .get((byte) samRecord.getReadBases()[mispos])]++; if (samRecord.getBaseQualityString().length() != 1 && (int) samRecord.getBaseQualityString().charAt(mispos) - readClass.sample.phred < Settings.baseQ) { java.util.Map.Entry<Integer, Byte> mismatch = new java.util.AbstractMap.SimpleEntry<>( r, (byte) Character .toLowerCase((char) samRecord.getReadBases()[mispos])); mismatches.add(mismatch); } else { java.util.Map.Entry<Integer, Byte> mismatch = new java.util.AbstractMap.SimpleEntry<>( r, samRecord.getReadBases()[mispos]); mismatches.add(mismatch); } } } catch (Exception e) { System.out.println(samRecord.getReadBases().length); e.printStackTrace(); } try { coverageArray[((readstart + r) - readClass.getCoverageStart())][0]++; if (coverageArray[((readstart + r) - readClass.getCoverageStart())][0] > readClass.getMaxcoverage()) { readClass.setMaxcoverage( coverageArray[((readstart + r) - readClass.getCoverageStart())][0]); } } catch (Exception e) { //TODO } mispos++; } readpos += element.getLength(); } else if (element.getOperator().compareTo(CigarOperator.DELETION) == 0) { // readWidth+=element.getLength(); for (int d = 0; d < element.getLength(); d++) { readClass.getCoverages()[(readstart + readpos + d) - readClass.getCoverageStart()][Main.baseMap.get((byte) 'D')]++; } readpos += element.getLength(); } else if (element.getOperator().compareTo(CigarOperator.INSERTION) == 0) { readClass.getCoverages()[(readstart + readpos) - readClass.getCoverageStart()][Main.baseMap.get((byte) 'I')]++; mispos += element.getLength(); } else if (element.getOperator().compareTo(CigarOperator.SOFT_CLIP) == 0) { if (Settings.softClips == 1) { for (int r = readpos; r < readpos + element.getLength(); r++) { if (((readstart + r) - split.getReadReference().getStartPos() - 1) > split.getReadReference().getSeq().length - 1) { split.getReadReference().append(samRecord.getUnclippedEnd() + 1000); } if (((readstart + r) - splitIndex.getReadReference().getStartPos() - 1) < 0) { split.getReadReference() .appendToStart(samRecord.getUnclippedStart() - 1000); } /* if(((readstart+r)-readClass.reference.getStartPos()-1) < 0) { continue; }*/ if (samRecord.getReadBases()[mispos] != split.getReadReference() .getSeq()[((readstart + r) - split.getReadReference().getStartPos() - 1)]) { if (SA == null) { readClass.getCoverages()[(readstart + r) - readClass.getCoverageStart()][Main.baseMap .get(samRecord.getReadBases()[mispos])]++; } if (mismatches == null) { mismatches = new java.util.ArrayList<java.util.Map.Entry<Integer, Byte>>(); } java.util.Map.Entry<Integer, Byte> mismatch = new java.util.AbstractMap.SimpleEntry<>( r, samRecord.getReadBases()[mispos]); mismatches.add(mismatch); } if (SA == null) { coverageArray[((readstart + r) - readClass.getCoverageStart())][0]++; } mispos++; } readpos += element.getLength(); } else { if (i == 0) { readpos += element.getLength(); mispos += element.getLength(); } } } else if (element.getOperator().compareTo(CigarOperator.HARD_CLIP) == 0) { if (i == 0) { readstart = samRecord.getAlignmentStart(); } } else if (element.getOperator().compareTo(CigarOperator.SKIPPED_REGION) == 0) { readpos += element.getLength(); // this.readWidth+=element.getLength(); } } } else { readstart = samRecord.getUnclippedStart(); /*if(readClass.getCoverageStart()>readstart) { return null; }*/ if ((samRecord.getUnclippedEnd() - split.getReadReference().getStartPos() - 1) > split.getReadReference().getSeq().length - 1) { split.getReadReference().append(samRecord.getUnclippedEnd() + 100); } if ((samRecord.getUnclippedStart() - split.getReadReference().getStartPos() - 1) < 0) { split.getReadReference().appendToStart(samRecord.getUnclippedStart() - 100); } for (int r = 0; r < samRecord.getReadLength(); r++) { try { if (samRecord.getReadBases()[r] != split.getReadReference() .getSeq()[((readstart + r) - split.getReadReference().getStartPos() - 1)]) { if ((readstart + r) - readClass.getCoverageStart() < readClass.getCoverages().length - 1) { readClass.getCoverages()[(readstart + r) - readClass.getCoverageStart()][Main.baseMap .get(samRecord.getReadBases()[r])]++; if (mismatches == null) { mismatches = new java.util.ArrayList<java.util.Map.Entry<Integer, Byte>>(); } java.util.Map.Entry<Integer, Byte> mismatch = new java.util.AbstractMap.SimpleEntry<>( r, samRecord.getReadBases()[r]); mismatches.add(mismatch); } } try { coverageArray[(readstart + r) - readClass.getCoverageStart()][0]++; } catch (Exception e) { //TODO //e.printStackTrace(); continue; } if (coverageArray[(samRecord.getUnclippedStart() - readClass.getCoverageStart()) + r][0] > readClass.getMaxcoverage()) { readClass.setMaxcoverage( coverageArray[(samRecord.getUnclippedStart() - readClass.getCoverageStart()) + r][0]); } } catch (Exception e) { ErrorLog.addError(e.getStackTrace()); e.printStackTrace(); return mismatches; } } } } } catch (Exception e) { e.printStackTrace(); return null; } return mismatches; }
From source file:org.apache.commons.lang3.StringUtils.java
/** * <p>Uncapitalizes a String changing the first letter to title case as * per {@link Character#toLowerCase(char)}. No other letters are changed.</p> * * <p>For a word based algorithm, see {@link org.apache.commons.lang3.text.WordUtils#uncapitalize(String)}. * A {@code null} input String returns {@code null}.</p> * * <pre>//from w w w . jav a2 s . c o m * StringUtils.uncapitalize(null) = null * StringUtils.uncapitalize("") = "" * StringUtils.uncapitalize("Cat") = "cat" * StringUtils.uncapitalize("CAT") = "cAT" * </pre> * * @param str the String to uncapitalize, may be null * @return the uncapitalized String, {@code null} if null String input * @see org.apache.commons.lang3.text.WordUtils#uncapitalize(String) * @see #capitalize(String) * @since 2.0 */ public static String uncapitalize(String str) { int strLen; if (str == null || (strLen = str.length()) == 0) { return str; } return new StringBuilder(strLen).append(Character.toLowerCase(str.charAt(0))).append(str.substring(1)) .toString(); }
From source file:org.apache.commons.lang3.StringUtils.java
/** * <p>Swaps the case of a String changing upper and title case to * lower case, and lower case to upper case.</p> * * <ul>/*from w w w . j av a 2 s . co m*/ * <li>Upper case character converts to Lower case</li> * <li>Title case character converts to Lower case</li> * <li>Lower case character converts to Upper case</li> * </ul> * * <p>For a word based algorithm, see {@link org.apache.commons.lang3.text.WordUtils#swapCase(String)}. * A {@code null} input String returns {@code null}.</p> * * <pre> * StringUtils.swapCase(null) = null * StringUtils.swapCase("") = "" * StringUtils.swapCase("The dog has a BONE") = "tHE DOG HAS A bone" * </pre> * * <p>NOTE: This method changed in Lang version 2.0. * It no longer performs a word based algorithm. * If you only use ASCII, you will notice no change. * That functionality is available in org.apache.commons.lang3.text.WordUtils.</p> * * @param str the String to swap case, may be null * @return the changed String, {@code null} if null String input */ public static String swapCase(String str) { if (StringUtils.isEmpty(str)) { return str; } char[] buffer = str.toCharArray(); for (int i = 0; i < buffer.length; i++) { char ch = buffer[i]; if (Character.isUpperCase(ch)) { buffer[i] = Character.toLowerCase(ch); } else if (Character.isTitleCase(ch)) { buffer[i] = Character.toLowerCase(ch); } else if (Character.isLowerCase(ch)) { buffer[i] = Character.toUpperCase(ch); } } return new String(buffer); }
From source file:com.cohort.util.String2.java
/** This changes the characters case to title case (only letters after non-letters are * capitalized). This is simplistic (it doesn't know about acronyms or pH or ...). *//*from w ww . ja va2 s . c om*/ public static String toTitleCase(String s) { if (s == null) return null; int sLength = s.length(); StringBuilder sb = new StringBuilder(s); char c = ' ', oc = ' '; for (int i = 0; i < sLength; i++) { oc = c; c = sb.charAt(i); if (isLetter(c)) sb.setCharAt(i, isLetter(oc) ? Character.toLowerCase(c) : Character.toUpperCase(c)); } return sb.toString(); }