Java Common methods

Source: Internet
Author: User

 /** * To get all directories that satisfy the conditions in this directory * @param lucenefilepathregular Regular directory, such as/user/solrindex/regular expression * @return A catalog collection that satisfies regular expressions List*/     Public StaticList<string>Fetchdirbyregularlinux (String lucenefilepathregular) {List<String> list=NewArraylist<>(); //Split get home directory        intlen= Lucenefilepathregular.lastindexof (etlconstants.linux_route_segment) +1; String Maindir=lucenefilepathregular.substring (0, Len); String Regular=lucenefilepathregular.substring (Len,lucenefilepathregular.length ()); File dir=NewFile (Maindir); if(Dir.exists () &&dir.isdirectory ()) {File [] arr=Dir.listfiles ();  for(File file:arr) {if(File.exists () &&file.isdirectory ()) {String FileName=File.getname (); if(Matchstr (FileName, Regular)) {List.add (File.getabsolutepath ()+Solrutil.index_dir_suffix); }                }            }        }        if(List.size () >0) {Logger.info ("The SOLR directories to which they are matched are:");  for(String s:list) {logger.info (s); }        }Else{logger.error ("Path {}, there is no directory that satisfies the regular: {} condition", dir, regular); }        returnlist; }

    /** * @Method Description: Matches the string by regular means * @param str * @param regular * @return*/     Public StaticBoolean matchstr (String str, string regular) {pattern pattern=Pattern.compile (Regular); Matcher Matcher=Pattern.matcher (str); returnmatcher.matches (); }    /** * Base exponent * @param base * @param exponent * @return*/     Public Static intPowint Base,intexponent) {        intresult=1;  for(intI=0; i<exponent;i++) {result=result*Base; }        returnresult; }

 Public StaticFinal map<string, long> date_map =NewHashmap<string, long>() {{put ("Month", +* -* -*24L); Put (" Day", +* -* -*24L); Put ("Hour", +* -*60L); }    };

/** * Convert string to specified number of digits size * insufficient, front supplemental Supplementvalue * exceeded, Iscutfront to true intercept front size bit * @param original * @p Aram Size * @param supplementvalue * @return*/     Public StaticString Supplementstringfront (string original,intsize,string Supplementvalue) {        returnCutstring (Original,size,true, Supplementvalue,true); }    /** * @param original * @param size * @param supplementvalue * @param front * @return*/    /** * Convert string to specified number of digits size * Insufficient, isfrontsupplement to true, front complement supplementvalue,isfrontsupplement false, back supplement Supplementvalu E * exceeds, Iscutfront is true to intercept the previous size bit, Iscutfront is false, intercept the size bit behind * @param original * @param size * @param ISFR Ontsupplement * @param supplementvalue * @param iscutfront * @return*/     Public StaticString Cutstring (string original,intSize,boolean isfrontsupplement,string Supplementvalue,boolean iscutfront) {        intLength=original.length (); String result=NULL; if(length==size) {Result=original; }Else if(length<size) {            if(isfrontsupplement) {result=supplementvalue+original;  while(Result.length () <size) {Result=supplementvalue+result; }            }Else{result=original+Supplementvalue;  while(Result.length () <size) {Result=result+Supplementvalue; }            }        }        //length>size        Else{            if(iscutfront) {result=original.substring (0, size); }Else{result=original.substring (Original.length ()-size,original.length ()); }        }        returnresult; }

Java Common methods

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.