int i=0;

                        for (i=0; i<msg.length;i++){

                            switch (i){

                                  case 0:

                                  case 1:

                                  case 2:

                                  case 3:

                                  case 4:

                                  case 5:

                                  case 6:

                                  case 7:

                                  case 8:

                                  case 9:

                                  case 10:

                                  case 11:

                                  case 18:

                                  case 19:

                                  case 26:

                                  case 27:

                                  case 34:

                                  case 35:

                                  case 42:

                                  case 43:

                                  case 50:

                                  case 51:

                                  case 52:

                                  case 53:

                                  case 54:

                                  case 55:

                                  case 58:

                                  case 59:

                                  case 62:

                                  case 63: log.debug("******** TRAZA-BEA: autenticacion ntlm. mensaje[" + i + "]: " + msg[i] + " SINSIGNO: " + (int)(msg[i] & 0x00ff) + "   " + new String(msg,i,1, "UTF-16LE")); break;

                                  case 12:

                                  case 14:

                                  case 16:

                                  case 20:

                                  case 22:

                                  case 24:

                                  case 28:

                                  case 30:

                                  case 32:

                                  case 36:

                                  case 38:

                                  case 40:

                                  case 44:

                                  case 46:

                                  case 48:

                                  case 56:

                                  case 60:log.debug("******** TRAZA-BEA: autenticacion ntlm. mensaje[" + i + "]: " + msg[i] + " SINSIGNO: " + (int)(msg[i] & 0x00ff) + "   " + new String(msg,i,2, "UTF-16LE")); break;

                                  case 13:

                                  case 15:

                                  case 17:

                                  case 21:

                                  case 23:

                                  case 25:

                                  case 29:

                                  case 31:

                                  case 33:

                                  case 37:

                                  case 39:

                                  case 41:

                                  case 45:

                                  case 47:

                                  case 49:

                                  case 57:

Why not case 60? LOL

By Pabs, 2017-12-26 14:03:33
	public static int findSplitVariable(LinkedList<ByteDataRow> matrix) {
		LinkedList<ByteDataRow> list = new LinkedList<ByteDataRow>();
		int maxNoOfZeros = 0;
		int maxNoOfOnes = 0;
		int varId = -1;
		int[] NoOfOnesInColumn = new int[matrix.get(0).getInVars().length];


		for (ByteDataRow bdr : matrix) {
			int tmpNoOfZeros = bdr.getNumberOfZeros();
			if (maxNoOfZeros < tmpNoOfZeros) {
				list.clear();
				list.add(bdr.clone());
				maxNoOfZeros = tmpNoOfZeros;
			} else if (maxNoOfZeros == tmpNoOfZeros) {
				list.add(bdr.clone());
			}
		}

		for (ByteDataRow bdr : list) {
			byte[] vars = bdr.getInVars();
			for (int i = 0; i < vars.length; i++) {
				NoOfOnesInColumn[i] = NoOfOnesInColumn[i]
						+ Byte.compare(vars[i], Byte.parseByte("0"));
				if (NoOfOnesInColumn[i] > maxNoOfOnes) {
					maxNoOfOnes = NoOfOnesInColumn[i];
					varId = i;
				}
			}
		}

		return varId;
	}

	public static int findSplitVariable(LinkedList<ByteDataRow> matrix, int varIdx) {
		LinkedList<ByteDataRow> list = new LinkedList<ByteDataRow>();
		int maxNoOfZeros = 0;
		int maxNoOfOnes = 0;
		int varId = -1;
		int[] NoOfOnesInColumn = new int[matrix.get(0).getInVars().length];

		// Wybierz kostkÍ z najwiÍkszπ liczbπ zer.
		for (ByteDataRow bdr : matrix) {
			int tmpNoOfZeros = bdr.getNumberOfZeros();
			if (maxNoOfZeros < tmpNoOfZeros) {
				list.clear();
				list.add(bdr.clone());
				maxNoOfZeros = tmpNoOfZeros;
			} else if (maxNoOfZeros == tmpNoOfZeros) {
				list.add(bdr.clone());
			}
		}

		for (ByteDataRow bdr : list) {
			byte[] vars = bdr.getInVars();
			for (int i = 0; i < vars.length; i++) {
				NoOfOnesInColumn[i] = NoOfOnesInColumn[i]
						+ Byte.compare(vars[i], Byte.parseByte("0"));
				if (NoOfOnesInColumn[i] > maxNoOfOnes) {
					maxNoOfOnes = NoOfOnesInColumn[i];
					varId = i;
				}
			}
		}

		return varId;
	}

There are two methods findSplitVariable. Second one takes extra parameter (varIdx) that is not used anywhere.

By Paul, 2018-02-17 14:47:37
if(computedDate != null){
    myObject.setDueDate(computedDate);
}
else{
    myObject.setDueDate(null);
}
By Anonymous, 2018-02-22 04:46:08
#266 Java -29
        //JSONObject input;
        
        String givenName = input.get("propName") != null ? (String)input.get("propName") : null;

WHAT DA FUCK ASSHOLES

By Anonymous, 2018-03-15 15:28:55
 private void EnableGPSAutoMatically() {
        GoogleApiClient googleApiClient = null;
        if (googleApiClient == null) {
            oogleApiClient = new GoogleApiClient.Builder(this)
                    .addApi(LocationServices.API).addConnectionCallbacks(this)
                    .addOnConnectionFailedListener(this).build();
            /* about 50 lines of code were here ... 
             * all depends on this if statement ... !
             * Actually the whole method depends on this if statement ! */
                    }
                }
            });
        }
}

