while (true) {
if ($current === $requested) {
break;
}
if (! in_array($requested, $available)) {
break;
}
session()->put('locale', $requested);
break;
}
private static final double RESULT_OF_DIVISION_BY_0 = 9.99;
public static double getPercentageDifference(long currentResult, long previousResult) {
if (previousResult == 0 && currentResult == 0) {
return 0;
} else if (previousResult == 0) {
return RESULT_OF_DIVISION_BY_0;
} else {
return (currentResult - previousResult) * 1.0 / previousResult;
}
}
// Method put on each input component to unregister
// itself from the form
detachFromForm: function detachFromForm(component) {
var componentPos = this.inputs.indexOf(component);
if (componentPos !== -1) {
this.inputs = this.inputs.slice(0, componentPos).concat(this.inputs.slice(componentPos + 1));
}
this.validateForm();
},
oh boy
class {
public State state;
//enums cant take double values...
public struct State
{
public const float IDLE = 0f;
public const float WALKING = 0.5f;
public const float RUNNING = 1f;
}
protected void Stop()
{
SetSpeed(State.IDLE);
}
protected void SetSpeed(float f)
{
agent.speed = f;
if (agent.speed > 1f && agent.speed < 5f)
{
f = State.WALKING;
agent.Resume();
}
else if (agent.speed > 5f)
{
f = State.RUNNING;
agent.Resume();
}
else
{
f = State.IDLE;
agent.Stop();
}
}
}
Who needs static float
when you can have a constant in a nested struct, as a bonus State state
has 0 references in the project
public class SentCon3 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
double input;
char choice;
System.out.println("**** Menu-Driven Temperature Converter*****");
System.out.println("only lowwer case is vaild");
System.out.print("Enter the value to beconverted==> ");
input = scan.nextDouble();
System.out.println("What is your choice?");
System.out.println("a)Fahrenheit to Celsius");
System.out.println("b)Celsius to Fahrenheit");
System.out.println("c)Kelvin to Celsius");
System.out.println("d)Celsius to Kelvin");
System.out.println("e)Kelvin to Fahrenheit");
System.out.println("f)Fahrenheit to Kelvin.");
System.out.print("Please enter your choice ==>");
choice = scan.next().charAt(0);
while (choice == 'a') {
System.out.println((input / 5) * 9 + 32);
break;
}
while (choice == 'b') {
System.out.println((input - 32) * 5 / 9);
break;
}
while (choice == 'c') {
System.out.println(input - 273.15);
break;
}
while (choice == 'd') {
System.out.println(input + 273.15);
break;
}
while (choice == 'e') {
System.out.println((input - 273.5) * 9 / 5 + 32);
break;
}
while (choice == 'f') {
System.out.println((input + 459.67) * 5 / 9);
break;
}
}
}
use while as if!!!!
/**
* fk--folder key,dk--doc key -->value is key string
* dt--doc type,ft--folder type -->both have 19 key options:
* bom tr amend history help info loeid cust cust0-cust9 custhist
* folder type only seen as "history" in toc,why ??do we use other ones? -- it only has one child
* doc type only seen two "tr" and "history" in toc??-- it only has one child
* node with "folder type="history"" is the only child of it parent either "<doc type="tr" key="xxx" trnum="xxx"....." or "<doc type="tr" trnum="xxx""
* <folder type="history" could has more then one doc children .e.g. title="History of AMM31-32-00-720-807" in 700/amm
*
*
*
* folder element has the follwing to identify itself:
* 1, key
* 2, type="history", in this case, folder is the only child of doc element with type ="tr"?????
*
* doc element has the following to identify itself
* 1, key
* 2, type="tr" trnum="xxxxx"
* 3, type="history", in this case, doc isthe only child of a folder element???
*
*
*
* the return json format likes following:
* [
* { "data" : "A node", "children" , "state" : "open" },
* { "data" : "Only child", "state" : "closed" },
* "Ajax node"
* ]
*/
public class XMLToJson
{
private static final Map<String, String> pathMap;
static
{
Map<String, String> aMap = new HashMap<String, String>();
aMap.put("fk", "folder[@key");
aMap.put("ft", "folder[@type");
aMap.put("fth", "folder[@type='history'");
aMap.put("dk", "doc[@key");
aMap.put("dt", "doc[@type");
aMap.put("dth", "doc[@type='history'");
aMap.put("dtrn", "doc[@trnum");
pathMap = Collections.unmodifiableMap(aMap);
}
Util util = new Util();
/*
* @param url the path to TOC.xml
* @param xPathString the short format searched node path
* @throws DocumentException
*
* sample xPathString : "fk:AMM24_fk:AMM24-FM_dk"
*/
@SuppressWarnings({ "unchecked" })
public String getJson(URL url, String xPathString) throws Exception
{
Document TOCDoc = util.getDocument(url);
String jsonString = "[";
Element node = null;
if (xPathString.equals("/"))
{
node = TOCDoc.getRootElement();
}
else
{
String realXPathString = pathMapping(xPathString);
System.out.println(realXPathString);
node = (Element) TOCDoc.selectSingleNode(realXPathString);
}
//List<Element> li = node.elements();
for (Iterator<Element> i = node.elementIterator(); i.hasNext();)
{
Element elem = (Element) i.next();
String eleName = elem.getName();
Boolean hasChildren = false;
if ((elem.elements().size() > 0))
{
hasChildren = true;
//current element has children itself, state shoud be "closed"
}
List<Attribute> list = elem.attributes();
String titleAttrContent = elem.attributeValue("title");
//Boolean isFileAttr = false;
String fileAttrContent = elem.attributeValue("file");
//if (fileAttrContent.isEmpty() )
if (eleName == "doc")
{
//doc element always has "file" attribute
for (Attribute attribute : list)
{
jsonString = jsonString.concat("{");
String attrName = attribute.getName();
//System.out.println("doc arribute Name : " + attrName);
//each one has to have "data" line, "attr" line "state" line and "children" line
jsonString = jsonString.concat("'data':'").concat(titleAttrContent).concat("',");
if (attrName.equals("key"))
{
String keyContent = elem.attributeValue("key");
jsonString = jsonString.concat("'attr':{'id':'").concat(xPathString).concat("_dk:").concat(keyContent).concat("','file':'").concat(fileAttrContent).concat("'}");
break;
}
else if (attrName.equals("trnum"))
{
String trnumContent = elem.attributeValue("trnum");
jsonString = jsonString.concat("'attr':{'id':'").concat(xPathString).concat("_dtrn:").concat(trnumContent).concat("','file':'").concat(fileAttrContent).concat("'}");
break;
}
/* else if (attrName.equals("type"))//type attribute for doc element won't determite what exactly the element is
{
String typeContent = elem.attributeValue("type");
//doc element has type "history"
if (typeContent == "history"){
jsonString = jsonString.concat("'attr':{'id':'").concat(xPathString).concat("_dth,");
}else if (typeContent == "?????"){
//any values for type attribute need to concern????
}
}
else if (attrName.equals("file"))
{
}*/
}
if (hasChildren)
{
//state set up as "closed" and no need to set up "children" field
jsonString = jsonString.concat(",'state':'closed'");
}
else
{
//no need to put anything
//jsonString = jsonString.concat("'state':'???'");
}
jsonString = jsonString.concat("},");
}
else if (eleName == "folder")
{
jsonString = jsonString.concat("{");
for (Attribute attribute : list)
{
String attrName = attribute.getName();
jsonString = jsonString.concat("'data':'").concat(titleAttrContent).concat("',");
if (attrName.equals("key"))
{
String keyContent = elem.attributeValue("key");
jsonString = jsonString.concat("'attr':{'id':'").concat(xPathString).concat("_fk:").concat(keyContent).concat("'}");
if (fileAttrContent != null)
{
jsonString = jsonString.concat("','file':'").concat(fileAttrContent).concat("'}");
}
break;
}
else if (attrName.equals("type"))
{
String typeContent = elem.attributeValue("type");
//doc element has type "history"
if (typeContent == "history")
{
jsonString = jsonString.concat("'attr':{'id':'").concat(xPathString).concat("_fth,");
}
else if (typeContent == "?????")
{
//any values need to concern????
}
break;
}
}
jsonString = jsonString.concat("},");
}
continue;
}
//return list;
jsonString = jsonString.substring(0, jsonString.length() - 1);
jsonString = jsonString.concat("]");
return jsonString;
}
/*
* read xpathstring from post request and generate the real xpath for toc
*/
public String getXPathString()
{
//readPostRequest()
return null;
}
/*
* post string looks like : "fk:LOETR_dtrn:TR12-118_fth_dth"
* it represents the inner doc elemnet:
* <folder key="LOETR" type="loetr" title="List of Effective TRs" file="loetr.html">
* <doc type="tr" trnum="TR12-118" trdate="May 07/2012" title="[TR12-118] TASK AMM12-31-00-660-806 - Inspection and Removal of De-Hydrated Anti-Icing Fluid inside the Flight Control Surfaces" file="TR12-118.pdf" refloc="AMM12-31-00-660-806">
* <folder type="history" title="History of AMM12-31-00-660-806">
* <doc title="TASK 12-31-00-660-806 - Inspection and Removal of De-Hydrated Anti-Icing Fluid inside the Flight Control Surfaces" file="AMM12-31-00-660-806.pdf" type="history" refloc="AMM12-31-00-660-806"/>
* </folder>
* the xpath string should be:
* folder[@key="LOETR"]/doc[@trnum="TR12-118"]/folder[@type="history"]/doc[@type="history"]
*
*
* the String : "fk:AMM24_fk:AMM24-FM_dk:CTOC-24"
* it represents the inner doc with attribute file="CTOC-24.pdf"
* the string : "fk:AMM24_fk:AMM24-00-00_fk:AMM24-00-00-02_dk:AMM24-00-00-700-801" represents
* <folder key="AMM24" title="CH 24 - Electrical Power">
* <folder key="AMM24-FM" title="Front Matter">
* <doc key="CTOC-24" title="Table of Contents" file="CTOC-24.pdf"/>
* </folder>
* <folder key="AMM24-00-00" title="24-00-00 - General">
* <folder key="AMM24-00-00-02" title="General - Maintenance Practices">
* <doc key="AMM24-00-00-700-801" title="TASK 24-00-00-700-801 - AC Power, DC Power and Battery Maintenance Practice Recommendations" file="AMM24-00-00-700-801.pdf"/>
*
* it can be even optimized as :
* "fk:AMM24_fk:00-00_fk:02_dk:AMM24-00-00-700-801"
* if the inner key fully include the previous key, omit it, otherwise use full string
* the xpath string should be:
* folder[@key="AMM24"]/folder[@key="AMM24-00-00"]/folder[@key="AMM24-00-00-02"]/doc[@key="AMM24-00-00-700-801"]
*
* if shortXPath is ?? which means the query based on the root of the document
*
*
*/
public String pathMapping(String shortXPath) throws Exception
{
String tagetString = null;
if (shortXPath.equals(""))
{
tagetString = "//toc";
}
else
{
tagetString = "//";
}
int newStart = 0;
String segString = "";
String valueString = "";
//dth???
//need mapping all senarios
//already??
while (shortXPath.indexOf("_", newStart) > -1)
{
int keyValueSepPos = 0;
String keyString = "";//not necessary key, might be type attribute
segString = shortXPath.substring(newStart, shortXPath.indexOf("_", newStart));
newStart = shortXPath.indexOf("_", newStart) + 1;//new start search point
//System.out.println(newStart);
if (segString.indexOf(":") > 0)
{
keyValueSepPos = segString.indexOf(":");
keyString = segString.substring(0, keyValueSepPos);
valueString = segString.substring(keyValueSepPos + 1);
if (pathMap.get(keyString).length() > 0)
{
tagetString = tagetString.concat(pathMap.get(keyString));
}
else
{
throw new Exception("no mapping found");
}
tagetString = tagetString.concat("='").concat(valueString).concat("']/");
}
}
//this is for scenerio either no "_" or sub string after "_"
segString = shortXPath.substring(newStart);
System.out.println(segString);
if (segString.indexOf(":") > 0)
{
int lastKeyValueSepPos = segString.indexOf(":");
String lastKeyString = segString.substring(0, lastKeyValueSepPos);
String lastValueString = segString.substring(lastKeyValueSepPos + 1);
if (pathMap.get(lastKeyString).length() > 0)
{
tagetString = tagetString.concat(pathMap.get(lastKeyString));
}
else
{
throw new Exception("no mapping found");
}
tagetString = tagetString.concat("='").concat(lastValueString).concat("']");
}
return tagetString;
}
public static void main(String[] args) throws Exception
{
XMLToJson x2j = new XMLToJson();
String test = "fk:AMM24_fk:AMM24-FM";
test = "";
System.out.println(x2j.getJson(new URL("http://localhost:8080/WebNavSpring/q400/amm/toc.xml"), test));
//System.out.println(x2j.pathMapping(test));
}
}
easy clean code to convert XML to JSON .
void destroy_phone(T9obj* ptr_T9Obj){
free(ptr_T9Obj);
}
Such thoughtful name!
sed -i 's/^#HTTPD=\/usr\/sbin\/httpd.worker/HTTPD=/\/usr\/sbin\/httpd.worker/g' /etc/sysconfig/httpd
precision mediump float;
uniform float time;
uniform vec2 resolution;
#define equals =
#define divided /
#define plus +
#define minus -
#define times *
#define by
#define point .
#define zero 0.
#define one 1.
#define five 5.
#define output gl_FragColor
#define then {
#define end }
#define less <
#define than
#define increment ++
#define afterwards ;
#define comma ,
#define semi .5
#define hundred 100.
void main ( void ) then
vec2 uv equals gl_FragCoord point xy divided by resolution point xy afterwards
float number equals sin( time plus uv point y ) afterwards
for ( float i equals zero afterwards i less than five afterwards increment i) then
number equals mod ( uv point x comma number ) afterwards
end
output equals vec4 (uv point x comma uv point y comma number times hundred comma one ) afterwards
end
if (preg_match("/^N/",$postcode)) {
if (preg_match("/^NW/", $postcode)) {
if (!preg_match("/^NW1/", $postcode)) {
// NORTH WEST (NW2, NW3, NW4, NW5, NW6, NW7, NW8, NW9, NW10)
$property['Prop_area'] = 'NW';
} else {
// NW1 which is Central
$property['Prop_area'] = 'SW';
}
} else {
// NORTH (N1, N2, N3, N4, N5 etc)
$property['Prop_area'] = 'N';
}
} else if (preg_match("/^W/",$postcode)) {
if (
!preg_match("/^W1 /",$postcode)
&& !preg_match("/^W2 /",$postcode)
&& !preg_match("/^W8/",$postcode)
&& !preg_match("/^W11/",$postcode)
) {
// WEST includes (W3, W4, W5, W6, W7, W9, W10, W12, W13, W14)
$property['Prop_area'] = 'W';
} else {
//W1 and W2, W8, W11 which are Central
$property['Prop_area'] = 'SW';
}
} else {
if (
preg_match("/^SW/",$postcode)
|| preg_match("/^EC/",$postcode)
|| preg_match("/^WC/",$postcode)
) {
// CENTRAL includes (W1, W2, EC, WC, NW1, SW1, SW3, SW5, SW7, W8, W11)
$property['Prop_area'] = 'SW';
} else {
// OTHER includes South and East and everything else
return 'SE';
}
}
int file_exist(){
FILE *file;
if((file = fopen(SCORE_FILE_NAME, "r"))){
fclose(file);
return 1;
}
return 0;
}
else if result !== true && result === false { return result !== true }
should I keep this in our project or nah
<div ng-repeat="recipient in $ctrl.resource.invoiceRecipients track by $index">
<div>
{{$ctrl.resource.invoiceRecipients[$index]}}
</div>
</div>
You could easily use the "recipient" variable instead of getting it again from the array, is there a reason for doing this?
#include <iostream>
#define OPEN_PARENTHESIS (
#define CLOSE_PARENTHESIS )
#define OPEN_BRACES {
#define CLOSE_BRACES }
#define INTEGER int
#define STANDARD_LIB std::
#define CONSOLE_OUT cout
#define ANGLE_BRACKETS <<
#define MESSAGE "Hello World\n"
#define SEMI ;
#define CLASS_NAME main
INTEGER CLASS_NAME OPEN_PARENTHESIS CLOSE_PARENTHESIS OPEN_BRACES
STANDARD_LIB CONSOLE_OUT ANGLE_BRACKETS MESSAGE SEMI
CLOSE_BRACES
Everything is defined
@SuppressWarnings("unchecked")
private void addEndpointsTags(JsonArray tagsArray) throws IOException {
if (registeredHandlers == null || registeredHandlers.isEmpty()) {
return;
}
TreeSet<String> handlerNamesSorted = new TreeSet<>(registeredHandlers.keySet());
handlerNamesSorted.forEach(key -> {
StringBuilder sb = new StringBuilder();
sb.append("{\"name\":\"");
sb.append(key);
sb.append("\",\"request\":{\"name\":\"");
try {
ServiceMethodHandler handler = registeredHandlers.get(key);
Class<? extends Message> requestClass = (Class<? extends Message>)
findSubClassParameterType(handler, 0);
Class<? extends Message> responseClass = (Class<? extends Message>)
findSubClassParameterType(handler, 1);
sb.append(requestClass.getSimpleName());
sb.append("\",\"type\":\"");
sb.append(requestClass.getSimpleName());
sb.append("\",\"values\":[");
sb.append(getProtobufClassFieldDescriptions(requestClass, new HashSet<>()));
sb.append("]},\"response\":{\"name\":\"");
sb.append(responseClass.getSimpleName());
sb.append("\",\"type\":\"");
sb.append(responseClass.getSimpleName());
sb.append("\",\"values\":[");
sb.append(getProtobufClassFieldDescriptions(responseClass, new HashSet<>()));
sb.append("]},\"metadata\":{\"stream\":\"false\"}}");
} catch (Exception e) {
logger.error("Error inspecting handlers", e);
return;
}
String tag = sb.toString();
tagsArray.add(new JsonPrimitive("e-" + binaryEncode(tag)));
});
}