[jira] [Commented] (GROOVY-8957) String with length 1, if assigned to int variable, assigns the ascii value. String with more than 1 length throws GroovyCastException

2019-02-26 Thread Adithyan K (JIRA)


[ 
https://issues.apache.org/jira/browse/GROOVY-8957?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16777996#comment-16777996
 ] 

Adithyan K commented on GROOVY-8957:


Closing as per the comment by Paul King

> String with length 1, if assigned to int variable, assigns the ascii value. 
> String with more than 1 length throws GroovyCastException
> -
>
> Key: GROOVY-8957
> URL: https://issues.apache.org/jira/browse/GROOVY-8957
> Project: Groovy
>  Issue Type: Bug
>  Components: groovy-jdk
>Reporter: Adithyan K
>Priority: Major
>
> String with length 1, if assigned to int variable, assigns the ascii value. 
> String with more than 1 length throws GroovyCastException
> {code}
> /*line 1  : case-1 */ charc1 = '1'
> /*line 2  : case-1 */ int n1 = c1
> /*line 3  : case-1 */ println "n1 = $n1" //prints ascii value of 1 :'n1 = 49'
> /*line 4  : case-2 */ String  s2 = '1'
> /*line 5  : case-2 */ int n21 = s2
> /*line 6  : case-2 */ int n22 = s2 as int
> /*line 7  : case-2 */ println "n21 = $n21" //prints 'n21 = 49'
> /*line 8  : case-2 */ println "n22 = $n22" //prints 'n22 = 1'
> /*line 9  : case-3 */ String  s3 = '10'
> /*line 10 : case-3 */ int n3 = s3 //Throwing Cast Exception
> /*line 11 : case-3 */ println n3
> {code}
> Case-1
> Line 3 prints `49`. It is ok as `char` is assgined to integer in line 2
> Case-2
>  Line 7 prints  `n21` eventhough String is assgined in line 5... Is it right?
> Line 6 : `n22` is assigned 1 as I have written `s2 as int`. This is ok
> Case-3
>  Line 10 : Throwing GroovyCastException. This is ok.
> The difference between Line-5 and Line-10 is the difference in String length. 
> Both are Strings. The former is of length 1 and the latter is of length 2.
> So, String with length 1, if assigned to int variable, assigns the ascii 
> value. String with more than 1 length throws GroovyCastException This looks 
> some what different...
> Is it the acceptable behavior
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Closed] (GROOVY-8957) String with length 1, if assigned to int variable, assigns the ascii value. String with more than 1 length throws GroovyCastException

2019-02-26 Thread Adithyan K (JIRA)


 [ 
https://issues.apache.org/jira/browse/GROOVY-8957?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Adithyan K closed GROOVY-8957.
--
Resolution: Not A Problem

Closing as per comment by Paul King

> String with length 1, if assigned to int variable, assigns the ascii value. 
> String with more than 1 length throws GroovyCastException
> -
>
> Key: GROOVY-8957
> URL: https://issues.apache.org/jira/browse/GROOVY-8957
> Project: Groovy
>  Issue Type: Bug
>  Components: groovy-jdk
>Reporter: Adithyan K
>Priority: Major
>
> String with length 1, if assigned to int variable, assigns the ascii value. 
> String with more than 1 length throws GroovyCastException
> {code}
> /*line 1  : case-1 */ charc1 = '1'
> /*line 2  : case-1 */ int n1 = c1
> /*line 3  : case-1 */ println "n1 = $n1" //prints ascii value of 1 :'n1 = 49'
> /*line 4  : case-2 */ String  s2 = '1'
> /*line 5  : case-2 */ int n21 = s2
> /*line 6  : case-2 */ int n22 = s2 as int
> /*line 7  : case-2 */ println "n21 = $n21" //prints 'n21 = 49'
> /*line 8  : case-2 */ println "n22 = $n22" //prints 'n22 = 1'
> /*line 9  : case-3 */ String  s3 = '10'
> /*line 10 : case-3 */ int n3 = s3 //Throwing Cast Exception
> /*line 11 : case-3 */ println n3
> {code}
> Case-1
> Line 3 prints `49`. It is ok as `char` is assgined to integer in line 2
> Case-2
>  Line 7 prints  `n21` eventhough String is assgined in line 5... Is it right?
> Line 6 : `n22` is assigned 1 as I have written `s2 as int`. This is ok
> Case-3
>  Line 10 : Throwing GroovyCastException. This is ok.
> The difference between Line-5 and Line-10 is the difference in String length. 
> Both are Strings. The former is of length 1 and the latter is of length 2.
> So, String with length 1, if assigned to int variable, assigns the ascii 
> value. String with more than 1 length throws GroovyCastException This looks 
> some what different...
> Is it the acceptable behavior
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Created] (GROOVY-9011) (2/1).equals(2) is false; but (2/1) == (2) is true