what if that mysterious power change it to be not null !! It gonna be a holly object and You should not "new" it anymore ?! damn ... :)))

By Anonymous, 2018-03-28 11:31:15
public class MandateData {

    public final UUID coreId;
    public final UUID accountId;
    public final String accountRef;
    public final String creditorId;
    public final String creditorName;
    public final String debtorFirstName;
    public final String debtorLastName;
    public final String branchCode;
    public final String accountNumber;
    public final LocalDate signingDate;
    public final Address debtorAddress;

    private MandateData(UUID coreId, UUID accountId, String accountRef, String creditorId, String creditorName, String branchCode, String accountNumber, String debtorFirstName, String debtorLastName,
                        LocalDate signingDate, Address debtorAddress) {
        this.coreId = coreId;
        this.accountId = accountId;
        this.accountRef = accountRef;
        this.creditorId = creditorId;
        this.creditorName = creditorName;
        this.debtorFirstName = debtorFirstName;
        this.debtorLastName = debtorLastName;
        this.branchCode = branchCode;
        this.accountNumber = accountNumber;
        this.signingDate = signingDate;
        this.debtorAddress = debtorAddress;
    }

    public static MandateData creationMandateData(UUID coreId, UUID accountId, String accountRef, String creditorId, String creditorName, String branchCode, String accountNumber, String debtorFirstName, String debtorLastName,
                                                  LocalDate signingDate, Address debtorAddress) {
        return new MandateData(coreId, accountId, accountRef, creditorId, creditorName, branchCode, accountNumber, debtorFirstName, debtorLastName, signingDate, debtorAddress);
    }
}

There is an ancient and mysterious legend about public static constructor, called createShit. If anyone want's just to create an instance of Shit be aware of it! This is too obvious! just Implement static method with the exactly the same fields, and make constructor private. Don't write a shit!

