idx
int64
0
41.2k
question
stringlengths
73
5.81k
target
stringlengths
5
918
29,300
public Post param ( String name , String value ) { params . put ( name , value ) ; return this ; }
Adds a parameter to the request as in a HTML form .
29,301
public < T extends Model > LazyList < T > where ( String subquery , Object ... params ) { StringBuilder query ; if ( subquery . equals ( "*" ) ) { query = new StringBuilder ( ) ; } else { query = new StringBuilder ( subquery ) ; query . append ( " AND " ) ; } for ( int i = 0 ; i < scopes . size ( ) ; i ++ ) { String sc...
Applies additional criteria to scopes defined in the model .
29,302
private Set < String > getEnvironments ( Properties props ) { Set < String > environments = new HashSet < > ( ) ; for ( Object k : props . keySet ( ) ) { String environment = k . toString ( ) . split ( "\\." ) [ 0 ] ; environments . add ( environment ) ; } return new TreeSet < > ( environments ) ; }
get environments defined in properties
29,303
private Properties readPropertyFile ( String file ) throws IOException { String fileName = file . startsWith ( "/" ) ? file : "/" + file ; LOGGER . info ( "Reading properties from: " + fileName + ". Will try classpath, then file system." ) ; return Util . readProperties ( fileName ) ; }
read from classpath if not found read from file system . If not found there throw exception
29,304
public static String driverClass ( String url ) { assert ! blank ( url ) ; if ( url . contains ( POSTGRESQL_FRAGMENT ) ) { return "org.postgresql.Driver" ; } if ( url . contains ( MYSQL_FRAGMENT ) ) { return "com.mysql.jdbc.Driver" ; } if ( url . contains ( HSQL_FRAGMENT ) ) { return "org.hsqldb.jdbcDriver" ; } if ( ur...
Given a jdbc url this tries to determine the target database and returns the driver class name as a string .
29,305
void convertWith ( Converter converter , String ... attributes ) { for ( String attribute : attributes ) { convertWith ( converter , attribute ) ; } }
Registers converter for specified model attributes .
29,306
void convertWith ( Converter converter , String attribute ) { List < Converter > list = attributeConverters . get ( attribute ) ; if ( list == null ) { list = new ArrayList < > ( ) ; attributeConverters . put ( attribute , list ) ; } list . add ( converter ) ; }
Registers converter for specified model attribute .
29,307
< S , T > Converter < S , T > converterForClass ( String attribute , Class < S > sourceClass , Class < T > destinationClass ) { List < Converter > list = attributeConverters . get ( attribute ) ; if ( list != null ) { for ( Converter converter : list ) { if ( converter . canConvert ( sourceClass , destinationClass ) ) ...
Returns converter for specified model attribute able to convert from sourceClass to destinationClass . Returns null if no suitable converter was found .
29,308
< T > Converter < Object , T > converterForValue ( String attribute , Object value , Class < T > destinationClass ) { return converterForClass ( attribute , value != null ? ( Class < Object > ) value . getClass ( ) : Object . class , destinationClass ) ; }
Returns converter for specified model attribute able to convert value to an instance of destinationClass . Returns null if no suitable converter was found .
29,309
public Object overrideDriverTypeConversion ( MetaModel mm , String attributeName , Object value ) { if ( value instanceof String && ! Util . blank ( value ) ) { String typeName = mm . getColumnMetadata ( ) . get ( attributeName ) . getTypeName ( ) ; if ( "date" . equalsIgnoreCase ( typeName ) ) { return java . sql . Da...
TDS converts a number of important data types to String . This isn t what we want nor helpful . Here we change them back .
29,310
public static Map toMap ( String json ) { try { return mapper . readValue ( json , Map . class ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } }
Convert a JSON map to a Java Map
29,311
public static String toJsonString ( Object val , boolean pretty ) { try { return pretty ? mapper . writerWithDefaultPrettyPrinter ( ) . with ( SerializationFeature . ORDER_MAP_ENTRIES_BY_KEYS ) . writeValueAsString ( val ) : mapper . writeValueAsString ( val ) ; } catch ( Exception e ) { throw new RuntimeException ( e ...
Convert Java object to a JSON string .
29,312
public static String toJsonObject ( Object ... namesAndValues ) { if ( namesAndValues . length % 2 != 0 ) { throw new IllegalArgumentException ( "number or arguments must be even" ) ; } StringBuilder sb = new StringBuilder ( "{" ) ; int count = 0 ; while ( true ) { Object name = namesAndValues [ count ] ; sb . append (...
Converts input into a JSON object .
29,313
public static List toList ( String json ) { try { return mapper . readValue ( json , List . class ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } }
Convert JSON array tp Java List
29,314
public static String sanitize ( String value , boolean clean , Character ... toEscape ) { StringBuilder builder = new StringBuilder ( ) ; Map < Character , String > replacements = clean ? CLEAN_CHARS : REPLACEMENT_CHARS ; for ( int i = 0 ; i < value . length ( ) ; i ++ ) { char c = value . charAt ( i ) ; if ( toEscape ...
Escapes control characters in a string when you need to generate JSON .
29,315
public static Boolean toBoolean ( Object value ) { if ( value == null ) { return false ; } else if ( value instanceof Boolean ) { return ( Boolean ) value ; } else if ( value instanceof BigDecimal ) { return value . equals ( BigDecimal . ONE ) ; } else if ( value instanceof Number ) { return ( ( Number ) value ) . intV...
Returns true if the value is any numeric type and has a value of 1 or if string type has a value of 1 t y true or yes . Otherwise return false .
29,316
public static Float toFloat ( Object value ) { if ( value == null ) { return null ; } else if ( value instanceof Float ) { return ( Float ) value ; } else if ( value instanceof Number ) { return ( ( Number ) value ) . floatValue ( ) ; } else { return Float . valueOf ( value . toString ( ) . trim ( ) ) ; } }
Converts value to Float if it can . If value is a Float it is returned if it is a Number it is promoted to Float and then returned in all other cases it converts the value to String then tries to parse Float from it .
29,317
public static Integer toInteger ( Object value ) { if ( value == null ) { return null ; } else if ( value instanceof Integer ) { return ( Integer ) value ; } else if ( value instanceof Number ) { return ( ( Number ) value ) . intValue ( ) ; } else { try { return Integer . valueOf ( value . toString ( ) . trim ( ) ) ; }...
Converts value to Integer if it can . If value is a Integer it is returned if it is a Number it is promoted to Integer and then returned in all other cases it converts the value to String then tries to parse Integer from it .
29,318
public static BigDecimal toBigDecimal ( Object value ) { if ( value == null ) { return null ; } else if ( value instanceof BigDecimal ) { return ( BigDecimal ) value ; } else { try { return new BigDecimal ( value . toString ( ) . trim ( ) ) ; } catch ( NumberFormatException e ) { throw new ConversionException ( "failed...
Converts value to BigDecimal if it can . If value is a BigDecimal it is returned if it is a BigDecimal it is promoted to BigDecimal and then returned in all other cases it converts the value to String then tries to parse BigDecimal from it .
29,319
private void doUnescape ( StringBuilder sb , String str , int firstAmp ) { sb . append ( str , 0 , firstAmp ) ; int len = str . length ( ) ; for ( int i = firstAmp ; i < len ; i ++ ) { char c = str . charAt ( i ) ; if ( c == '&' ) { int nextIdx = i + 1 ; int semiColonIdx = str . indexOf ( ';' , nextIdx ) ; if ( semiCol...
Underlying unescape method that allows the optimisation of not starting from the 0 index again .
29,320
public static byte [ ] readResourceBytes ( String resourceName ) { InputStream is = Util . class . getResourceAsStream ( resourceName ) ; try { return bytes ( is ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } finally { closeQuietly ( is ) ; } }
Reads contents of resource fully into a byte array .
29,321
public static String readResource ( String resourceName , String charset ) { InputStream is = Util . class . getResourceAsStream ( resourceName ) ; try { return read ( is , charset ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } finally { closeQuietly ( is ) ; } }
Reads contents of resource fully into a string .
29,322
public static String readFile ( String fileName , String charset ) { FileInputStream in = null ; try { in = new FileInputStream ( fileName ) ; return read ( in , charset ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } finally { closeQuietly ( in ) ; } }
Reads contents of file fully and returns as string .
29,323
public static String read ( InputStream in , String charset ) throws IOException { if ( in == null ) { throw new IllegalArgumentException ( "input stream cannot be null" ) ; } InputStreamReader reader = null ; try { reader = new InputStreamReader ( in , charset ) ; char [ ] buffer = new char [ 1024 ] ; StringBuilder sb...
Reads contents of the input stream fully and returns it as String .
29,324
public static byte [ ] read ( File file ) throws IOException { FileInputStream is = new FileInputStream ( file ) ; try { return bytes ( is ) ; } finally { closeQuietly ( is ) ; } }
Reads file into a byte array .
29,325
public static List < String > getResourceLines ( String resourceName ) throws IOException { InputStreamReader isreader = null ; BufferedReader reader = null ; try { isreader = new InputStreamReader ( Util . class . getResourceAsStream ( resourceName ) ) ; reader = new BufferedReader ( isreader ) ; List < String > lines...
Returns lines of text of a resource as list .
29,326
public static String join ( String [ ] array , String delimiter ) { if ( empty ( array ) ) { return "" ; } StringBuilder sb = new StringBuilder ( ) ; join ( sb , array , delimiter ) ; return sb . toString ( ) ; }
Joins the items in array with a delimiter .
29,327
public static void join ( StringBuilder sb , Collection < ? > collection , String delimiter ) { if ( collection . isEmpty ( ) ) { return ; } Iterator < ? > it = collection . iterator ( ) ; sb . append ( it . next ( ) ) ; while ( it . hasNext ( ) ) { sb . append ( delimiter ) ; sb . append ( it . next ( ) ) ; } }
Joins the items in collection with a delimiter and appends the result to StringBuilder .
29,328
public static void join ( StringBuilder sb , Object [ ] array , String delimiter ) { if ( empty ( array ) ) { return ; } sb . append ( array [ 0 ] ) ; for ( int i = 1 ; i < array . length ; i ++ ) { sb . append ( delimiter ) ; sb . append ( array [ i ] ) ; } }
Joins the items in array with a delimiter and appends the result to StringBuilder .
29,329
public static void repeat ( StringBuilder sb , String str , int count ) { for ( int i = 0 ; i < count ; i ++ ) { sb . append ( str ) ; } }
Repeats string of characters a defined number of times and appends result to StringBuilder .
29,330
public static void joinAndRepeat ( StringBuilder sb , String str , String delimiter , int count ) { if ( count > 0 ) { sb . append ( str ) ; for ( int i = 1 ; i < count ; i ++ ) { sb . append ( delimiter ) ; sb . append ( str ) ; } } }
Repeats string of characters a defined number of times with a delimiter and appends result to StringBuilder .
29,331
public static String getStackTraceString ( Throwable throwable ) { StringWriter sw = null ; PrintWriter pw = null ; try { sw = new StringWriter ( ) ; pw = new PrintWriter ( sw ) ; pw . println ( throwable . toString ( ) ) ; throwable . printStackTrace ( pw ) ; pw . flush ( ) ; return sw . toString ( ) ; } finally { clo...
Converts stack trace to string .
29,332
public static void saveTo ( String path , byte [ ] content ) { InputStream is = null ; try { is = new ByteArrayInputStream ( content ) ; saveTo ( path , is ) ; } finally { closeQuietly ( is ) ; } }
Saves content of byte array to file .
29,333
public static void recursiveDelete ( Path directory ) throws IOException { try { Files . walkFileTree ( directory , new SimpleFileVisitor < Path > ( ) { public FileVisitResult visitFile ( Path file , BasicFileAttributes attrs ) throws java . io . IOException { try { Files . delete ( file ) ; } catch ( NoSuchFileExcepti...
Deletes a directory recursively with all its contents . Will ignore files and directories if they are disappear during the oprtation .
29,334
protected List < String > getEdges ( String join ) { List < String > results = new ArrayList < > ( ) ; for ( Many2ManyAssociation a : many2ManyAssociations ) { if ( a . getJoin ( ) . equalsIgnoreCase ( join ) ) { results . add ( getMetaModel ( a . getSourceClass ( ) ) . getTableName ( ) ) ; results . add ( getMetaModel...
An edge is a table in a many to many relationship that is not a join .
29,335
public List < Migration > getPendingMigrations ( ) { List < String > appliedMigrations = getAppliedMigrationVersions ( ) ; List < Migration > allMigrations = migrationResolver . resolve ( ) ; List < Migration > pendingMigrations = new ArrayList < Migration > ( ) ; for ( Migration migration : allMigrations ) { if ( ! ap...
Returns pending migrations .
29,336
public void migrate ( Log log , String encoding ) { createSchemaVersionTable ( ) ; final Collection < Migration > pendingMigrations = getPendingMigrations ( ) ; if ( pendingMigrations . isEmpty ( ) ) { log . info ( "No new migrations are found" ) ; return ; } log . info ( "Migrating database, applying " + pendingMigrat...
Migrates the database to the latest version enabling migrations if necessary .
29,337
public static void html ( StringBuilder sb , String html ) { for ( int i = 0 ; i < html . length ( ) ; i ++ ) { char c = html . charAt ( i ) ; switch ( c ) { case '&' : sb . append ( "&amp;" ) ; break ; case '"' : sb . append ( "&quot;" ) ; break ; case '\'' : sb . append ( "&apos;" ) ; break ; case '<' : sb . append (...
Escapes HTML appending to StringBuilder .
29,338
public static String html ( String html ) { StringBuilder sb = createStringBuilder ( html . length ( ) ) ; html ( sb , html ) ; return sb . toString ( ) ; }
Escapes HTML .
29,339
public static String gsub ( String word , String rule , String replacement ) { Pattern pattern = Pattern . compile ( rule , Pattern . CASE_INSENSITIVE ) ; Matcher matcher = pattern . matcher ( word ) ; return matcher . find ( ) ? matcher . replaceFirst ( replacement ) : null ; }
Replaces a found pattern in a word and returns a transformed word .
29,340
public void setCurrentPageIndex ( int currentPageIndex , boolean skipCheck ) { if ( currentPageIndex < 1 ) { throw new IndexOutOfBoundsException ( "currentPageIndex cannot be < 1" ) ; } if ( ! skipCheck ) { if ( currentPageIndex > pageCount ( ) ) { throw new IndexOutOfBoundsException ( "currentPageIndex it outside of r...
Sets an index of a current page . This method will make a quick count query to check that the index you are setting is within the boundaries .
29,341
private void addCP ( ) throws DependencyResolutionRequiredException , MalformedURLException , InvocationTargetException , NoSuchMethodException , IllegalAccessException { List runtimeClasspathElements = project . getRuntimeClasspathElements ( ) ; for ( Object runtimeClasspathElement : runtimeClasspathElements ) { Strin...
man what a hack!
29,342
private boolean assertValidParams ( ) { return username != null && ! this . username . isEmpty ( ) && password != null && ! this . password . isEmpty ( ) && sqlString != null && ! this . sqlString . isEmpty ( ) && ( ( database != null && ! this . database . isEmpty ( ) ) || ( jdbcConnString != null && ! jdbcConnString ...
This function will check that required parameters are set
29,343
static Connection connectWithURL ( String username , String password , String jdbcURL , String driverName ) throws ClassNotFoundException , SQLException { String driver = ( Objects . isNull ( driverName ) || driverName . isEmpty ( ) ) ? "com.mysql.cj.jdbc.Driver" : driverName ; return doConnect ( driver , jdbcURL , use...
This is a utility function that allows connecting to a database instance identified by the provided jdbcURL The connector driver name can be empty
29,344
private static Connection doConnect ( String driver , String url , String username , String password ) throws SQLException , ClassNotFoundException { Class . forName ( driver ) ; Connection connection = DriverManager . getConnection ( url , username , password ) ; logger . debug ( "DB Connected Successfully" ) ; return...
This will attempt to connect to a database using the provided parameters . On success it ll return the java . sql . Connection object
29,345
static List < String > getAllTables ( String database , Statement stmt ) throws SQLException { List < String > table = new ArrayList < > ( ) ; ResultSet rs ; rs = stmt . executeQuery ( "SHOW TABLE STATUS FROM `" + database + "`;" ) ; while ( rs . next ( ) ) { table . add ( rs . getString ( "Name" ) ) ; } return table ;...
This is a utility function to get the names of all the tables that re in the database supplied
29,346
static String getEmptyTableSQL ( String database , String table ) { String safeDeleteSQL = "SELECT IF( \n" + "(SELECT COUNT(1) as table_exists FROM information_schema.tables \n" + "WHERE table_schema='" + database + "' AND table_name='" + table + "') > 1, \n" + "'DELETE FROM " + table + "', \n" + "'SELECT 1') INTO @Del...
This function is an helper function that ll generate a DELETE FROM database . table SQL to clear existing table
29,347
private boolean isValidateProperties ( ) { return properties != null && properties . containsKey ( DB_USERNAME ) && properties . containsKey ( DB_PASSWORD ) && ( properties . containsKey ( DB_NAME ) || properties . containsKey ( JDBC_CONNECTION_STRING ) ) ; }
This function will check if the required minimum properties are set for database connection and exporting
29,348
private boolean isEmailPropertiesSet ( ) { return properties != null && properties . containsKey ( EMAIL_HOST ) && properties . containsKey ( EMAIL_PORT ) && properties . containsKey ( EMAIL_USERNAME ) && properties . containsKey ( EMAIL_PASSWORD ) && properties . containsKey ( EMAIL_FROM ) && properties . containsKey ...
This function will check if all the minimum required email properties are set that can facilitate sending of exported sql to email
29,349
private String getTableInsertStatement ( String table ) throws SQLException { StringBuilder sql = new StringBuilder ( ) ; ResultSet rs ; boolean addIfNotExists = Boolean . parseBoolean ( properties . containsKey ( ADD_IF_NOT_EXISTS ) ? properties . getProperty ( ADD_IF_NOT_EXISTS , "true" ) : "true" ) ; if ( table != n...
This will generate the SQL statement for creating the table supplied in the method signature
29,350
public void clearTempFiles ( boolean preserveZipFile ) { File sqlFile = new File ( dirName + "/sql/" + sqlFileName ) ; if ( sqlFile . exists ( ) ) { boolean res = sqlFile . delete ( ) ; logger . debug ( LOG_PREFIX + ": " + sqlFile . getAbsolutePath ( ) + " deleted successfully? " + ( res ? " TRUE " : " FALSE " ) ) ; } ...
This function will delete all the temp files generated ny the library unless it s otherwise instructed not to do so by the preserveZipFile variable
29,351
public String getSqlFilename ( ) { return isSqlFileNamePropertySet ( ) ? properties . getProperty ( SQL_FILE_NAME ) + ".sql" : new SimpleDateFormat ( "d_M_Y_H_mm_ss" ) . format ( new Date ( ) ) + "_" + database + "_database_dump.sql" ; }
This will get the final output sql file name .
29,352
private boolean isPropertiesSet ( ) { return ! this . host . isEmpty ( ) && this . port > 0 && ! this . username . isEmpty ( ) && ! this . password . isEmpty ( ) && ! this . toAdd . isEmpty ( ) && ! this . fromAdd . isEmpty ( ) && ! this . subject . isEmpty ( ) && ! this . msg . isEmpty ( ) && this . attachments != nul...
This will check if the necessary properties are set for sending an email successfully
29,353
boolean sendMail ( ) { if ( ! this . isPropertiesSet ( ) ) { logger . debug ( LOG_PREFIX + ": Required Mail Properties are not set. Attachments will not be sent" ) ; return false ; } Properties prop = new Properties ( ) ; prop . put ( "mail.smtp.auth" , true ) ; prop . put ( "mail.smtp.starttls.enable" , "true" ) ; pro...
This function will send an email and add the generated sql file as an attachment
29,354
public final void setDate ( final Date date ) { this . date = date ; if ( date instanceof DateTime ) { if ( Value . DATE . equals ( getParameter ( Parameter . VALUE ) ) ) { getParameters ( ) . replace ( Value . DATE_TIME ) ; } updateTimeZone ( ( ( DateTime ) date ) . getTimeZone ( ) ) ; } else { if ( date != null ) { g...
Sets the date value of this property . The timezone and value of this instance will also be updated accordingly .
29,355
public final PeriodList getConsumedTime ( final Date rangeStart , final Date rangeEnd ) { return getConsumedTime ( rangeStart , rangeEnd , true ) ; }
Returns a normalised list of periods representing the consumed time for this event .
29,356
public final PeriodList getConsumedTime ( final Date rangeStart , final Date rangeEnd , final boolean normalise ) { PeriodList periods = new PeriodList ( ) ; if ( ! Transp . TRANSPARENT . equals ( getProperty ( Property . TRANSP ) ) ) { periods = calculateRecurrenceSet ( new Period ( new DateTime ( rangeStart ) , new D...
Returns a list of periods representing the consumed time for this event in the specified range . Note that the returned list may contain a single period for non - recurring components or multiple periods for recurring components . If no time is consumed by this event an empty list is returned .
29,357
public final VEvent getOccurrence ( final Date date ) throws IOException , URISyntaxException , ParseException { final PeriodList consumedTime = getConsumedTime ( date , date ) ; for ( final Period p : consumedTime ) { if ( p . getStart ( ) . equals ( date ) ) { final VEvent occurrence = ( VEvent ) this . copy ( ) ; oc...
Returns a single occurrence of a recurring event .
29,358
public final DtEnd getEndDate ( final boolean deriveFromDuration ) { DtEnd dtEnd = getProperty ( Property . DTEND ) ; if ( dtEnd == null && deriveFromDuration && getStartDate ( ) != null ) { final DtStart dtStart = getStartDate ( ) ; final Duration vEventDuration ; if ( getDuration ( ) != null ) { vEventDuration = getD...
Convenience method to pull the DTEND out of the property list . If DTEND was not specified use the DTSTART + DURATION to calculate it .
29,359
public Component copy ( ) throws ParseException , IOException , URISyntaxException { final VEvent copy = ( VEvent ) super . copy ( ) ; copy . alarms = new ComponentList < VAlarm > ( alarms ) ; return copy ; }
Overrides default copy method to add support for copying alarm sub - components .
29,360
public static String unquote ( final String aValue ) { if ( aValue != null && aValue . startsWith ( "\"" ) && aValue . endsWith ( "\"" ) ) { return aValue . substring ( 0 , aValue . length ( ) - 1 ) . substring ( 1 ) ; } return aValue ; }
Convenience method for removing surrounding quotes from a string value .
29,361
public final boolean includes ( final Date date , final int inclusiveMask ) { boolean includes ; if ( ( inclusiveMask & INCLUSIVE_START ) > 0 ) { includes = ! rangeStart . after ( date ) ; } else { includes = rangeStart . before ( date ) ; } if ( ( inclusiveMask & INCLUSIVE_END ) > 0 ) { includes = includes && ! rangeE...
Decides whether a date falls within this period .
29,362
public final boolean intersects ( final DateRange range ) { boolean intersects = false ; if ( range . includes ( rangeStart ) && ! range . getRangeEnd ( ) . equals ( rangeStart ) ) { intersects = true ; } else if ( includes ( range . getRangeStart ( ) ) && ! rangeEnd . equals ( range . getRangeStart ( ) ) ) { intersect...
Decides whether this period intersects with another one .
29,363
public final boolean adjacent ( final DateRange range ) { boolean adjacent = false ; if ( rangeStart . equals ( range . getRangeEnd ( ) ) ) { adjacent = true ; } else if ( rangeEnd . equals ( range . getRangeStart ( ) ) ) { adjacent = true ; } return adjacent ; }
Decides whether these periods are serial without a gap .
29,364
protected final void registerExtendedFactory ( String key , T factory ) { extendedFactories . put ( key , factory ) ; }
Register a non - standard content factory .
29,365
public final < R > R getProperty ( final String aName ) { for ( final T p : this ) { if ( p . getName ( ) . equalsIgnoreCase ( aName ) ) { return ( R ) p ; } } return null ; }
Returns the first property of specified name .
29,366
@ SuppressWarnings ( "unchecked" ) public final < C extends T > PropertyList < C > getProperties ( final String name ) { final PropertyList < C > list = new PropertyList < C > ( ) ; for ( final T p : this ) { if ( p . getName ( ) . equalsIgnoreCase ( name ) ) { list . add ( ( C ) p ) ; } } return list ; }
Returns a list of properties with the specified name .
29,367
public static String encode ( final String s ) { if ( CompatibilityHints . isHintEnabled ( CompatibilityHints . KEY_NOTES_COMPATIBILITY ) && CID_PATTERN . matcher ( s ) . matches ( ) ) { return NOTES_CID_REPLACEMENT_PATTERN . matcher ( s ) . replaceAll ( "" ) ; } return s ; }
Encodes the specified URI string using the UTF - 8 charset . In the event that an exception is thrown the specifed URI string is returned unmodified .
29,368
public PropertyList < Property > getProperties ( final String paramValue ) { PropertyList < Property > properties = index . get ( paramValue ) ; if ( properties == null ) { properties = EMPTY_LIST ; } return properties ; }
Returns a list of properties containing a parameter with the specified value .
29,369
public Property getProperty ( final String paramValue ) { final PropertyList < Property > properties = getProperties ( paramValue ) ; if ( ! properties . isEmpty ( ) ) { return properties . iterator ( ) . next ( ) ; } return null ; }
Returns the first property containing a parameter with the specified value .
29,370
public final void validate ( Method method ) throws ValidationException { final Validator < CalendarComponent > validator = getValidator ( method ) ; if ( validator != null ) { validator . validate ( this ) ; } else { throw new ValidationException ( "Unsupported method: " + method ) ; } }
Performs method - specific ITIP validation .
29,371
public final TemporalAmount getDuration ( ) { if ( duration == null ) { return TemporalAmountAdapter . fromDateRange ( getStart ( ) , getEnd ( ) ) . getDuration ( ) ; } return duration . getDuration ( ) ; }
Returns the duration of this period . If an explicit duration is not specified the duration is derived from the end date .
29,372
public final PeriodList subtract ( final Period period ) { final PeriodList result = new PeriodList ( ) ; if ( period . contains ( this ) ) { return result ; } else if ( ! period . intersects ( this ) ) { result . add ( this ) ; return result ; } DateTime newPeriodStart ; DateTime newPeriodEnd ; if ( ! period . getStar...
Creates a set of periods resulting from the subtraction of the specified period from this one . If the specified period is completely contained in this period the resulting list will contain two periods . Otherwise it will contain one . If the specified period does not interest this period a list containing this period...
29,373
public final int compareTo ( final Period arg0 ) { if ( arg0 == null ) { throw new ClassCastException ( "Cannot compare this object to null" ) ; } final int startCompare = getStart ( ) . compareTo ( arg0 . getStart ( ) ) ; if ( startCompare != 0 ) { return startCompare ; } else if ( duration == null ) { final int endCo...
Compares the specified period with this period . First compare the start dates . If they are the same compare the end dates .
29,374
public final boolean inDaylightTime ( final Date date ) { final Observance observance = vTimeZone . getApplicableObservance ( new DateTime ( date ) ) ; return ( observance instanceof Daylight ) ; }
Determines if the specified date is in daylight time according to this timezone . This is done by finding the latest supporting observance for the specified date and identifying whether it is daylight time .
29,375
public final < T extends Parameter > T getParameter ( final String aName ) { for ( final Parameter p : parameters ) { if ( aName . equalsIgnoreCase ( p . getName ( ) ) ) { return ( T ) p ; } } return null ; }
Returns the first parameter with the specified name .
29,376
public final ParameterList getParameters ( final String name ) { final ParameterList list = new ParameterList ( ) ; for ( final Parameter p : parameters ) { if ( p . getName ( ) . equalsIgnoreCase ( name ) ) { list . add ( p ) ; } } return list ; }
Returns a list of parameters with the specified name .
29,377
public final boolean replace ( final Parameter parameter ) { for ( Parameter parameter1 : getParameters ( parameter . getName ( ) ) ) { remove ( parameter1 ) ; } return add ( parameter ) ; }
Replace any parameters of the same type with the one specified .
29,378
public final void removeAll ( final String paramName ) { final ParameterList params = getParameters ( paramName ) ; parameters . removeAll ( params . parameters ) ; }
Remove all parameters with the specified name .
29,379
public Parameter createParameter ( final String name , final String value ) throws URISyntaxException { final ParameterFactory factory = getFactory ( name ) ; Parameter parameter ; if ( factory != null ) { parameter = factory . createParameter ( value ) ; } else if ( isExperimentalName ( name ) ) { parameter = new XPar...
Creates a parameter .
29,380
public static Calendar load ( final String filename ) throws IOException , ParserException { return new CalendarBuilder ( ) . build ( Files . newInputStream ( Paths . get ( filename ) ) ) ; }
Loads a calendar from the specified file .
29,381
public static Calendar load ( final URL url ) throws IOException , ParserException { final CalendarBuilder builder = new CalendarBuilder ( ) ; return builder . build ( url . openStream ( ) ) ; }
Loads a calendar from the specified URL .
29,382
public static Calendar wrap ( final CalendarComponent ... component ) { final ComponentList < CalendarComponent > components = new ComponentList < > ( Arrays . asList ( component ) ) ; return new Calendar ( components ) ; }
Wraps a component in a calendar .
29,383
public static Uid getUid ( final Calendar calendar ) throws ConstraintViolationException { Uid uid = null ; for ( final Component c : calendar . getComponents ( ) ) { for ( final Property foundUid : c . getProperties ( Property . UID ) ) { if ( uid != null && ! uid . equals ( foundUid ) ) { throw new ConstraintViolatio...
Returns a unique identifier as specified by components in the provided calendar .
29,384
public static String getContentType ( Calendar calendar , Charset charset ) { final StringBuilder b = new StringBuilder ( "text/calendar" ) ; final Method method = calendar . getProperty ( Property . METHOD ) ; if ( method != null ) { b . append ( "; method=" ) ; b . append ( method . getValue ( ) ) ; } if ( charset !=...
Returns an appropriate MIME Content - Type for the specified calendar object .
29,385
public static boolean isUtc ( final TimeZone timezone ) { return UTC_ID . equals ( timezone . getID ( ) ) || IBM_UTC_ID . equals ( timezone . getID ( ) ) ; }
Indicates whether the specified timezone is equivalent to UTC time .
29,386
public final Observance getApplicableObservance ( final Date date ) { Observance latestObservance = null ; Date latestOnset = null ; for ( final Observance observance : getObservances ( ) ) { final Date onset = observance . getLatestOnset ( date ) ; if ( latestOnset == null || ( onset != null && onset . after ( latestO...
Returns the latest applicable timezone observance for the specified date .
29,387
public Component copy ( ) throws ParseException , IOException , URISyntaxException { final VTimeZone copy = ( VTimeZone ) super . copy ( ) ; copy . observances = new ComponentList < Observance > ( observances ) ; return copy ; }
Overrides default copy method to add support for copying observance sub - components .
29,388
public static Date getInstance ( final java . util . Date date , final Value type ) { if ( Value . DATE . equals ( type ) ) { return new Date ( date ) ; } return new DateTime ( date ) ; }
Returns a new date instance of the specified type . If no type is specified a DateTime instance is returned .
29,389
public static DateList getDateListInstance ( final DateList origList ) { final DateList list = new DateList ( origList . getType ( ) ) ; if ( origList . isUtc ( ) ) { list . setUtc ( true ) ; } else { list . setTimeZone ( origList . getTimeZone ( ) ) ; } return list ; }
Instantiate a new datelist with the same type timezone and utc settings as the origList .
29,390
public static long round ( final long time , final int precision , final TimeZone tz ) { if ( ( precision == PRECISION_SECOND ) && ( ( time % Dates . MILLIS_PER_SECOND ) == 0 ) ) { return time ; } final Calendar cal = Calendar . getInstance ( tz ) ; cal . setTimeInMillis ( time ) ; if ( precision == PRECISION_DAY ) { c...
Rounds a time value to remove any precision smaller than specified .
29,391
private void setTime ( final String value , final DateFormat format , final java . util . TimeZone tz ) throws ParseException { if ( tz != null ) { format . setTimeZone ( tz ) ; } setTime ( format . parse ( value ) . getTime ( ) ) ; }
Internal set of time by parsing value string .
29,392
public final void setUtc ( final boolean utc ) { this . timezone = null ; if ( utc ) { getFormat ( ) . setTimeZone ( TimeZones . getUtcTimeZone ( ) ) ; } else { resetTimeZone ( ) ; } time = new Time ( time , getFormat ( ) . getTimeZone ( ) , utc ) ; }
Updates this date - time to display in UTC time if the argument is true . Otherwise resets to the default timezone .
29,393
private DateTime getCachedOnset ( final Date date ) { int index = Arrays . binarySearch ( onsetsMillisec , date . getTime ( ) ) ; if ( index >= 0 ) { return onsetsDates [ index ] ; } else { int insertionIndex = - index - 1 ; return onsetsDates [ insertionIndex - 1 ] ; } }
Returns a cached onset for the specified date .
29,394
public final void setValue ( final String aValue ) throws URISyntaxException { if ( getParameter ( Parameter . ENCODING ) != null ) { try { final BinaryDecoder decoder = DecoderFactory . getInstance ( ) . createBinaryDecoder ( getParameter ( Parameter . ENCODING ) ) ; binary = decoder . decode ( aValue . getBytes ( ) )...
Sets the current value of the Attach instance . If the specified value is encoded binary data the value is decoded and stored in the binary field . Otherwise the value is assumed to be a URI location to binary data and is stored as such .
29,395
public < T extends Parameter > T copy ( ) throws URISyntaxException { if ( factory == null ) { throw new UnsupportedOperationException ( "No factory specified" ) ; } return ( T ) factory . createParameter ( getValue ( ) ) ; }
Deep copy of parameter .
29,396
public void assertOneOrLess ( final String propertyName , final PropertyList properties ) throws ValidationException { if ( properties . getProperties ( propertyName ) . size ( ) > 1 ) { throw new ValidationException ( ASSERT_ONE_OR_LESS_MESSAGE , new Object [ ] { propertyName } ) ; } }
Ensure a property occurs no more than once .
29,397
public void assertOneOrMore ( final String propertyName , final PropertyList properties ) throws ValidationException { if ( properties . getProperties ( propertyName ) . size ( ) < 1 ) { throw new ValidationException ( ASSERT_ONE_OR_MORE_MESSAGE , new Object [ ] { propertyName } ) ; } }
Ensure a property occurs at least once .
29,398
public void assertOne ( final String propertyName , final PropertyList properties ) throws ValidationException { if ( properties . getProperties ( propertyName ) . size ( ) != 1 ) { throw new ValidationException ( ASSERT_ONE_MESSAGE , new Object [ ] { propertyName } ) ; } }
Ensure a property occurs once .
29,399
public void assertNone ( final String propertyName , final PropertyList properties ) throws ValidationException { if ( properties . getProperty ( propertyName ) != null ) { throw new ValidationException ( ASSERT_NONE_MESSAGE , new Object [ ] { propertyName } ) ; } }
Ensure a property doesn t occur in the specified list .