--- a/extensions.st Wed Nov 30 17:43:06 2016 +0100
+++ b/extensions.st Wed Nov 30 17:46:38 2016 +0100
@@ -951,6 +951,502 @@
"Modified: / 07-05-2013 / 11:21:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
+!(Java classForName:'JAVA::java::lang::Byte') class methodsFor:'* proxies *'!
+
+javaWrap: object
+ |inst|
+ inst := self basicNew.
+ inst perform: #'<init>(B)V' with: object.
+ ^ inst.
+! !
+
+!(Java classForName:'JAVA::java::lang::Byte') class methodsFor:'* proxies *'!
+
+javaWrapRequired
+ "Returns true, if a #javaWrap: has to be called
+ prior an instance of Smalltalk object is passed
+ as an argument to Java method, whoose formal tyoe
+ is the receiver."
+
+ ^true
+! !
+
+!(Java classForName:'JAVA::java::lang::Double') class methodsFor:'queries'!
+
+javaWrap: object
+ |inst|
+ inst := self basicNew.
+ inst perform: #'<init>(D)V' with: object with: nil.
+ ^ inst.
+! !
+
+!(Java classForName:'JAVA::java::lang::Double') class methodsFor:'queries'!
+
+javaWrapRequired
+ "Returns true, if a #javaWrap: has to be called
+ prior an instance of Smalltalk object is passed
+ as an argument to Java method, whoose formal tyoe
+ is the receiver."
+
+ ^true
+! !
+
+!(Java classForName:'JAVA::java::lang::Float') class methodsFor:'queries'!
+
+javaWrap: object
+ |inst|
+ inst := self basicNew.
+ inst perform: #'<init>(F)V' with: object.
+ ^ inst.
+! !
+
+!(Java classForName:'JAVA::java::lang::Float') class methodsFor:'queries'!
+
+javaWrapRequired
+ "Returns true, if a #javaWrap: has to be called
+ prior an instance of Smalltalk object is passed
+ as an argument to Java method, whoose formal tyoe
+ is the receiver."
+
+ ^true
+! !
+
+!(Java classForName:'JAVA::java::lang::Integer') class methodsFor:'queries'!
+
+javaWrap: object
+ |inst|
+ inst := self basicNew.
+ inst perform: #'<init>(I)V' with: object.
+ ^ inst.
+! !
+
+!(Java classForName:'JAVA::java::lang::Integer') class methodsFor:'queries'!
+
+javaWrapRequired
+ "Returns true, if a #javaWrap: has to be called
+ prior an instance of Smalltalk object is passed
+ as an argument to Java method, whoose formal tyoe
+ is the receiver."
+
+ ^true
+! !
+
+!(Java classForName:'JAVA::java::lang::Long') class methodsFor:'queries'!
+
+javaWrap: object
+ |inst|
+ inst := self basicNew.
+ inst perform: #'<init>(J)V' with: object with: nil.
+ ^ inst.
+! !
+
+!(Java classForName:'JAVA::java::lang::Long') class methodsFor:'queries'!
+
+javaWrapRequired
+ "Returns true, if a #javaWrap: has to be called
+ prior an instance of Smalltalk object is passed
+ as an argument to Java method, whoose formal tyoe
+ is the receiver."
+
+ ^true
+! !
+
+!(Java classForName:'JAVA::java::lang::Short') class methodsFor:'queries'!
+
+javaWrap: object
+ |inst|
+ inst := self basicNew.
+ inst perform: #'<init>(S)V' with: object.
+ ^ inst.
+! !
+
+!(Java classForName:'JAVA::java::lang::Short') class methodsFor:'queries'!
+
+javaWrapRequired
+ "Returns true, if a #javaWrap: has to be called
+ prior an instance of Smalltalk object is passed
+ as an argument to Java method, whoose formal tyoe
+ is the receiver."
+
+ ^true
+! !
+
+!(Java classForName:'JAVA::java::lang::String') class methodsFor:'queries'!
+
+javaWrap: object
+ | jstring |
+
+ object isNil ifTrue:[ ^ nil ].
+ jstring := self basicNew.
+ jstring perform: #'<init>([C)V' with: object.
+ ^jstring
+! !
+
+!(Java classForName:'JAVA::java::lang::String') class methodsFor:'queries'!
+
+javaWrapRequired
+ "Returns true, if a #javaWrap: has to be called
+ prior an instance of Smalltalk object is passed
+ as an argument to Java method, whoose formal tyoe
+ is the receiver."
+
+ ^true
+! !
+
+!(Java classForName:'java.lang.Throwable') methodsFor:'others'!
+
+description
+ ^self getMessage
+! !
+
+!(Java classForName:'java.lang.Throwable') methodsFor:'others'!
+
+isJavaLangThrowable
+ ^true
+! !
+
+!(Java classForName:'java.util.AbstractList') methodsFor:'* instance *'!
+
+at: index
+
+ "/ Defined here (in addition to List iface) to overwrite
+ "/ Object>>at:
+ ^ self get: index - 1.
+! !
+
+!(Java classForName:'java.util.AbstractList') methodsFor:'* instance *'!
+
+inspectorClass
+ ^JavaListInspectorView
+! !
+
+!(Java classForName:'java.util.Collection') methodsFor:'* instance *'!
+
+anElement
+ "return any element from the collection,
+ report an error if there is none"
+
+ self do: [:each | ^ each].
+ Smalltalk::Collection emptyCollectionSignal raise.
+! !
+
+!(Java classForName:'java.util.Collection') methodsFor:'* instance *'!
+
+collect:aBlock
+ "for each element in the receiver, evaluate the argument, aBlock
+ and return a new collection with the results"
+
+ |newCollection|
+
+ newCollection := self species new.
+ self do:[:element | newCollection add:(aBlock value:element)].
+ ^ newCollection
+
+ "
+ #(1 2 3 4) collect:[:n | n * 2]
+ "
+! !
+
+!(Java classForName:'java.util.Collection') methodsFor:'* instance *'!
+
+detect:aBlock
+ "evaluate the argument, aBlock for each element in the receiver until
+ the block returns true; in this case return the element which caused
+ the true evaluation.
+ If none of the evaluations returns true, report an error"
+
+ ^ self detect:aBlock ifNone:[self errorNotFound]
+
+ "
+ #(1 2 3 4) detect:[:n | n odd]
+ #(2 4 6 8) detect:[:n | n odd]
+ "
+! !
+
+!(Java classForName:'java.util.Collection') methodsFor:'* instance *'!
+
+detect:aOneArgBlock ifNone:exceptionBlock
+ "evaluate the argument, aBlock for each element in the receiver until
+ the block returns true; in this case return the element which caused
+ the true evaluation.
+ If none of the evaluations returns true, return the result of the
+ evaluation of the exceptionBlock"
+
+ self do:[:each |
+ (aOneArgBlock value:each) ifTrue:[^ each].
+ ].
+ ^ exceptionBlock value
+
+ "
+ #(1 2 3 4) detect:[:n | n odd] ifNone:['sorry']
+ #(2 4 6 8) detect:[:n | n odd] ifNone:['sorry']
+ "
+
+ "Modified: / 13-09-2006 / 11:17:42 / cg"
+! !
+
+!(Java classForName:'java.util.Collection') methodsFor:'* instance *'!
+
+do: aBlock
+ "Iterate over collection evaluating given block with each element"
+
+ | iterator |
+
+ iterator := self iterator.
+ [ iterator hasNext ] whileTrue:[
+ aBlock value: iterator next.
+ ].
+! !
+
+!(Java classForName:'java.util.Collection') methodsFor:'* instance *'!
+
+do:aBlock separatedBy:betweenBlock
+ "evaluate the argument, aBlock for each element.
+ Between elements (i.e. after each except for the last),
+ evaluate betweenBlock.
+ This is a utility helper for collection printers
+ (for example, to print a space between elements)."
+
+"/ could do the more hackish:
+"/
+"/ |b|
+"/
+"/ b := [ b := betweenBlock ].
+"/ self do:[:element |
+"/ b value.
+"/ aBlock value:element
+"/ ].
+"/
+"/ but that creates a block, whereas the following does not.
+
+ |first|
+
+ first := true.
+ self do:[:element |
+ first ifTrue:[
+ first := false
+ ] ifFalse:[
+ betweenBlock value.
+ ].
+ aBlock value:element
+ ].
+
+ "
+ #(1 2 3 4) do:[:el | Transcript show:el]
+ separatedBy:[ Transcript show:'-']
+
+ (Dictionary with:(1->'one') with:(2->'two'))
+ do:[:el | Transcript showCR:el printString]
+ separatedBy:[ Transcript showCR:'----']
+
+ (Dictionary with:(1->'one') with:(2->'two'))
+ associations
+ do:[:el | Transcript showCR:el printString]
+ separatedBy:[ Transcript showCR:'----']
+
+ "
+
+ "Modified: / 11.2.2000 / 11:23:15 / cg"
+! !
+
+!(Java classForName:'java.util.Collection') methodsFor:'* instance *'!
+
+inject:thisValue into:binaryBlock
+ "starting with thisValue for value, pass this value and each element
+ to binaryBlock, replacing value with the result returned from the block
+ in the next iteration.
+
+ See also: #fold: #reduce:"
+
+ |nextValue|
+
+ nextValue := thisValue.
+ self do: [:each | nextValue := binaryBlock value:nextValue value:each].
+ ^ nextValue
+
+ "sum up the elements of a collection:
+
+ #(1 2 3 4) inject:0 into:[:accu :element | accu + element]
+ (1 to:10) inject:0 into:[:accu :element | accu + element]
+
+ find the minimum:
+
+ |coll|
+ coll := #(1 99 -15 20 100).
+ coll inject:(coll first) into:[:minSoFar :element | minSoFar min:element]
+ "
+
+ "Modified: 23.4.1996 / 13:47:06 / cg"
+! !
+
+!(Java classForName:'java.util.Collection') methodsFor:'* instance *'!
+
+reject:aBlock
+ "return a new collection with all elements from the receiver, for which
+ the argument aBlock evaluates to false"
+
+ ^ self select:[:element | (aBlock value:element) not]
+
+ "
+ #(1 2 3 4) reject:[:e | e odd]
+ (1 to:10) reject:[:e | e even]
+ "
+! !
+
+!(Java classForName:'java.util.Collection') methodsFor:'* instance *'!
+
+select:aBlock
+ "return a new collection with all elements from the receiver, for which
+ the argument aBlock evaluates to true.
+ See also: #removeAllFoundIn: and #removeAllSuchThat:"
+
+ |newCollection|
+
+ newCollection := self species new.
+ self do:[:each |
+ (aBlock value:each) ifTrue:[newCollection add:each].
+ ].
+ ^ newCollection
+
+ "
+ #(1 2 3 4) select:[:e | e odd]
+ (1 to:10) select:[:e | e even]
+ "
+
+ "Modified: / 07-08-2010 / 16:26:40 / cg"
+! !
+
+!(Java classForName:'java.util.List') methodsFor:'* instance *'!
+
+at: index
+ ^ self at: index ifAbsent:[ self subscriptBoundsError: index ]
+! !
+
+!(Java classForName:'java.util.List') methodsFor:'* instance *'!
+
+at: index ifAbsent: errorBlock
+ (index between: 1 and: self size) ifTrue:[
+ ^ self get: index - 1
+ ].
+ ^ errorBlock value
+! !
+
+!(Java classForName:'java.util.List') methodsFor:'* instance *'!
+
+at: index put: anObject
+ ^ self put: index - 1 value: anObject
+! !
+
+!(Java classForName:'java.util.List') methodsFor:'* instance *'!
+
+fifth
+ ^ self get: 4
+! !
+
+!(Java classForName:'java.util.List') methodsFor:'* instance *'!
+
+first
+ ^ self get: 0
+! !
+
+!(Java classForName:'java.util.List') methodsFor:'* instance *'!
+
+fourth
+ ^ self get: 3
+! !
+
+!(Java classForName:'java.util.List') methodsFor:'* instance *'!
+
+identityIndexOf:anElement
+ "Returns the index of an element or 0, if not found.
+ Compare using == (identity)"
+
+ 1 to: self size do:[:i |
+ (self get: i - 1) == anElement ifTrue:[ ^ i ].
+ ].
+ ^ 0
+! !
+
+!(Java classForName:'java.util.List') methodsFor:'* instance *'!
+
+indexOf:anElement
+ "Returns the index of an element or 0, if not found.
+ Compare using Object#equals()"
+
+ ^ (self perform: #'indexOf(Ljava/lang/Object;)I' with: anElement) + 1.
+! !
+
+!(Java classForName:'java.util.List') methodsFor:'* instance *'!
+
+last
+ ^ self get: self size - 1
+! !
+
+!(Java classForName:'java.util.List') methodsFor:'* instance *'!
+
+second
+ ^ self get: 1
+! !
+
+!(Java classForName:'java.util.List') methodsFor:'* instance *'!
+
+third
+ ^ self get: 2
+! !
+
+!(Java classForName:'java.util.Map') methodsFor:'* instance *'!
+
+at:aKey
+ "return the element indexed by aKey - report an error if none found"
+
+ ^ self at:aKey ifAbsent:[self errorKeyNotFound:aKey]
+! !
+
+!(Java classForName:'java.util.Map') methodsFor:'* instance *'!
+
+at:key ifAbsent:exceptionBlock
+ "return the element indexed by aKey -
+ return result of exceptionBlock if no element is stored under aKey"
+
+ (self containsKey: key) ifTrue:[ ^ self get: key ].
+ ^ exceptionBlock value
+! !
+
+!(Java classForName:'java.util.Map') methodsFor:'* instance *'!
+
+do:aBlock
+ "perform the block for all values in the collection.
+
+ See also:
+ #associationsDo: (which passes key-value associations)
+ #keysAndValuesDo: (which passes keys & values separately)
+ #keysDo: (which passes keys only)
+
+ WARNING: do not add/remove elements while iterating over the receiver.
+ Iterate over a copy to do this."
+
+ self values do: aBlock
+! !
+
+!(Java classForName:'java.util.Map') methodsFor:'* instance *'!
+
+keysAndValuesDo:aTwoArgBlock
+ "evaluate the argument, aBlock for every element in the collection,
+ passing both key and element as arguments.
+
+ See also:
+ #associationsDo: (which passes keys->value pairs)
+ #do: (which only passes values)
+ #keysDo: (which only passes keys)
+
+ This is much like #associationsDo:, but aBlock gets the
+ key and value as two separate arguments."
+
+ self keySet do:[:each |
+ aTwoArgBlock value: each value: (self get: each).
+ ].
+! !
+
!LargeInteger class methodsFor:'queries'!
isJavaPrimitiveType
@@ -2042,12 +2538,11 @@
!ZipArchive methodsFor:'queries - java support'!
isValidFile: path
- "Return true, if the recevier contains given file. false otherwise.
- "
- ^zipMembersByName includesKey: path
+ "Return true, if the recevier contains given file. false otherwise."
+
+ ^ zipMembersByName notNil and:[zipMembersByName includesKey:path]
"Created: / 20-05-2013 / 23:37:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-
! !
!ZipArchive methodsFor:'reading - java support'!