By Anonymous, 2018-06-07 13:03:44
switch (kafkaStreams.state()) {
                case RUNNING: {
                    if (kafkaStreams.state().isRunning()) {
                        countDownLatch.countDown();
                    }
                }
                break;
By Anonymous, 2018-07-05 18:05:59

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (android.os.Build.VERSION.SDK_INT > 9) {
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);
        }

        fileObjectDAO = new FileObjectDAO(this);
        iv = (ImageView)findViewById(R.id.imageView);
        tv = (TextView)findViewById(R.id.textView);
        centerImageView = (ImageButton)findViewById(R.id.imageButton);
        leftText = (TextView)findViewById(R.id.textView2);
        rightText = (TextView)findViewById(R.id.textView3);
        leftArrow = (TextView)findViewById(R.id.textView4);
        rightArrow =  (TextView)findViewById(R.id.textView9);
        leftCancel = (ImageButton)findViewById(R.id.imageButton2);
        displayWelcome1  = (TextView)findViewById(R.id.textView5);
        displayWelcome2  = (TextView)findViewById(R.id.textView6);
        rightCancel = (ImageButton)findViewById(R.id.imageButton3);

        seatButton = (ImageButton)findViewById(R.id.imageButton4);
        waitButton = (ImageButton)findViewById(R.id.imageButton5);
        clearButton = (ImageButton)findViewById(R.id.imageButton6);
        enityButton = (ImageButton)findViewById(R.id.imageButton7);
        bookButton = (ImageButton)findViewById(R.id.imageButton8);
        settingButton = (ImageButton)findViewById(R.id.imageButton9);

        displatSeat = (TextView)findViewById(R.id.textView7);
        displatSeatNumber = (TextView)findViewById(R.id.textView8);
        isClearing = false;
        hidenAll();
        key1 = 0;
        key2 = 0;
        key3 = 0;

        isError = false;
        isWaiting = false;

        myTTS = new TapiaTTS(this);
        myhandler = new Tapiahandler();
        mySTT = new TapiaSTT(this,myhandler,false);
        isResume = false;
        tapiaAnimation = new TapiaAnimation(this);

        liveData.add("愛媛");
        liveData.add("松山");
        liveData.add("今治");
        liveData.add("高知");
        liveData.add("福岡");
        liveData.add("北九州");
        liveData.add("佐賀");
        liveData.add("長崎");
        liveData.add("熊本");
        liveData.add("大分");
        liveData.add("別府");
        liveData.add("宮崎");
        liveData.add("高千穂");
        liveData.add("鹿児島");
        liveData.add("奄美大島");
        liveData.add("屋久島");
        liveData.add("沖縄");
        liveData.add("那覇");
        liveData.add("北海道");
        liveData.add("札幌");
        liveData.add("函館");
        liveData.add("室蘭");
        liveData.add("浦河");
        liveData.add("旭川");
        liveData.add("留萌");
        liveData.add("稚内");
        liveData.add("網走");
        liveData.add("帯広");
        liveData.add("登別");
        liveData.add("知床");
        liveData.add("釧路");
        liveData.add("根室");
        liveData.add("青森");
        liveData.add("岩手");
        liveData.add("盛岡");
        liveData.add("秋田");
        liveData.add("宮城");
        liveData.add("仙台");
        liveData.add("松島");
        liveData.add("泉");
        liveData.add("登米");
        liveData.add("佐沼");
        liveData.add("山形");
        liveData.add("福島");
        liveData.add("郡山");
        liveData.add("茨城");
        liveData.add("水戸");
        liveData.add("栃木");
        liveData.add("日光");
        liveData.add("宇都宮");
        liveData.add("群馬");
        liveData.add("前橋");
        liveData.add("高崎");
        liveData.add("埼玉");
        liveData.add("千葉");
        liveData.add("成田");
        liveData.add("木更津");
        liveData.add("船橋");
        liveData.add("松戸");
        liveData.add("東京");
        liveData.add("銀座");
        liveData.add("浅草");
        liveData.add("池袋");
        liveData.add("上野");
        liveData.add("新宿");
        liveData.add("渋谷");
        liveData.add("品川");
        liveData.add("巣鴨");
        liveData.add("八王子");
        liveData.add("神奈川");
        liveData.add("横浜");
        liveData.add("川崎");
        liveData.add("横須賀");
        liveData.add("相模原");
        liveData.add("山梨");
        liveData.add("甲府");
        liveData.add("新潟");
        liveData.add("佐渡");
        liveData.add("富山");
        liveData.add("石川");
        liveData.add("金沢");
        liveData.add("福井");
        liveData.add("長野");
        liveData.add("軽井沢");
        liveData.add("松本");
        liveData.add("岐阜");
        liveData.add("飛騨高山");
        liveData.add("静岡");
        liveData.add("富士");
        liveData.add("浜松");
        liveData.add("愛知");
        liveData.add("名古屋");
        liveData.add("三重");
        liveData.add("伊勢");
        liveData.add("津");
        liveData.add("滋賀");
        liveData.add("大津");
        liveData.add("京都");
        liveData.add("大阪");
        liveData.add("堺");
        liveData.add("東大阪");
        liveData.add("兵庫");
        liveData.add("神戸");
        liveData.add("姫路");
        liveData.add("奈良");
        liveData.add("和歌山");
        liveData.add("鳥取");
        liveData.add("島根");
        liveData.add("出雲");
        liveData.add("松江");
        liveData.add("岡山");
        liveData.add("広島");
        liveData.add("福山");
        liveData.add("山口");
        liveData.add("下関");
        liveData.add("徳島");
        liveData.add("香川");
        liveData.add("高松");
        try {
            SN = getSerialNumber();
        }catch (Exception e){
            SN = "mji123456";
        }
//
        Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
            @Override
            public void uncaughtException(Thread paramThread, Throwable paramThrowable) {
                myHandaling(paramThread, paramThrowable);
            }
        });
        
        
        connectFtp();

        tapiaGet = new TapiaGetJson();
        setWalkpaper();

