@Test public void testCopyWithAll3() { Integer[] x = new Integer[] {1, 2, 3}; Integer[] y = new Integer[] {4, 5, 6}; Integer[] z = ArrayExtensions.copyWithAll_(x, y); assertTrue(ArrayExtensions.isSameAs_(z, new Integer[] {1, 2, 3, 4, 5, 6})); }
public UpdateClassDiff diffTo_(final ClassNode _aClassNode) { if (!st.gravel.support.jvm.ObjectExtensions.equals_(_aClassNode.name(), _name)) { st.gravel.support.jvm.ObjectExtensions.halt(_aClassNode); } if (!st.gravel.support.jvm.ArrayExtensions.equals_(_aClassNode.namespace(), _namespace)) { st.gravel.support.jvm.ObjectExtensions.halt(_aClassNode); } if (!st.gravel.support.jvm.StringExtensions.equals_( _aClassNode.superclassPath(), _superclassPath)) { st.gravel.support.jvm.ObjectExtensions.halt(_aClassNode); } if (!st.gravel.support.jvm.DictionaryExtensions.equals_( _aClassNode.properties(), _properties)) { st.gravel.support.jvm.ObjectExtensions.halt(_aClassNode); } if (!st.gravel.support.jvm.BooleanExtensions.equals_(_aClassNode.isExtension(), _isExtension)) { st.gravel.support.jvm.ObjectExtensions.halt(_aClassNode); } if (!st.gravel.support.jvm.BooleanExtensions.equals_(_aClassNode.isTrait(), _isTrait)) { st.gravel.support.jvm.ObjectExtensions.halt(_aClassNode); } return UpdateClassDiff.factory.reference_superclassReference_thisDiff_metaDiff_( _aClassNode.reference(), ((AbsoluteReference) _aClassNode.superclassReference()), this.diffToClassDescriptionNode_(_aClassNode), _metaclassNode.diffToClassDescriptionNode_(_aClassNode.metaclassNode())); }
@Test public void testSyncWith() { final Integer[] x = new Integer[] {1, 2, 3}; final String[] y = new String[] {"1", "2", "4"}; final ArrayList<String> results = new ArrayList<>(); ArrayExtensions.syncWith( x, y, new Predicate2<Integer, String>() { @Override public boolean value_value_(Integer o, String n) { return o.toString().equals(n); } }, new Block2<Object, Integer, String>() { @Override public Object value_value_(Integer o, String n) { results.add("Then old:" + o + " new: " + n); return null; } }, new Block1<Object, String>() { @Override public Object value_(String n) { results.add("New: " + n); return null; } }, new Block1<Object, Integer>() { @Override public Object value_(Integer o) { results.add("Old: " + o); return null; } }); String[] resultArray = results.toArray(new String[results.size()]); assertTrue( ArrayExtensions.isSameAs_( resultArray, new String[] {"Then old:1 new: 1", "Then old:2 new: 2", "Old: 3", "New: 4"})); }
@Override public ClassNode withMethodNode_(final MethodNode _aMethodNode) { final MethodNode _current; _current = this.methodOrNilAt_(_aMethodNode.selector()); if (_current != null) { throw new RuntimeException("Duplicate selector: " + _aMethodNode.selector()); } return this.copy() .pvtSetMethods_(st.gravel.support.jvm.ArrayExtensions.copyWith_(_methods, _aMethodNode)); }
public JVMLocalDeclaration[] localsForSignature_(final JVMType[] _anArray) { return st.gravel.support.jvm.ArrayExtensions.keysAndValuesCollect_( _anArray, new st.gravel.support.jvm.Block2<JVMLocalDeclaration, Integer, JVMType>() { @Override public JVMLocalDeclaration value_value_(final Integer _i, final JVMType _type) { return (JVMLocalDeclaration) JVMLocalDeclaration.factory.varName_type_index_("arg" + "" + _i, _type, (_i - 1)); } }); }
@Override public Reference superclassReference() { final st.gravel.core.Symbol[] _path; if (_superclassPath == null) { return null; } _path = st.gravel.support.jvm.ArrayExtensions.collect_( st.gravel.support.jvm.StringExtensions.tokensBasedOn_(_superclassPath, '.'), ((st.gravel.support.jvm.Block1<st.gravel.core.Symbol, String>) (new st.gravel.support.jvm.Block1<st.gravel.core.Symbol, String>() { @Override public st.gravel.core.Symbol value_(final String _str) { return (st.gravel.core.Symbol) st.gravel.core.Symbol.value(_str); } }))); if (st.gravel.support.jvm.IntegerExtensions.equals_(_path.length, 1)) { return AbsoluteReference.factory.path_( st.gravel.support.jvm.ArrayExtensions.copyWith_(_namespace, _path[0])); } return AbsoluteReference.factory.path_(_path); }
public MethodNode[] mergeMethods_with_( final MethodNode[] _originalMethods, final MethodNode[] _extensionMethods) { final java.util.Set<String>[] _s; _s = new java.util.Set[1]; _s[0] = new java.util.HashSet(); for (final MethodNode _m : _originalMethods) { _s[0].add(_m.selector()); } for (final MethodNode _m : _extensionMethods) { if (_s[0].contains(_m.selector())) { throw new RuntimeException("Override: " + _m.selector()); } } return st.gravel.support.jvm.ArrayExtensions.copyWithAll_(_originalMethods, _extensionMethods); }
@Override public ClassNode copyRemoveSelector_(final String _selector) { return this.copy() .pvtSetMethods_( st.gravel.support.jvm.ArrayExtensions.reject_( _methods, new st.gravel.support.jvm.Predicate1<MethodNode>() { @Override public boolean value_(final MethodNode _each) { return st.gravel.support.jvm.StringExtensions.equals_( _each.selector(), _selector); } })); }
@Override public ClassNode withExtraMethods_(final MethodNode[] _extraMethods) { return st.gravel.support.jvm.ArrayExtensions.inject_into_( _extraMethods, this, ((st.gravel.support.jvm.Block2<ClassNode, ClassNode, MethodNode>) (new st.gravel.support.jvm.Block2<ClassNode, ClassNode, MethodNode>() { @Override public ClassNode value_value_(final ClassNode _cdn, final MethodNode _m) { if (_cdn.includesSelector_(_m.selector())) { return _cdn; } else { return _cdn.withMethodNode_(_m); } } }))); }
@Override public ClassNode copyReplaceMethodNode_(final MethodNode _aMethodNode) { return this.copy() .pvtSetMethods_( st.gravel.support.jvm.ArrayExtensions.collect_( _methods, ((st.gravel.support.jvm.Block1<MethodNode, MethodNode>) (new st.gravel.support.jvm.Block1<MethodNode, MethodNode>() { @Override public MethodNode value_(final MethodNode _each) { if (st.gravel.support.jvm.StringExtensions.equals_( _each.selector(), _aMethodNode.selector())) { return _aMethodNode; } else { return _each; } } })))); }
public st.gravel.core.Symbol[] javaClassPath() { final Object _temp1 = new Object(); try { final String _javaClass; _javaClass = ((String) st.gravel.support.jvm.DictionaryExtensions.at_ifAbsent_( _properties, "javaClass", ((st.gravel.support.jvm.Block0<String>) (new st.gravel.support.jvm.Block0<String>() { @Override public String value() { throw new NonLocalReturn(null, _temp1); } })))); return ((st.gravel.core.Symbol[]) st.gravel.support.jvm.ArrayExtensions.collect_( st.gravel.support.jvm.StringExtensions.tokensBasedOn_(_javaClass, '.'), ((st.gravel.support.jvm.Block1<st.gravel.core.Symbol, String>) (new st.gravel.support.jvm.Block1<st.gravel.core.Symbol, String>() { @Override public st.gravel.core.Symbol value_(final String _each) { return (st.gravel.core.Symbol) st.gravel.core.Symbol.value(_each); } })))); } catch (NonLocalReturn nlr) { if (nlr.marker == _temp1) { return (st.gravel.core.Symbol[]) nlr.returnValue; } else { throw nlr; } } }
@Override public ClassNode withInstVar_(final VariableDeclarationNode _aVariableDeclarationNode) { return this.copy() .pvtSetInstVars_( st.gravel.support.jvm.ArrayExtensions.copyWith_(_instVars, _aVariableDeclarationNode)); }
@Override public AbsoluteReference reference() { return AbsoluteReference.factory.path_( st.gravel.support.jvm.ArrayExtensions.copyWith_(_namespace, _name)); }
@Override public boolean equals(final Object _anObject) { if (!super.equals(_anObject)) { return false; } if (this._name == null) { if (!(((ClassNode) _anObject)._name == null)) { return false; } } else { if (!st.gravel.support.jvm.ObjectExtensions.equals_( this._name, ((ClassNode) _anObject)._name)) { return false; } } if (this._namespace == null) { if (!(((ClassNode) _anObject)._namespace == null)) { return false; } } else { if (!st.gravel.support.jvm.ArrayExtensions.equals_( this._namespace, ((ClassNode) _anObject)._namespace)) { return false; } } if (this._superclassPath == null) { if (!(((ClassNode) _anObject)._superclassPath == null)) { return false; } } else { if (!st.gravel.support.jvm.StringExtensions.equals_( this._superclassPath, ((ClassNode) _anObject)._superclassPath)) { return false; } } if (this._properties == null) { if (!(((ClassNode) _anObject)._properties == null)) { return false; } } else { if (!st.gravel.support.jvm.DictionaryExtensions.equals_( this._properties, ((ClassNode) _anObject)._properties)) { return false; } } if (!st.gravel.support.jvm.BooleanExtensions.equals_( this._isExtension, ((ClassNode) _anObject)._isExtension)) { return false; } if (this._metaclassNode == null) { if (!(((ClassNode) _anObject)._metaclassNode == null)) { return false; } } else { if (!st.gravel.support.jvm.ObjectExtensions.equals_( this._metaclassNode, ((ClassNode) _anObject)._metaclassNode)) { return false; } } if (!st.gravel.support.jvm.BooleanExtensions.equals_( this._isTrait, ((ClassNode) _anObject)._isTrait)) { return false; } return true; }