2019-02-26 Thread Adithyan K (JIRA)
Adithyan K created GROOVY-9011:
--

 Summary: (2/1).equals(2) is false; but (2/1) == (2) is true
 Key: GROOVY-9011
 URL: https://issues.apache.org/jira/browse/GROOVY-9011
 Project: Groovy
  Issue Type: Bug
  Components: syntax
 Environment: Linux, Ubuntu 18.04
Reporter: Adithyan K


Is it an expected behavior??

Difference between '==' and 'equals()' observed

 

{{adithyan@adithyan:~$ *groovy -e 'println( (2/1).equals(2) )'* }}
{{{color:#14892c}*false* {color}}}
{{adithyan@adithyan:~$ *groovy -e 'println( (2/1) == (2) )'* }}
{{{color:#14892c}*true*{color}}}

{{adithyan@adithyan:~$ *groovy -v* }}
{{*{color:#14892c}Groovy Version: 2.4.15 JVM: 1.8.0_144 Vendor: Oracle 
Corporation OS: Linux{color}*}}

 

 

 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (GROOVY-8957) String with length 1, if assigned to int variable, assigns the ascii value. String with more than 1 length throws GroovyCastException

2019-01-15 Thread Adithyan K (JIRA)


[ 
https://issues.apache.org/jira/browse/GROOVY-8957?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16743581#comment-16743581
 ] 

Adithyan K commented on GROOVY-8957:


Calling `as int` to convert a String to int is perfectly ok.

The point I was concerned is the difference between 'Line-5' and 'Line-10'. 
Both lines are assigning a `String` (Data type is perfectly String. The 
previous line confirms it) to an `int` variable without `as int`.

Line-10 shouts as CastException as it is more than 1 length and Line-5 silently 
assigns the ascii value 49 to the int variable.

If I read your answer as `Groovy treats Strings with length 1 always as char 
for all purposes`, then this issue can be closed. 

> String with length 1, if assigned to int variable, assigns the ascii value. 
> String with more than 1 length throws GroovyCastException
> -
>
> Key: GROOVY-8957
> URL: https://issues.apache.org/jira/browse/GROOVY-8957
> Project: Groovy
>  Issue Type: Bug
>  Components: groovy-jdk
>Reporter: Adithyan K
>Priority: Major
>
> String with length 1, if assigned to int variable, assigns the ascii value. 
> String with more than 1 length throws GroovyCastException
> {code}
> /*line 1  : case-1 */ charc1 = '1'
> /*line 2  : case-1 */ int n1 = c1
> /*line 3  : case-1 */ println "n1 = $n1" //prints ascii value of 1 :'n1 = 49'
> /*line 4  : case-2 */ String  s2 = '1'
> /*line 5  : case-2 */ int n21 = s2
> /*line 6  : case-2 */ int n22 = s2 as int
> /*line 7  : case-2 */ println "n21 = $n21" //prints 'n21 = 49'
> /*line 8  : case-2 */ println "n22 = $n22" //prints 'n22 = 1'
> /*line 9  : case-3 */ String  s3 = '10'
> /*line 10 : case-3 */ int n3 = s3 //Throwing Cast Exception
> /*line 11 : case-3 */ println n3
> {code}
> Case-1
> Line 3 prints `49`. It is ok as `char` is assgined to integer in line 2
> Case-2
>  Line 7 prints  `n21` eventhough String is assgined in line 5... Is it right?
> Line 6 : `n22` is assigned 1 as I have written `s2 as int`. This is ok
> Case-3
>  Line 10 : Throwing GroovyCastException. This is ok.
> The difference between Line-5 and Line-10 is the difference in String length. 
> Both are Strings. The former is of length 1 and the latter is of length 2.
> So, String with length 1, if assigned to int variable, assigns the ascii 
> value. String with more than 1 length throws GroovyCastException This looks 
> some what different...
> Is it the acceptable behavior
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Created] (GROOVY-8957) String with length 1, if assigned to int variable, assigns the ascii value. String with more than 1 length throws GroovyCastException

2019-01-15 Thread Adithyan K (JIRA)
Adithyan K created GROOVY-8957:
--

 Summary: String with length 1, if assigned to int variable, 
assigns the ascii value. String with more than 1 length throws 
GroovyCastException
 Key: GROOVY-8957
 URL: https://issues.apache.org/jira/browse/GROOVY-8957
 Project: Groovy
  Issue Type: Bug
  Components: groovy-jdk
Reporter: Adithyan K


String with length 1, if assigned to int variable, assigns the ascii value. 
String with more than 1 length throws GroovyCastException
{code}
/*line 1  : case-1 */ charc1 = '1'
/*line 2  : case-1 */ int n1 = c1
/*line 3  : case-1 */ println "n1 = $n1" //prints ascii value of 1 :'n1 = 49'

/*line 4  : case-2 */ String  s2 = '1'
/*line 5  : case-2 */ int n21 = s2
/*line 6  : case-2 */ int n22 = s2 as int
/*line 7  : case-2 */ println "n21 = $n21" //prints 'n21 = 49'
/*line 8  : case-2 */ println "n22 = $n22" //prints 'n22 = 1'

/*line 9  : case-3 */ String  s3 = '10'
/*line 10 : case-3 */ int n3 = s3 //Throwing Cast Exception
/*line 11 : case-3 */ println n3
{code}
Case-1

Line 3 prints `49`. It is ok as `char` is assgined to integer in line 2

Case-2
 Line 7 prints  `n21` eventhough String is assgined in line 5... Is it right?

Line 6 : `n22` is assigned 1 as I have written `s2 as int`. This is ok

Case-3
 Line 10 : Throwing GroovyCastException. This is ok.

The difference between Line-5 and Line-10 is the difference in String length. 
Both are Strings. The former is of length 1 and the latter is of length 2.

So, String with length 1, if assigned to int variable, assigns the ascii value. 
String with more than 1 length throws GroovyCastException This looks some what 
different...

Is it the acceptable behavior

 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (GROOVY-8939) Additional Methods in StringGroovyMethods

2018-12-25 Thread Adithyan K (JIRA)


[ 
https://issues.apache.org/jira/browse/GROOVY-8939?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16728841#comment-16728841
 ] 

Adithyan K commented on GROOVY-8939:


PR created https://github.com/apache/groovy/pull/846

> Additional Methods in StringGroovyMethods
> -
>
> Key: GROOVY-8939
> URL: https://issues.apache.org/jira/browse/GROOVY-8939
> Project: Groovy
>  Issue Type: Improvement
>Affects Versions: 3.0.0-alpha-4
>Reporter: Adithyan K
>Priority: Minor
>  Time Spent: 10m
>  Remaining Estimate: 0h
>
> Additional methods can be added in StringGroovyMethods for better API Usage.
> {{CharSequence takeRight(CharSequence self, int num) }}
> {{String takeRight(String self, int num) }}
> {{String takeRight(GString self, int num) }}
> {{CharSequence takeAfter(CharSequence self, CharSequence searchString) }}
> {{String takeAfter(String self, CharSequence searchString) }}
> {{String takeAfter(GString self, CharSequence searchString) }}
> {{CharSequence takeBefore(CharSequence self, CharSequence searchString) }}
> {{String takeBefore(GString self, String searchString) }}
> {{String takeBefore(String self, String searchString) }}
> {{CharSequence dropRight(CharSequence self, int num) }}
> {{String dropRight(String self, int num) }}
> {{String dropRight(GString self, int num) }}
> {{CharSequence takeBetween(CharSequence self, CharSequence from, CharSequence 
> to) }}
> {{String takeBetween(String self, CharSequence from, CharSequence to) }}
> {{String takeBetween(GString self, CharSequence from, CharSequence to) }}
> {{CharSequence takeBetween(CharSequence self, CharSequence enclosure) }}
> {{String takeBetween(String self, CharSequence enclosure) }}
> {{String takeBetween(GString self, CharSequence enclosure) }}
> {{CharSequence takeBetween(CharSequence self, CharSequence from, CharSequence 
> to, int occurrence) }}
> {{String takeBetween(String self, CharSequence from, CharSequence to, int 
> occurrence) }}
> {{String takeBetween(GString self, CharSequence from, CharSequence to, int 
> occurrence) }}
> {{CharSequence takeBetween(CharSequence self, CharSequence enclosure, int 
> occurrence) }}
> {{String takeBetween(String self, CharSequence enclosure, int occurrence) }}
> {{String takeBetween(GString self, CharSequence enclosure, int occurrence) }}
> {{boolean startsWithIgnoreCase(CharSequence self, CharSequence searchString) 
> }}
> {{boolean endsWithIgnoreCase(CharSequence self, CharSequence searchString) }}
> {{boolean containsIgnoreCase(CharSequence self, CharSequence searchString)}}
>  
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (GROOVY-8939) Additional Methods in StringGroovyMethods

2018-12-25 Thread Adithyan K (JIRA)


[ 
https://issues.apache.org/jira/browse/GROOVY-8939?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16728839#comment-16728839
 ] 

Adithyan K commented on GROOVY-8939:


Interim PR got reviewed [https://github.com/adithyank/groovy/pull/1] and 
changes incorporated

 

> Additional Methods in StringGroovyMethods
> -
>
> Key: GROOVY-8939
> URL: https://issues.apache.org/jira/browse/GROOVY-8939
> Project: Groovy
>  Issue Type: Improvement
>Affects Versions: 3.0.0-alpha-4
>Reporter: Adithyan K
>Priority: Minor
>
> Additional methods can be added in StringGroovyMethods for better API Usage.
> {{CharSequence takeRight(CharSequence self, int num) }}
> {{String takeRight(String self, int num) }}
> {{String takeRight(GString self, int num) }}
> {{CharSequence takeAfter(CharSequence self, CharSequence searchString) }}
> {{String takeAfter(String self, CharSequence searchString) }}
> {{String takeAfter(GString self, CharSequence searchString) }}
> {{CharSequence takeBefore(CharSequence self, CharSequence searchString) }}
> {{String takeBefore(GString self, String searchString) }}
> {{String takeBefore(String self, String searchString) }}
> {{CharSequence dropRight(CharSequence self, int num) }}
> {{String dropRight(String self, int num) }}
> {{String dropRight(GString self, int num) }}
> {{CharSequence takeBetween(CharSequence self, CharSequence from, CharSequence 
> to) }}
> {{String takeBetween(String self, CharSequence from, CharSequence to) }}
> {{String takeBetween(GString self, CharSequence from, CharSequence to) }}
> {{CharSequence takeBetween(CharSequence self, CharSequence enclosure) }}
> {{String takeBetween(String self, CharSequence enclosure) }}
> {{String takeBetween(GString self, CharSequence enclosure) }}
> {{CharSequence takeBetween(CharSequence self, CharSequence from, CharSequence 
> to, int occurrence) }}
> {{String takeBetween(String self, CharSequence from, CharSequence to, int 
> occurrence) }}
> {{String takeBetween(GString self, CharSequence from, CharSequence to, int 
> occurrence) }}
> {{CharSequence takeBetween(CharSequence self, CharSequence enclosure, int 
> occurrence) }}
> {{String takeBetween(String self, CharSequence enclosure, int occurrence) }}
> {{String takeBetween(GString self, CharSequence enclosure, int occurrence) }}
> {{boolean startsWithIgnoreCase(CharSequence self, CharSequence searchString) 
> }}
> {{boolean endsWithIgnoreCase(CharSequence self, CharSequence searchString) }}
> {{boolean containsIgnoreCase(CharSequence self, CharSequence searchString)}}
>  
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Created] (GROOVY-8939) Additional Methods in StringGroovyMethods

2018-12-25 Thread Adithyan K (JIRA)
Adithyan K created GROOVY-8939:
--

 Summary: Additional Methods in StringGroovyMethods
 Key: GROOVY-8939
 URL: https://issues.apache.org/jira/browse/GROOVY-8939
 Project: Groovy
  Issue Type: Improvement
Affects Versions: 3.0.0-alpha-4
Reporter: Adithyan K


Additional methods can be added in StringGroovyMethods for better API Usage.

{{CharSequence takeRight(CharSequence self, int num) }}
{{String takeRight(String self, int num) }}
{{String takeRight(GString self, int num) }}
{{CharSequence takeAfter(CharSequence self, CharSequence searchString) }}
{{String takeAfter(String self, CharSequence searchString) }}
{{String takeAfter(GString self, CharSequence searchString) }}
{{CharSequence takeBefore(CharSequence self, CharSequence searchString) }}
{{String takeBefore(GString self, String searchString) }}
{{String takeBefore(String self, String searchString) }}
{{CharSequence dropRight(CharSequence self, int num) }}
{{String dropRight(String self, int num) }}
{{String dropRight(GString self, int num) }}
{{CharSequence takeBetween(CharSequence self, CharSequence from, CharSequence 
to) }}
{{String takeBetween(String self, CharSequence from, CharSequence to) }}
{{String takeBetween(GString self, CharSequence from, CharSequence to) }}
{{CharSequence takeBetween(CharSequence self, CharSequence enclosure) }}
{{String takeBetween(String self, CharSequence enclosure) }}
{{String takeBetween(GString self, CharSequence enclosure) }}
{{CharSequence takeBetween(CharSequence self, CharSequence from, CharSequence 
to, int occurrence) }}
{{String takeBetween(String self, CharSequence from, CharSequence to, int 
occurrence) }}
{{String takeBetween(GString self, CharSequence from, CharSequence to, int 
occurrence) }}
{{CharSequence takeBetween(CharSequence self, CharSequence enclosure, int 
occurrence) }}
{{String takeBetween(String self, CharSequence enclosure, int occurrence) }}
{{String takeBetween(GString self, CharSequence enclosure, int occurrence) }}
{{boolean startsWithIgnoreCase(CharSequence self, CharSequence searchString) }}
{{boolean endsWithIgnoreCase(CharSequence self, CharSequence searchString) }}
{{boolean containsIgnoreCase(CharSequence self, CharSequence searchString)}}

 

 

 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (GROOVY-7154) Adding new useful String extension methods

2018-05-10 Thread Adithyan K (JIRA)

[ 
https://issues.apache.org/jira/browse/GROOVY-7154?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16470984#comment-16470984
 ] 

Adithyan K commented on GROOVY-7154:


For one of my projects, I have already implemented the below methods in my own 
`*StringExtension*` class

Can I send a PR for this?

Pls advice !

 

static String after(String self, String after)

/**
 * Splits the given String with the given separator String and returns the 
value at the given column Index. By
 * default, successive occurrence of the separator String is taken are one unit 
and the split is performed
 * 
 * @param self
 * @param separator
 * @param colIndex
 * @return
 */
 static String column(String self, String separator, int colIndex)

/**
 * Splits the given String with Space characters and returns the value at the 
given column Index.
 * 
 * @param self
 * @param colIndex
 * @return
 */
 static String column(String self, int colIndex)
 
 static String left(String self, int chars)

static String right(String self, int chars)

static String before(String self, String searchString)

/**
 * Returns string before '=' char
 *
 */
 static String getBeforeeq(String self)

static String bwDoubleQuotes(String line)

static String bwSingleQuotes(String line)

static String bw(String line, String enclosure)

static String bw(String line, String from, String to)

static String bwDoubleQuotes(String line, int item)

static String bwSingleQuotes(String line, int item)

static String bw(String line, String enclosure, int item)
 
 static void split(String self, String regex, Closure closure)
 
 static long getHexToLong(String hexString)

 

> Adding new useful String extension methods 
> ---
>
> Key: GROOVY-7154
> URL: https://issues.apache.org/jira/browse/GROOVY-7154
> Project: Groovy
>  Issue Type: New Feature
>  Components: groovy-jdk
>Reporter: Maciej Ziarko
>Priority: Minor
>
> There are several methods in commons lang StringUtils that are used very 
> often.
> It would be pretty nice to see them in Groovy in order to eliminate nasty 
> static non-object-oriented invocations StringUtils.methodName
> Suggested methods:
> String substringAfter(String separator)
> Gets the substring after the first occurrence of a separator.
> String substringAfterLast(String separator)
> Gets the substring after the last occurrence of a separator
> String substringBefore(String separator)
> Gets the substring before the first occurrence of a separator.
> String substringBeforeLast(String separator)
> Gets the substring before the last occurrence of a separator.
> String substringBetween(String tag)
> Gets the String that is nested in between two instances of the same String.
> String substringBetween(String open, String close)
> Gets the String that is nested in between two Strings.
> static String[] substringsBetween(String open, String close)
> Searches a String for substrings delimited by a start and end tag, returning 
> all matching substrings in an array.
> String prependIfMissing(CharSequence prefix, CharSequence... prefixes)
> Prepends the prefix to the start of the string if the string does not already 
> start with any of the prefixes.
> String appendIfMissing(CharSequence suffix, CharSequence... suffixes)
> Appends the suffix to the end of the string if the string does not already 
> end with any the suffixes.
> Any other suggestions are welcome.
> I'd like to implement it (possibly migrate from Commons Utils) if it gets 
> green light.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)