//        longPressRunnable = new Runnable() {
//            public void run() {
//                if(currentMode.equalsIgnoreCase("talk")){
//                    myTTS.stopSpeak();
//                    mySTT.stop();
//                    checkHandler98_BLUE.removeCallbacks(checkRunnable98_BLUE);
//                    isListen = false;
//                    tapiaAnimation.playColor1(1);
//                    String [] SpeakArray = {"またあとでね", "またね", "あとでね", "ちょっとひとやすみ", "休憩するね"};
//                    Random ran = new Random();
//                    int index = ran.nextInt(SpeakArray.length);
//                    String toSpeak = SpeakArray[index];
//                    //Toast.makeText(getApplicationContext(), toSpeak,Toast.LENGTH_SHORT).show();
//                    myTTS.TapiaSpeak(toSpeak);
//                    //iv.setImageResource(R.drawable.black);
//                    myTTS.player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
//
//                        @Override
//                        public void onCompletion(MediaPlayer mp) {
////                                Intent intent = new Intent(context, StartActivity.class);
////                                startActivity(intent);
//                            count98 =0;
//                            checkStateHander.postDelayed(checkStateRunnable,5000);
//                            handler98.postDelayed(runnable98,800);
//                            setSleepMode();
//                        }
//
//                    });
//                }else if(currentMode.equalsIgnoreCase("sleep")){
//                    setTalkingMode();
//                    checkStateHander.removeCallbacks(checkStateRunnable);
//                    handler98.removeCallbacks(runnable98);
//                    needForHelp("なにかご用ですか?");
//                }
//            }
//        };
//

        createDirIfNotExists("/sdcard/TapiaData/Send/");
        createDirIfNotExists("/sdcard/TapiaData/Receive/");
 public void run() {

                Log.d("Tapia","Check 98");

                if(count98==0){


                    boolean check = false;
                    boolean check2 = false;
                    String path = "/Tapia/"+seatNumber+"/";
                    allFileName = ftpPrintFilesList(path);
                    if(allFileName.size()==0){


                    }else{
                        for(String filename :allFileName){

                            if(filename.endsWith("98.trg")){

                                if(!fileObjectDAO.checkFileExit(filename)){
                                    fileObjectDAO.addFile(filename);
                                    isDelete = true;
                                    check = true;
                                    Log.e("checking","98");
                                    ftpDownload(path + filename, "/sdcard/TapiaData/Receive/" + filename);
                                    break;
                                }
                            }
                        }

                    }

                    if(!check){
                        path = "/Tapia/ALL/";
                        allFileName = ftpPrintFilesList(path);
                        if(allFileName.size()==0){


                        }else{
                            for(String filename :allFileName){

                                if(filename.endsWith("98.trg")){

                                    if(!fileObjectDAO.checkFileExit(filename)){
                                        fileObjectDAO.addFile(filename);
                                        isDelete = true;
                                        check2 = true;
                                        ftpDownload(path+filename,"/sdcard/TapiaData/Receive/"+filename);
                                        break;
                                    }
                                }
                            }

                        }


                    }
                        count98++;
                        handler98.postDelayed(this, 1000);

                }else{
                    count98++;
                    if(count98==10)count98=0;
                    handler98.postDelayed(this, 1000);
                }

            }
        };


Trust me it works!!!

PS. This is 300 out of 3000 lines from one Class

By SIMON WONG , 2018-08-20 10:19:44
        if (!rtrId.isPresent()) {
            ...
        } else if (identityId.isPresent() && rtrId.isPresent()) {
            ...
        }
        

A treasured knife protects

By Dunia, 2018-09-18 10:34:19
Boolean b = new Boolean(true);
if (b == true){
    ...
}

think outside the autoboxing

By ktb, 2018-09-18 15:17:38
public void sleep(long duration) {
    long start = System.currentTimeMillis();
    while(true) {
        if (System.currentTimeMillis() - start >= duration)
            break;
    }
}
By imaN NeO, 2018-10-28 09:35:15
if (responseCode / 100 == 2) {//success
    return handleSuccess();
} else if (responseCode == 401) {
    return handleNotAuthorized();
} else {
    // something else
} 
By Anonymous, 2019-01-29 09:41:13

/**
 * 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 .

By used in Major Airspace company , 2019-03-15 17:59:54
try {
    channel.send(eventMessage);
} catch (MessageHandlingException ex) {
    channel.send(eventMessage);
}
By Anonymous, 2019-03-29 08:53:50
    @Override
    public String toString() {
        List<Integer> accountLevels = new ArrayList<>();
        List<String> accountIds = new ArrayList<>();

        for (SelectedHierarchyLevel selectedHierarchyLevel : selectedHierarchyLevels) {
            accountLevels.add(selectedHierarchyLevel.getLevel());
            accountIds.add(selectedHierarchyLevel.getAccountRowId());
        }

        vetoAreValidIds(accountIds);
        StringBuilder converterString = new StringBuilder();

        convert(accountLevels, converterString);
        converterString.append("$");
        convert(accountIds, converterString);

        return converterString.toString();
    }

Just because you can, doesn’t mean you should.

By Anonymous, 2019-04-12 10:55:17