Project

General

Profile

3821c.4384g.patch

Marian Edu, 02/01/2021 08:26 AM

Download (779 KB)

View differences:

src/com/goldencode/p2j/oo/core/Assert.java 2020-10-23 13:00:35 +0000
12 12
**                  IsTrue.
13 13
** 003 IAS 20190923 Added implementation of additional methods
14 14
** 004 CA  20191024 Added method support levels and updated the class support level.
15
** 005 ME  20201023 Added implementation for isType, notType.
15 16
*/
16 17

  
17 18
/*
......
1008 1009
            final character _p2)
1009 1010
   {
1010 1011
      internalProcedure(Assert.class, "IsNull", new Block((Body) () -> {
1011
         AssertObject.isNull(_p1, new character("argument"));
1012
         AssertObject.isNull(_p1, _p2);
1012 1013
      }));
1013 1014
   }
1014 1015

  
......
1071 1072
   @LegacySignature(type = Type.METHOD, name = "IsPositive", parameters = {
1072 1073
            @LegacyParameter(name = "p1", type = "DECIMAL", mode = "INPUT"),
1073 1074
            @LegacyParameter(name = "p2", type = "CHARACTER", mode = "INPUT") })
1074
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_STUB)
1075
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
1075 1076
   public static void isPositive(final decimal _p1, final character _p2)
1076 1077
   {
1077 1078
      internalProcedure(Assert.class, "IsPositive", new Block((Body) () -> {
......
1174 1175
   @LegacySignature(type = Type.METHOD, name = "IsType", parameters = {
1175 1176
            @LegacyParameter(name = "p1", type = "HANDLE", mode = "INPUT"),
1176 1177
            @LegacyParameter(name = "p2", type = "OBJECT", qualified = "openedge.core.datatypeenum", mode = "INPUT") })
1177
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_STUB)
1178
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
1178 1179
   public static void isType(final handle _p1,
1179 1180
            final object<? extends com.goldencode.p2j.oo.core.DataTypeEnum> _p2)
1180 1181
   {
1181 1182
      ObjectOps.load(Assert.class);
1182 1183

  
1183
      handle p1 = TypeFactory.initInput(_p1);
1184
      object<? extends com.goldencode.p2j.oo.core.DataTypeEnum> p2 = TypeFactory.initInput(_p2);
1185

  
1186
      internalProcedure(Assert.class, "IsType", new Block());
1184
      internalProcedure(Assert.class, "IsType", new Block((Body) () -> {
1185
         AssertObject.isType(_p1, _p2, new character("argument"));
1186
      }));
1187 1187
   }
1188 1188

  
1189 1189
   @LegacySignature(type = Type.METHOD, name = "IsType", parameters = {
1190 1190
            @LegacyParameter(name = "p1", type = "HANDLE", mode = "INPUT"),
1191 1191
            @LegacyParameter(name = "p2", type = "OBJECT", qualified = "openedge.core.datatypeenum", mode = "INPUT"),
1192 1192
            @LegacyParameter(name = "p3", type = "CHARACTER", mode = "INPUT") })
1193
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_STUB)
1193
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
1194 1194
   public static void isType(final handle _p1,
1195 1195
            final object<? extends com.goldencode.p2j.oo.core.DataTypeEnum> _p2,
1196 1196
            final character _p3)
1197 1197
   {
1198 1198
      ObjectOps.load(Assert.class);
1199 1199

  
1200
      handle p1 = TypeFactory.initInput(_p1);
1201
      object<? extends com.goldencode.p2j.oo.core.DataTypeEnum> p2 = TypeFactory.initInput(_p2);
1202
      character p3 = TypeFactory.initInput(_p3);
1203

  
1204
      internalProcedure(Assert.class, "IsType", new Block());
1200
      internalProcedure(Assert.class, "IsType", new Block((Body) () -> {
1201
         AssertObject.isType(_p1, _p2, _p3);
1202
      }));
1205 1203
   }
1206 1204

  
1207 1205
   @LegacySignature(type = Type.METHOD, name = "IsType", parameters = {
......
1303 1301
   @LegacySignature(type = Type.METHOD, name = "IsZero", parameters = {
1304 1302
            @LegacyParameter(name = "p1", type = "INT64", mode = "INPUT"),
1305 1303
            @LegacyParameter(name = "p2", type = "CHARACTER", mode = "INPUT") })
1306
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_STUB)
1304
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
1307 1305
   public static void isZero(final int64 _p1, final character _p2)
1308 1306
   {
1309 1307
      ObjectOps.load(Assert.class);
......
2156 2154
   @LegacySignature(type = Type.METHOD, name = "NotNull", parameters = {
2157 2155
            @LegacyParameter(name = "p1", type = "HANDLE", mode = "INPUT"),
2158 2156
            @LegacyParameter(name = "p2", type = "CHARACTER", mode = "INPUT") })
2159
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_STUB)
2157
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
2160 2158
   public static void notNull(final handle _p1, final character _p2)
2161 2159
   {
2162 2160
      handle p1 = TypeFactory.initInput(_p1);
......
2474 2472
   @LegacySignature(type = Type.METHOD, name = "NotNullOrZero", parameters = {
2475 2473
            @LegacyParameter(name = "p1", type = "INTEGER", mode = "INPUT"),
2476 2474
            @LegacyParameter(name = "p2", type = "CHARACTER", mode = "INPUT") })
2477
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_STUB)
2475
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
2478 2476
   public static void notNullOrZero(final integer _p1, final character _p2)
2479 2477
   {
2480 2478
      internalProcedure(Assert.class, "NotNullOrZero", new Block((Body) () -> {
......
2525 2523
            @LegacyParameter(name = "p1", type = "HANDLE", mode = "INPUT"),
2526 2524
            @LegacyParameter(name = "p2", type = "OBJECT", qualified = "openedge.core.datatypeenum", mode = "INPUT"),
2527 2525
            @LegacyParameter(name = "p3", type = "CHARACTER", mode = "INPUT") })
2528
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_STUB)
2526
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
2529 2527
   public static void notType(final handle _p1,
2530 2528
            final object<? extends com.goldencode.p2j.oo.core.DataTypeEnum> _p2,
2531 2529
            final character _p3)
2532 2530
   {
2533
      handle p1 = TypeFactory.initInput(_p1);
2534
      object<? extends com.goldencode.p2j.oo.core.DataTypeEnum> p2 = TypeFactory.initInput(_p2);
2535
      character p3 = TypeFactory.initInput(_p3);
2536

  
2537
      internalProcedure(Assert.class, "NotType", new Block());
2531
      internalProcedure(Assert.class, "NotType", new Block((Body) () -> {
2532
         AssertObject.notType(_p1, _p2, _p3);
2533
      }));
2538 2534
   }
2539 2535

  
2540 2536
   @LegacySignature(type = Type.METHOD, name = "NotType", parameters = {
src/com/goldencode/p2j/oo/core/ByteBucket.java 2021-01-31 10:14:52 +0000
10 10
** 003 CA  20200313 Fixed a typo in putBytes_1 LegacySignature annotation.
11 11
** 004 GES 20200429 Shifted to new legacy enum approach.
12 12
** 005 ME  20200604 Rewrite to match the 4GL implementation.
13
**         20201019 Always write at the end regardless of position set, check max size
14
**         boundary (2G).          
13 15
** 006 CA  20210113 Renamed clear() to clear_(), to follow NameConverter's rules.
14 16
*/
15 17

  
......
79 81

  
80 82
import java.util.*;
81 83

  
82
import org.apache.commons.lang3.*;
83

  
84 84
/**
85 85
 * Business logic (converted to Java from the 4GL source code
86 86
 * in OpenEdge/Core/ByteBucket.cls).
......
100 100
   /** The current position */
101 101
   protected int64 position = TypeFactory.int64(0L);
102 102

  
103
   /** The current write position, putBytes always seems to write at the end regardless of position set **/
104
   private long writePosition = 0L;
105
   
103 106
   /** The bucket size (total number of bytes) */
104 107
   protected int64 size = TypeFactory.int64(0L);
105 108

  
106
   private integer initialNumRecs = TypeFactory.integer(3L);
107
   private int currentDataIndex;
108

  
109 109
   /** List of rows */
110
   protected LinkedList<BucketEntry> buckets = new LinkedList<>();
110
   protected LinkedList<byte[]> buckets = new LinkedList<>();
111 111

  
112 112
   /**
113 113
    * Execute method
......
176 176
   public int64 getSize()
177 177
   {
178 178
      return function(this, "Size", int64.class, new Block((Body) () -> {
179
         returnNormal(size);
179
         // make sure size is not unknown (destroy), $GL BUG probably not checking for valid object
180
         if (size.isUnknown()) 
181
         {
182
            ErrorManager.recordOrThrowError(3135, "Invalid handle. Not initialized or points to a deleted object");
183
         } 
184
         else 
185
         {
186
            returnNormal(size);
187
         }
180 188
      }));
181 189
   }
182 190

  
......
197 205
   public void __core_ByteBucket_constructor__()
198 206
   {
199 207
      internalProcedure(this, "__core_ByteBucket_constructor__", new Block((Body) () -> {
200
         __core_ByteBucket_constructor__(initialNumRecs);
208
         __core_ByteBucket_constructor__(new int64(0));
201 209
      }));
202 210
   }
203 211

  
204 212
   /**
205 213
    * Constructor.
206 214
    * 
207
    * @param _p1 the initial size of the memptrs that are held in the Bucket's array.
208
    */
209
   @LegacySignature(type = Type.CONSTRUCTOR, parameters = {
210
            @LegacyParameter(name = "p1", type = "INT64", mode = "INPUT") })
211
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
212
   public void __core_ByteBucket_constructor__(final int64 _p1)
213
   {
214
      // default capacity sent as input ignored on 4GL implementation, deprecated
215
      // since 11.7.0
216
      __core_ByteBucket_constructor__(initialNumRecs);
217
   }
218

  
219
   /**
220
    * Constructor.
221
    * 
222
    * @param _p1 the initial size of the memptrs that are held in the Bucket's array.
223
    */
224
   @LegacySignature(type = Type.CONSTRUCTOR, parameters = {
225
            @LegacyParameter(name = "p1", type = "INTEGER", mode = "INPUT") })
226
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
227
   public void __core_ByteBucket_constructor__(final integer _p1)
228
   {
229

  
230
      integer p1 = TypeFactory.initInput(_p1);
231

  
215
    * @param defaultCapacity the default capacity of the memptrs that are held in the Bucket's array.
216
    */
217
   @LegacySignature(type = Type.CONSTRUCTOR, parameters = {
218
            @LegacyParameter(name = "defaultCapacity", type = "INT64", mode = "INPUT") })
219
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
220
   public void __core_ByteBucket_constructor__(final int64 _defaultCapacity)
221
   {
222
      int64 defaultCapacity = TypeFactory.initInput(_defaultCapacity);
223
      
232 224
      internalProcedure(this, "__core_ByteBucket_constructor__", new Block((Body) () -> {
233 225
         __lang_BaseObject_constructor__();
234 226

  
235
         Assert.isPositive(p1, new character("Initial size"));
236

  
237
         position.assign(1);
238
         defaultCapacity.assign(MAX_BYTES_PER_ROW);
239
         initialNumRecs.assign(p1);
240
         currentDataIndex = 0;
227
         // just throw a 'matching' error for now until implementation is using the new MemoryOutputStream
228
         if (defaultCapacity.isUnknown() || defaultCapacity.longValue() < 0) {
229
            ErrorManager.recordOrThrowError(18193, "Invalid value specified for parameter 'value' of method or constructor 'Progress.IO.MemoryOutputStream'.");
230
         }
231
         
232
         if (defaultCapacity.longValue() != 0 ) {
233
            if (defaultCapacity.longValue() > Integer.MAX_VALUE ) {
234
               ErrorManager.recordOrThrowError(0, "The initial stream size cannot be greater than 2GB");
235
            }
236
            
237
            // pre-allocate memory???
238
            for (int i = 0; i < (int) (defaultCapacity.longValue() / MAX_BYTES_PER_ROW); i++)
239
            {
240
               buckets.add(new byte[MAX_BYTES_PER_ROW]);
241
            }
242
         }
243
         
244
         this.defaultCapacity.assign(defaultCapacity);
245
         this.position.assign(1);
246
      }));
247
      
248
      
249
   }
250

  
251
   /**
252
    * Constructor.
253
    * 
254
    * @param initialSize the initial size of the memptrs that are held in the Bucket's array.
255
    */
256
   @LegacySignature(type = Type.CONSTRUCTOR, parameters = {
257
            @LegacyParameter(name = "initialSize", type = "INTEGER", mode = "INPUT") })
258
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
259
   public void __core_ByteBucket_constructor__(final integer _initialSize)
260
   {
261

  
262
      integer initialSize = TypeFactory.initInput(_initialSize);
263

  
264
      internalProcedure(this, "__core_ByteBucket_constructor__", new Block((Body) () -> {
265
         __core_ByteBucket_constructor__();
266

  
267
         Assert.isPositive(initialSize, new character("Initial size"));
241 268
      }));
242 269
   }
243 270

  
......
248 275
    * @param _p2 the initial number of buckets (not used in  the current implementation).
249 276
    */
250 277
   @LegacySignature(type = Type.CONSTRUCTOR, parameters = {
251
            @LegacyParameter(name = "p1", type = "INTEGER", mode = "INPUT"),
252
            @LegacyParameter(name = "p2", type = "INT64", mode = "INPUT") })
278
            @LegacyParameter(name = "initialSize", type = "INTEGER", mode = "INPUT"),
279
            @LegacyParameter(name = "defaultCapacity", type = "INT64", mode = "INPUT") })
253 280
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
254
   public void __core_ByteBucket_constructor__(final integer p1, final int64 p2)
281
   public void __core_ByteBucket_constructor__(final integer initialSize, final int64 defaultCapacity)
255 282
   {
256 283
      // default capacity input parameter ignored on 4GL, deprecated since 11.7.0
257
      __core_ByteBucket_constructor__(p1);
284
      // in OE12.2 initial size (number of rows) is not used anymore but default capacity (bytes) is used instead 
285
      __core_ByteBucket_constructor__(defaultCapacity);
258 286
   }
259 287

  
260 288
   /**
......
280 308
      internalProcedure(this, "Clear", new Block((Body) () -> {
281 309
         this.position.assign(1);
282 310
         this.size.assign(0);
283
         currentDataIndex = 0;
284

  
285
         for (BucketEntry bucket : buckets)
286
         {
287
            bucket.bytesWritten = 0;
288
         }
289 311
      }));
290 312
   }
291 313

  
292 314
   /**
293
    * Debug method to dump out current RAW bytes into numbered files. 
294
    * Files are named bytebucket-memptr-&lt;number&gt;.bin 
315
    * Debug method to dump out current RAW bytes into a file. 
316
    * The file is saved in session temporary folder as "bytebucket-memptr-&lt;object_id&gt;.bin" 
295 317
    */
296 318
   @LegacySignature(type = Type.METHOD, name = "Debug")
297
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_STUB)
319
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
298 320
   public void debug()
299 321
   {
300 322
      internalProcedure(this, "Debug", new Block((Body) () -> {
301 323

  
302
         String folderPath = EnvironmentOps.getTempDirectory().getValue();
303
         character fullPath = TypeFactory.character();
304

  
305
         for (int i = 0; i < buckets.size(); i++)
306
         {
307
            BucketEntry bucket = buckets.get(i);
308

  
309
            memptr ptr = new memptr(Arrays.copyOf(bucket.data, bucket.bytesWritten));
310
            fullPath.assign(String.format("%sbytebucket-memptr-%d.bin", folderPath, i + 1));
311

  
312
            try
313
            {
314
               new LobCopy(new SourceLob(ptr), new TargetLobFile(fullPath)).run();
315
            }
316
            finally
317
            {
318
               ptr.setLength(0);
319
            }
320
         }
321

  
324
         String debugPath = String.format("%sbytebucket-memptr-%d.bin", 
325
                  EnvironmentOps.getTempDirectory().getValue(), 
326
                  handle.resourceId(ObjectOps.asResource(this)));
327
         memptr ptr = getBytes().ref().getValue();
328
         
329
         try
330
         {
331
            new LobCopy(new SourceLob(ptr), new TargetLobFile(debugPath)).run();
332
         }
333
         finally
334
         {
335
            ptr.setLength(0);
336
         }
337
         
322 338
      }));
323 339
   }
324 340

  
......
332 348
   {
333 349
      internalProcedure(this, "Destroy", new Block((Body) () -> {
334 350
         this.position.assign(1);
335
         this.size.assign(0);
336
         currentDataIndex = 0;
351
         this.size.setUnknown();
337 352

  
338 353
         buckets.clear();
339 354
      }));
......
373 388
      int64 p = TypeFactory.initInput(_pos);
374 389

  
375 390
      return function(this, "GetByte", integer.class, new Block((Body) () -> {
376
         Assert.isPositive(p, new character("Start position"));
377
         long pos = p.longValue();
378

  
379
         int nbucket = (int) ((pos - 1) / defaultCapacity.longValue());
380
         int offset = (int) ((pos - 1) % defaultCapacity.longValue());
381

  
382
         if (nbucket < buckets.size())
383
         {
384
            BucketEntry bucket = buckets.get(nbucket);
385

  
386
            if (offset < bucket.bytesWritten)
387
               returnNormal(new integer(bucket.data[offset]));
388

  
389
            // data in 4GL blob field is truncated, read pass length returns unknown
390
            returnNormal(new integer());
391
         if (!p.isUnknown()) {
392
            long pos = p.longValue();
393
            
394
            if (pos < 1) 
395
            {
396
               BinaryData.genIndexError();
397
            }
398
            else if (pos <= size.longValue()) 
399
            {
400
               int nbucket = (int) ((pos - 1) / MAX_BYTES_PER_ROW);
401
               int offset = (int) ((pos - 1) % MAX_BYTES_PER_ROW);
402
      
403
               if (nbucket < buckets.size())
404
               {
405
                  byte[] bucket = buckets.get(nbucket);
406
      
407
                  returnNormal(new integer(bucket[offset] & 0xFF));
408
               }
409
            }
391 410
         }
392

  
411
         
393 412
         returnNormal(new integer(0));
394 413
      }));
395 414
   }
......
441 460
      int64 size = TypeFactory.initInput(_size);
442 461

  
443 462
      return function(this, "GetBytes", object.class, new Block((Body) () -> {
444
         if (CompareOps._isEqual(size, 0) || CompareOps._isEqual(getSize(), 0))
463
         if (getSize().longValue() == 0 || size.longValue() == 0)
445 464
         {
446 465
            returnNormal(Memptr.getEmpty());
447 466
         }
......
507 526
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
508 527
   public longchar getString()
509 528
   {
510
      return getString(new int64(1), this.size);
529
      return getString(new int64(1), this.getSize());
511 530
   }
512 531

  
513 532
   /**
......
593 612
         Assert.isPositive(pos, new character("Start position"));
594 613
         Assert.isZeroOrPositive(size, new character("Slice size"));
595 614

  
596
         if (StringUtils.isBlank(targetCP.getValue()))
615
         if (TextOps.isEmpty(targetCP))
597 616
            targetCP.assign("UTF-8");
598 617

  
599 618
         longchar lc = TypeFactory.longchar();
......
604 623
            returnNormal(lc);
605 624
         }
606 625

  
607
         if (StringUtils.isBlank(sourceCP.getValue()))
626
         if (TextOps.isEmpty(sourceCP))
608 627
            sourceCP.assign("UTF-8");
609 628

  
610 629
         memptr ptr = TypeFactory.memptr();
......
639 658
   {
640 659
      internalProcedure(this, "Initialize", new Block((Body) () -> {
641 660
         clear_();
642
         resize(initialNumRecs);
643 661
      }));
644 662
   }
645 663

  
......
673 691
   public static object<? extends ByteBucket> instance(final int64 _p1)
674 692
   {
675 693
      int64 p1 = TypeFactory.initInput(_p1);
676
      ObjectOps.load(ByteBucket.class);
677 694
      return function(ByteBucket.class, "Instance", object.class, new Block((Body) () -> {
678 695
         object<? extends ByteBucket> bb = ObjectOps.newInstance(ByteBucket.class, "I", p1);
679 696
         bb.ref().initialize();
......
697 714
   {
698 715
      integer p1 = TypeFactory.initInput(_p1);
699 716
      int64 p2 = TypeFactory.initInput(_p2);
700
      ObjectOps.load(ByteBucket.class);
701 717
      return function(ByteBucket.class, "Instance", object.class, new Block((Body) () -> {
702
         Assert.isPositive(p1, new character("Initial size"));
703 718
         object<? extends ByteBucket> bb = ObjectOps.newInstance(ByteBucket.class, "II", p1, p2);
704 719
         bb.ref().initialize();
705 720
         returnNormal(bb);
706 721
      }));
707 722
   }
708 723

  
709
   private static void mergeBuckets(final ByteBucket source, final ByteBucket target)
710
   {
711
      int total = source.getSize().intValue();
712

  
713
      if (total == 0)
714
      {
715
         return;
716
      }
717

  
718
      source.buckets.stream().filter(b -> b.bytesWritten > 0)
719
               .forEachOrdered(b -> target.writeBytes(b.data, b.bytesWritten));
720

  
721
   }
722

  
723 724
   /**
724 725
    * Copies all of the bytes from a ByteBucket instance into this bucket.
725 726
    * 
......
728 729
   @LegacySignature(type = Type.METHOD, name = "PutBytes", parameters = {
729 730
            @LegacyParameter(name = "data", type = "OBJECT", qualified = "openedge.core.bytebucket", mode = "INPUT") })
730 731
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
731
   public void putBytes(final object<? extends ByteBucket> data)
732
   public void putBytes(final object<? extends ByteBucket> _data)
732 733
   {
734
      object<? extends ByteBucket> data = TypeFactory.initInput(_data);
735

  
733 736
      internalProcedure(this, "PutBytes", new Block((Body) () -> {
734 737
         Assert.notNull(data, new character("Input data"));
735 738

  
736
         if (data.getSize() > 0)
739
         ByteBucket bbucket = data.ref();
740
         long size = bbucket.getSize().longValue();
741

  
742
         if (size > 0)
737 743
         {
738
            mergeBuckets(data.ref(), this);
744
            int endBucket = (int) (size / MAX_BYTES_PER_ROW);
745
            int endOffset = (int) (size % MAX_BYTES_PER_ROW);
746

  
747
            for (int i = 0; i <= endBucket; i++)
748
            {
749
               byte[] bucket = bbucket.buckets.get(i);
750

  
751
               writeBytes(bucket, i < endBucket ? MAX_BYTES_PER_ROW : endOffset);
752
            }
739 753
         }
740 754
      }));
741 755
   }
......
866 880
      character targetCP = TypeFactory.initInput(_targetCP);
867 881

  
868 882
      internalProcedure(this, "PutString", new Block((Body) () -> {
869
         if (!data.isUnknown() && StringUtils.isEmpty(data.getValue()))
883
         if (TextOps.isEmpty(data))
870 884
            return;
871 885

  
872
         if (targetCP.isUnknown() || StringUtils.isEmpty(targetCP.getValue()))
886
         if (TextOps.isEmpty(targetCP))
873 887
         {
874 888
            targetCP.assign("UTF-8");
875 889
         }
......
916 930
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
917 931
   public void resize(final integer _p1)
918 932
   {
919
      integer psize = TypeFactory.initInput(_p1);
920

  
921
      internalProcedure(this, "Resize", new Block((Body) () -> {
922
         if (!psize.isUnknown())
923
         {
924
            if (psize.intValue() > currentDataIndex)
925
            {
926
               for (int i = currentDataIndex + 1; i < psize.intValue(); i++)
927
               {
928
                  if (buckets.size() < i)
929
                  {
930
                     buckets.add(new BucketEntry());
931
                  }
932
               }
933
               
934
            }
935
            else if (!defaultCapacity.isUnknown())
936
            {
937

  
938
               while (buckets.size() > Math.ceil(psize.longValue() / defaultCapacity.longValue()))
939
               {
940
                  BucketEntry bucket = buckets.getLast();
941

  
942
                  if (bucket.bytesWritten != 0)
943
                     break;
944

  
945
                  buckets.remove(bucket);
946
               }
947
            }
948
         }
949

  
950
         currentDataIndex = psize.isUnknown() ? 0 : psize.intValue() - 1;
951
      }));
933
      // no-op in OE12.2
952 934
   }
953 935

  
954 936
   /**
......
962 944
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
963 945
   public void resizeArray(final integer _p1)
964 946
   {
965
      integer p1 = TypeFactory.initInput(_p1);
966

  
967
      internalProcedure(this, "ResizeArray", new Block((Body) () -> {
968
         resize(p1);
969
      }));
947
      // no-op in oe12.2
970 948
   }
971 949

  
972 950
   /**
......
984 962
      long pos = p.longValue();
985 963
      long bytesLeft = data.lengthOf();
986 964
      int putAt = 0;
987
      int nbucket = (int) ((pos - 1) / defaultCapacity.longValue());
988
      int offset = (int) ((pos - 1) % defaultCapacity.longValue());
965
      int nbucket = (int) ((pos - 1) / MAX_BYTES_PER_ROW);
966
      int offset = (int) ((pos - 1) % MAX_BYTES_PER_ROW);
967
      int endBucket = (int) ((size.longValue()) / MAX_BYTES_PER_ROW);
968
      int endOffset = (int) ((size.longValue()) % MAX_BYTES_PER_ROW);
969
      
989 970

  
990
      for (int i = nbucket; i <= currentDataIndex; i++)
971
      for (int i = nbucket; i <= endBucket; i++)
991 972
      {
992
         BucketEntry bucket = buckets.get(i);
993
         int numBytes = (int) Math.min(bucket.bytesWritten - offset, bytesLeft);
973
         byte[] bucket = buckets.get(i);
974
         int numBytes = (int) Math.min((i == endBucket ? endOffset : MAX_BYTES_PER_ROW) - offset, bytesLeft);
994 975

  
995 976
         if (numBytes > 0)
996 977
         {
997
            data.write(true, Arrays.copyOfRange(bucket.data, offset, offset + numBytes), putAt,
978
            data.write(true, Arrays.copyOfRange(bucket, offset, offset + numBytes), putAt,
998 979
                     false);
999 980

  
1000 981
            offset = 0;
......
1017 998
   {
1018 999

  
1019 1000
      long bytesLeft = ptr.lengthOf();
1020
      long startPos = 0;
1001
      long bytesWritten = 0;
1021 1002

  
1022
      while (bytesLeft > 0)
1003
      while (bytesLeft > bytesWritten)
1023 1004
      {
1024 1005
         long numBytes = Math.min(bytesLeft, Integer.MAX_VALUE);
1025 1006

  
1026
         writeBytes(ptr.asByteArray(startPos, numBytes), (int) numBytes);
1027
         startPos += numBytes;
1028
         bytesLeft -= numBytes;
1007
         numBytes = writeBytes(ptr.asByteArray(bytesWritten, numBytes), (int) numBytes);
1008
         bytesWritten += numBytes;
1029 1009
      }
1010
      
1011
      this.position.assign(this.position.longValue() + bytesWritten);
1030 1012
   }
1031 1013

  
1032
   private void writeBytes(byte[] data, int len)
1014
   /**
1015
    * Write the content of byte array.
1016
    * 
1017
    * The method updates the size but not the position because putBytes form ByteBucket does not 
1018
    * change the current position.
1019
    * 
1020
    * @param data the byte array data
1021
    * @param len  the length of data to write
1022
    * 
1023
    * @return the number of bytes written 
1024
    */
1025
   private int writeBytes(byte[] data, int len)
1033 1026
   {
1034 1027

  
1035 1028
      int bytesLeft = Math.min(data.length, len);
1036
      int startPos = 0;
1037

  
1038
      while (bytesLeft > 0)
1039
      {
1040
         BucketEntry bucket;
1041

  
1042
         if (buckets.size() > currentDataIndex)
1043
         {
1044
            bucket = buckets.get(currentDataIndex);
1045
         }
1046
         else
1047
         {
1048
            bucket = new BucketEntry();
1049
            buckets.add(bucket);
1050
         }
1051

  
1052
         int numBytes = Math.min(MAX_BYTES_PER_ROW - bucket.bytesWritten, bytesLeft);
1053
         bytesLeft -= numBytes;
1054

  
1055
         if (numBytes > 0)
1056
         {
1057
            System.arraycopy(data, startPos, bucket.data, bucket.bytesWritten, numBytes);
1058
            bucket.bytesWritten += numBytes;
1059
            startPos += numBytes;
1060
            position.assign(this.position.longValue() + numBytes);
1061
            size.assign(this.size.longValue() + numBytes);
1062
         }
1063

  
1064
         if (bucket.bytesWritten == MAX_BYTES_PER_ROW)
1065
         {
1066
            currentDataIndex++;
1067
         }
1068
      }
1069
   }
1070

  
1071
   private static class BucketEntry
1072
   {
1073
      public byte[] data;
1074
      public int bytesWritten;
1075

  
1076
      BucketEntry()
1077
      {
1078
         data = new byte[MAX_BYTES_PER_ROW];
1079
         bytesWritten = 0;
1080

  
1081
      }
1082
   }
1029
      int bytesWritten = 0;
1030
      int crtBucket = (int) (writePosition / MAX_BYTES_PER_ROW);
1031
      int endBucket = (int) ((size.longValue()) / MAX_BYTES_PER_ROW);
1032
      int endOffset = (int) ((size.longValue()) % MAX_BYTES_PER_ROW);
1033

  
1034
      if (writePosition + bytesLeft > Integer.MAX_VALUE)
1035
      {
1036
         ErrorManager.recordOrThrowError(0,
1037
                  "Cannot expand memory allocation because it exceeds the limit", false);
1038
         return 0;
1039

  
1040
      }
1041
      else
1042
      {
1043

  
1044
         while (bytesLeft > 0)
1045
         {
1046
            byte[] bucket;
1047

  
1048
            if (buckets.size() > crtBucket)
1049
            {
1050
               bucket = buckets.get(crtBucket);
1051
            }
1052
            else
1053
            {
1054
               bucket = new byte[MAX_BYTES_PER_ROW];
1055
               buckets.add(bucket);
1056
            }
1057

  
1058
            int pos = crtBucket == endBucket ? endOffset : 0;
1059
            int numBytes = Math.min(MAX_BYTES_PER_ROW - pos, bytesLeft);
1060

  
1061
            bytesLeft -= numBytes;
1062

  
1063
            if (numBytes > 0)
1064
            {
1065
               System.arraycopy(data, bytesWritten, bucket, pos, numBytes);
1066
               bytesWritten += numBytes;
1067
            }
1068

  
1069
            crtBucket++;
1070
         }
1071

  
1072
         writePosition += bytesWritten;
1073
         size.assign(this.size.longValue() + bytesWritten);
1074

  
1075
         return bytesWritten;
1076
      }
1077
   }
1078
   
1083 1079
}
src/com/goldencode/p2j/oo/core/assertion/AssertObject.java 2020-10-23 13:00:35 +0000
8 8
** -#- -I- --Date-- -------------------------------Description--------------------------------
9 9
** 001 ME  20200324 Created the first version, by converting the legacy skeleton .cls file and
10 10
**                  using that output.
11
** 002 ME  20201023 Added implementation for isType, notType.
11 12
*/
12 13

  
13 14
/*
......
564 565
            @LegacyParameter(name = "p1", type = "HANDLE", mode = "INPUT"),
565 566
            @LegacyParameter(name = "p2", type = "OBJECT", qualified = "openedge.core.datatypeenum", mode = "INPUT"),
566 567
            @LegacyParameter(name = "p3", type = "CHARACTER", mode = "INPUT") })
567
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_STUB)
568
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
568 569
   public static void isType(final handle _p1,
569 570
            final object<? extends com.goldencode.p2j.oo.core.DataTypeEnum> _p2,
570 571
            final character _p3)
......
574 575
      object<? extends com.goldencode.p2j.oo.core.DataTypeEnum> p2 = TypeFactory.initInput(_p2);
575 576
      character p3 = TypeFactory.initInput(_p3);
576 577

  
577
      internalProcedure(AssertObject.class, "IsType", new Block());
578
      internalProcedure(AssertObject.class, "IsType", new Block((Body) () -> {
579
         Assert.notNull(p1, p3);
580
         notNull(p2, new character("Check DataType"));
581
         
582
         if (!p1.isType(p2.ref().toLegacyString().getValue()))
583
            returnError(ObjectOps.newInstance(AssertionFailedError.class, "II",
584
                     substitute("&1 is not of type &2", p3, p2), 0));
585
      }));
578 586
   }
579 587

  
580 588
   @LegacySignature(type = Type.METHOD, name = "IsType", parameters = {
......
593 601
            @LegacyParameter(name = "p1", type = "HANDLE", mode = "INPUT"),
594 602
            @LegacyParameter(name = "p2", type = "OBJECT", qualified = "openedge.core.datatypeenum", mode = "INPUT"),
595 603
            @LegacyParameter(name = "p3", type = "CHARACTER", mode = "INPUT") })
596
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_STUB)
604
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
597 605
   public static void notType(final handle _p1,
598 606
            final object<? extends com.goldencode.p2j.oo.core.DataTypeEnum> _p2,
599 607
            final character _p3)
......
603 611
      object<? extends com.goldencode.p2j.oo.core.DataTypeEnum> p2 = TypeFactory.initInput(_p2);
604 612
      character p3 = TypeFactory.initInput(_p3);
605 613

  
606
      internalProcedure(AssertObject.class, "NotType", new Block());
614
      internalProcedure(AssertObject.class, "NotType", new Block((Body) () -> {
615
         Assert.notNull(p1, p3);
616
         notNull(p2, new character("Check DataType"));
617
         
618
         if (p1.isType(p2.ref().toLegacyString().getValue()))
619
            returnError(ObjectOps.newInstance(AssertionFailedError.class, "II",
620
                     substitute("&1 cannot be of type &2", p3, p2), 0));
621
      }));
607 622
   }
608 623

  
609 624
   @LegacySignature(type = Type.METHOD, name = "NotType", parameters = {
......
681 696

  
682 697
   @LegacySignature(type = Type.METHOD, name = "IsSerializable", parameters = {
683 698
            @LegacyParameter(name = "p1", type = "OBJECT", qualified = "progress.lang.object", mode = "INPUT") })
684
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_STUB)
699
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
685 700
   public static void isSerializable(
686 701
            final object<? extends com.goldencode.p2j.oo.lang._BaseObject_> _p1)
687 702
   {
688 703
      ObjectOps.load(AssertObject.class);
689 704
      object<? extends com.goldencode.p2j.oo.lang._BaseObject_> p1 = TypeFactory.initInput(_p1);
690 705

  
691
      internalProcedure(AssertObject.class, "IsSerializable", new Block());
692
      // TODO: add serializable in progress.lang.class (LegacyClass)
706
      internalProcedure(AssertObject.class, "IsSerializable", new Block((Body) () -> {
707
         Assert.notNull(p1, new character("argument"));
708
         
709
         object<? extends LegacyClass> cls = LegacyClass.getLegacyClass(p1);
710
         
711
         if (!cls.ref().isSerializable().booleanValue())
712
            returnError(ObjectOps.newInstance(AssertionFailedError.class, "II",
713
                     substitute("Object &1 (of type &2) is not serializable", p1.ref().toLegacyString(), cls.ref().getTypeName()), 0));
714
      }));
693 715
   }
694 716

  
695 717
   @LegacySignature(type = Type.METHOD, name = "NotSerializable", parameters = {
696 718
            @LegacyParameter(name = "p1", type = "OBJECT", qualified = "progress.lang.object", mode = "INPUT") })
697
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_STUB)
719
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
698 720
   public static void notSerializable(
699 721
            final object<? extends com.goldencode.p2j.oo.lang._BaseObject_> _p1)
700 722
   {
701 723
      ObjectOps.load(AssertObject.class);
702 724
      object<? extends com.goldencode.p2j.oo.lang._BaseObject_> p1 = TypeFactory.initInput(_p1);
703 725

  
704
      internalProcedure(AssertObject.class, "NotSerializable", new Block());
705
      // TODO: add serializable in progress.lang.class (LegacyClass)
726
      internalProcedure(AssertObject.class, "NotSerializable", new Block((Body) () -> {
727
         Assert.notNull(p1, new character("argument"));
728
         
729
         object<? extends LegacyClass> cls = LegacyClass.getLegacyClass(p1);
730
         
731
         if (cls.ref().isSerializable().booleanValue())
732
            returnError(ObjectOps.newInstance(AssertionFailedError.class, "II",
733
                     substitute("Object &1 (of type &2) is serializable", p1.ref().toLegacyString(), cls.ref().getTypeName()), 0));
734
      }));
706 735
   }
707 736

  
708 737
}
src/com/goldencode/p2j/oo/core/collections/AbstractTtcollection.java 2021-01-31 10:14:52 +0000
8 8
** 001 ME  20200514 First version, stubs taken by converting the skeleton using FWD.
9 9
** 002 CA  20210113 Renamed Iiterator.next to Iiterator.next_, to follow NameConverter's rules.
10 10
**         20210113 Renamed clear() to clear_(), to follow NameConverter's rules.
11
** 003 ME  20210128 Keep only the default 4GL temp-table implementation.
11 12
*/
12 13

  
13 14
/*
......
68 69
import com.goldencode.p2j.util.BlockManager.Action;
69 70
import com.goldencode.p2j.util.BlockManager.Condition;
70 71

  
71
import edu.emory.mathcs.backport.java.util.Arrays;
72

  
73 72
import com.goldencode.p2j.oo.core.Assert;
74 73
import com.goldencode.p2j.oo.core.collections.Icollection;
75 74
import com.goldencode.p2j.oo.lang.*;
......
79 78
import static com.goldencode.p2j.util.BlockManager.*;
80 79
import static com.goldencode.p2j.util.InternalEntry.Type;
81 80

  
82
import java.util.ArrayList;
83
import java.util.Collection;
84
import java.util.Collections;
85

  
86 81
/**
87 82
 * Business logic (converted to Java from the 4GL source code
88 83
 * in OpenEdge/Core/Collections/AbstractTTCollection.cls).
......
98 93
   private handle fieldHandle = TypeFactory.handle();
99 94
   private handle queryHandle = TypeFactory.handle();
100 95

  
101
   private Collection<object<? extends _BaseObject_>> objects;
102

  
103 96
   public void __core_collections_AbstractTtcollection_execute__()
104 97
   {
105 98
      externalProcedure(AbstractTtcollection.class, AbstractTtcollection.this,
......
113 106
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
114 107
   public integer getSize()
115 108
   {
116
      return function(AbstractTtcollection.class, this, "Size", integer.class,
117
               new Block((Body) () ->
118
               {
119
                  returnNormal(size);
120
               }));
109
      return function(this, "Size", integer.class, new Block((Body) () -> {
110
         returnNormal(size);
111
      }));
121 112
   }
122 113

  
123 114
   @LegacySignature(type = Type.CONSTRUCTOR)
......
128 119
               "__core_collections_AbstractTtcollection_constructor__", new Block((Body) () ->
129 120
               {
130 121
                  __lang_BaseObject_constructor__();
131
                  // use a java collection by default
132
                  objects = new ArrayList<object<? extends _BaseObject_>>();
133 122
               }));
134 123
   }
135 124

  
......
157 146
            final character _p2)
158 147
   {
159 148
      internalProcedure(AbstractTtcollection.class, this,
160
               "__core_collections_AbstractTtcollection_constructor__", new Block((Body) () ->
161
               {
162
                  __core_collections_AbstractTtcollection_constructor__(_p1,
163
                           _p1.isType(LegacyResource.TEMP_TABLE)
164
                                    ? _p1.unwrapTempTable().defaultBufferHandle().unwrapBuffer()
165
                                             .bufferField(_p2)
166
                                    : new handle());
149
               "__core_collections_AbstractTtcollection_constructor__", new Block((Body) () -> {
150
                  __core_collections_AbstractTtcollection_constructor__(_p1, _p1.unwrapTempTable()
151
                           .defaultBufferHandle().unwrapBuffer().bufferField(_p2));
167 152
               }));
168 153
   }
169 154

  
......
183 168
                  __lang_BaseObject_constructor__();
184 169
                  size.assign(0);
185 170

  
186
                  // default 4GL temp-table implementation
187
                  if (p1.isType(LegacyResource.TEMP_TABLE))
188
                  {
189
                     tableHandle.assign(p1);
190
                     fieldHandle.assign(p2);
191
                     objects = Collections.EMPTY_LIST;
192
                  }
193
                  // java map implementation
194
                  else
195
                  {
196
                     objects = new ArrayList<object<? extends _BaseObject_>>();
197
                  }
171
                  tableHandle.assign(p1.unwrapTempTable());
172
                  fieldHandle.assign(p2);
198 173
               }));
199 174
   }
200 175

  
......
217 192
   {
218 193
      object<? extends _BaseObject_> p1 = TypeFactory.initInput(_p1);
219 194

  
220
      return function(AbstractTtcollection.class, this, "Add", logical.class,
221
               new Block((Body) () ->
222
               {
223
                  boolean result = false;
224

  
225
                  if (p1._isValid())
226
                  {
227
                     if (objects == Collections.EMPTY_LIST)
228
                     {
229
                        Buffer buffer = tableHandle.unwrapTempTable().defaultBufferHandle()
230
                                 .unwrapBuffer();
231
                        buffer.bufferCreate();
232
                        fieldHandle.unwrapBufferField().changeValue(p1);
233
                        buffer.bufferRelease();
234

  
235
                        result = true;
236
                     }
237
                     else
238
                     {
239
                        result = objects.add(p1);
240
                     }
241
                  }
242

  
243
                  if (result)
244
                     size.assign(size.intValue() + 1);
245

  
246
                  returnNormal(result);
247

  
248
               }));
195
      return function(this, "Add", logical.class, new Block((Body) () -> {
196

  
197
         if (p1._isValid())
198
         {
199
               Buffer buffer = tableHandle.unwrapTempTable().defaultBufferHandle().unwrapBuffer();
200
               buffer.bufferCreate();
201
               fieldHandle.unwrapBufferField().changeValue(p1);
202
               buffer.bufferRelease();
203

  
204
               size.assign(size.intValue() + 1);
205
               
206
               returnNormal(true);
207
         }
208

  
209
         returnNormal(false);
210

  
211
      }));
249 212
   }
250 213

  
251 214
   @LegacySignature(type = Type.METHOD, name = "AddArray", parameters = {
......
253 216
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
254 217
   public logical addArray(final object<? extends _BaseObject_>[] _p1)
255 218
   {
256
      object<? extends _BaseObject_>[] p1[] = new object[][] { TypeFactory.initInput(_p1) };
257

  
258
      return function(AbstractTtcollection.class, this, "AddArray", logical.class,
259
               new Block((Body) () ->
260
               {
261
                  if (p1[0].length > 0)
262
                  {
263
                     if (objects == Collections.EMPTY_LIST)
264
                     {
265
                        for (int i = 0; i < p1.length; i++)
266
                        {
267
                           add(p1[0][i]);
268
                        }
269
                     }
270
                     else
271
                     {
272
                        objects.addAll(Arrays.asList(p1[0]));
273

  
274
                        size.assign(size.intValue() + p1[0].length);
275
                     }
276
                  }
277

  
278
                  returnNormal(true);
279
               }));
219
      object<? extends _BaseObject_> p1[] = TypeFactory.initInput(_p1);
220

  
221
      return function(this, "AddArray", logical.class, new Block((Body) () -> {
222
         if (p1.length > 0)
223
         {
224
            for (int i = 0; i < p1.length; i++)
225
            {
226
               add(p1[i]);
227
            }
228
         }
229

  
230
         returnNormal(true);
231
      }));
280 232
   }
281 233

  
282 234
   @LegacySignature(type = Type.METHOD, name = "AddAll", parameters = {
......
286 238
   {
287 239
      object<? extends Icollection> p1 = TypeFactory.initInput(_p1);
288 240

  
289
      return function(AbstractTtcollection.class, this, "AddAll", logical.class,
290
               new Block((Body) () ->
291
               {
292
                  if (objects == Collections.EMPTY_LIST && getLegacyClass().ref()
293
                           .legacyEquals(p1.ref().getLegacyClass()).booleanValue())
294
                  {
295
                     p1.ref().toTable(new TableParameter(tableHandle, true));
296
                     size.assign(size.intValue() + p1.ref().getSize().intValue());
297
                  }
298
                  else
299
                  {
300
                     Iiterator it = p1.ref().iterator().ref();
301

  
302
                     while (it.hasNext().booleanValue())
303
                     {
304
                        add(it.next_());
305
                     }
306
                  }
307

  
308
                  returnNormal(true);
309
               }));
241
      return function(this, "AddAll", logical.class, new Block((Body) () -> {
242
         if (getLegacyClass().ref()
243
                  .legacyEquals(p1.ref().getLegacyClass()).booleanValue())
244
         {
245
            p1.ref().toTable(new TableParameter(tableHandle, true));
246
            size.assign(size.intValue() + p1.ref().getSize().intValue());
247
         }
248
         else
249
         {
250
            Iiterator it = p1.ref().iterator().ref();
251

  
252
            while (it.hasNext().booleanValue())
253
            {
254
               add(it.next_());
255
            }
256
         }
257

  
258
         returnNormal(true);
259
      }));
310 260
   }
311 261

  
312 262
   @LegacySignature(type = Type.METHOD, name = "Clear")
......
315 265
   {
316 266
      internalProcedure(AbstractTtcollection.class, this, "Clear", new Block((Body) () ->
317 267
      {
318
         if (objects == Collections.EMPTY_LIST)
319
         {
320
            tableHandle.unwrapTempTable().deleteAll();
321
         }
322
         else
323
         {
324
            objects.clear();
325
         }
326

  
268
         tableHandle.unwrapTempTable().deleteAll();
327 269
         size.assign(0);
328 270
      }));
329 271
   }
......
335 277
   {
336 278
      object<? extends _BaseObject_> p1 = TypeFactory.initInput(_p1);
337 279

  
338
      return function(AbstractTtcollection.class, this, "Contains", logical.class,
339
               new Block((Body) () ->
340
               {
341
                  if (objects == Collections.EMPTY_LIST)
342
                  {
343
                     findBufferUseObject(p1);
344
                     returnNormal(tableHandle.unwrapTempTable().defaultBufferHandle()
345
                              .unwrapBuffer().available());
346
                  }
347
                  else
348
                  {
349
                     returnNormal(objects.contains(p1));
350
                  }
351
               }));
280
      return function(this, "Contains", logical.class, new Block((Body) () -> {
281
         findBufferUseObject(p1);
282
         returnNormal(tableHandle.unwrapTempTable().defaultBufferHandle().unwrapBuffer()
283
                  .available());
284
      }));
352 285
   }
353 286

  
354 287
   @LegacySignature(type = Type.METHOD, name = "ContainsAll", parameters = {
......
358 291
   {
359 292
      object<? extends Icollection> p1 = TypeFactory.initInput(_p1);
360 293

  
361
      return function(AbstractTtcollection.class, this, "ContainsAll", logical.class,
362
               new Block((Body) () ->
363
               {
364
                  Assert.notNull(p1, new character("Collection to check"));
365

  
366
                  if (p1.ref().isEmpty().booleanValue())
367
                     returnNormal(true);
368

  
369
                  // this is handled like a set not collection 
370
                  if (p1.ref().getSize().intValue() > size.intValue())
371
                     returnNormal(false);
372

  
373
                  Iiterator it = p1.ref().iterator().ref();
374

  
375
                  while (it.hasNext().booleanValue())
376
                  {
377
                     if (!contains(it.next_()).booleanValue())
378
                        returnNormal(false);
379
                  }
380

  
381
                  returnNormal(true);
382
               }));
294
      return function(this, "ContainsAll", logical.class, new Block((Body) () -> {
295
         Assert.notNull(p1, new character("Collection to check"));
296

  
297
         if (p1.ref().isEmpty().booleanValue())
298
            returnNormal(true);
299

  
300
         // this is handled like a set not collection 
301
         if (p1.ref().getSize().intValue() > size.intValue())
302
            returnNormal(false);
303

  
304
         Iiterator it = p1.ref().iterator().ref();
305

  
306
         while (it.hasNext().booleanValue())
307
         {
308
            if (!contains(it.next_()).booleanValue())
309
               returnNormal(false);
310
         }
311

  
312
         returnNormal(true);
313
      }));
383 314
   }
384 315

  
385 316
   @LegacySignature(type = Type.METHOD, name = "Iterator", qualified = "openedge.core.collections.iiterator")
386 317
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
387 318
   public object<? extends com.goldencode.p2j.oo.core.collections.Iiterator> iterator()
388 319
   {
389
      return function(AbstractTtcollection.class, this, "Iterator", object.class,
390
               new Block((Body) () ->
391
               {
392
                  if (objects == Collections.EMPTY_LIST)
393
                  {
394
                     returnNormal(ObjectOps.newInstance(LegacyIterator.class, "III",
395
                              new object(this), tableHandle, fieldHandle.unwrap().name()));
396
                  }
397
                  else
398
                  {
399
                     returnNormal(ObjectOps.newInstance(LegacyIterator.class, "III",
400
                              new object(this), new handle(new TransparentWrapper(objects)), ""));
401
                  }
402

  
403
               }));
320
      return function(this, "Iterator", object.class, new Block((Body) () -> {
321
         returnNormal(ObjectOps.newInstance(LegacyIterator.class, "III", new object(this),
322
                  tableHandle, fieldHandle.unwrap().name()));
323
      }));
404 324
   }
405 325

  
406 326
   @LegacySignature(type = Type.METHOD, name = "IsEmpty")
407 327
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
408 328
   public logical isEmpty()
409 329
   {
410
      return function(AbstractTtcollection.class, this, "IsEmpty", logical.class,
411
               new Block((Body) () ->
412
               {
413
                  if (objects == Collections.EMPTY_LIST)
414
                  {
415
                     returnNormal(!tableHandle.unwrapTempTable().hasRecords().booleanValue());
416
                  }
417
                  else
418
                  {
419
                     returnNormal(objects.isEmpty());
420
                  }
421
               }));
330
      return function(this, "IsEmpty", logical.class, new Block((Body) () -> {
331
         returnNormal(!tableHandle.unwrapTempTable().hasRecords().booleanValue());
332
      }));
422 333
   }
423 334

  
424 335
   @LegacySignature(type = Type.METHOD, name = "ToTable", parameters = {
425 336
            @LegacyParameter(name = "p1", type = "HANDLE", mode = "OUTPUT") })
426
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_PARTIAL)
337
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
427 338
   public void toTable(final TableParameter _p1)
428 339
   {
429 340
      handle p1 = new handle();
......
433 344
         TypeFactory.initOutput(p1);
434 345
      }, (Body) () ->
435 346
      {
436
         if (objects == Collections.EMPTY_LIST)
437
         {
438
            TemporaryBuffer.createDynamicTable(_p1, p1, false, true);
439
            p1.assign(tableHandle);
440
         }
441
         // TODO: create table from collection
442
         else
443
         {
444

  
445
         }
347
         TemporaryBuffer.createDynamicTable(_p1, p1, false, true);
348
         p1.assign(tableHandle);
446 349
      }));
447 350
   }
448 351

  
......
453 356
   {
454 357
      object<? extends _BaseObject_> p1 = TypeFactory.initInput(_p1);
455 358

  
456
      return function(AbstractTtcollection.class, this, "Remove", logical.class,
457
               new Block((Body) () ->
359
      return function(this, "Remove", logical.class, new Block((Body) () -> {
360
         boolean result = false;
361

  
362
         if (p1._isValid())
363
         {
364
               findBufferUseObject(p1);
365
               Buffer buffer = tableHandle.unwrapTempTable().defaultBufferHandle().unwrapBuffer();
366
               if (buffer._available())
458 367
               {
459
                  boolean result = false;
460

  
461
                  if (p1._isValid())
462
                  {
463
                     if (objects == Collections.EMPTY_LIST)
464
                     {
465
                        findBufferUseObject(p1);
466
                        Buffer buffer = tableHandle.unwrapTempTable().defaultBufferHandle()
467
                                 .unwrapBuffer();
468
                        if (buffer._available())
469
                        {
470
                           buffer.deleteRecord();
471
                           result = true;
472
                        }
473

  
474
                     }
475
                     else
476
                     {
477
                        result = objects.remove(p1);
478
                     }
479
                  }
480

  
481
                  if (result)
482
                     size.assign(size.intValue() - 1);
483

  
484
                  returnNormal(result);
485

  
486
               }));
368
                  buffer.deleteRecord();
369
                  result = true;
370
               }
371
         }
372

  
373
         if (result)
374
            size.assign(size.intValue() - 1);
375

  
376
         returnNormal(result);
377
      }));
487 378
   }
488 379

  
489 380
   @LegacySignature(type = Type.METHOD, name = "RemoveAll", parameters = {
......
493 384
   {
494 385
      object<? extends Icollection> p1 = TypeFactory.initInput(_p1);
495 386

  
496
      return function(AbstractTtcollection.class, this, "RemoveAll", logical.class,
497
               new Block((Body) () ->
498
               {
499
                  boolean result = false;
500
                  Iiterator it = p1.ref().iterator().ref();
501

  
502
                  while (it.hasNext().booleanValue())
503
                  {
504
                     object<? extends _BaseObject_> obj = it.next_();
505
                     while (remove(obj).booleanValue())
506
                        result = true;
507
                  }
508

  
509
                  returnNormal(result);
510
               }));
387
      return function(this, "RemoveAll", logical.class, new Block((Body) () -> {
388
         boolean result = false;
389
         Iiterator it = p1.ref().iterator().ref();
390

  
391
         while (it.hasNext().booleanValue())
392
         {
393
            object<? extends _BaseObject_> obj = it.next_();
394
            while (remove(obj).booleanValue())
395
               result = true;
396
         }
397

  
398
         returnNormal(result);
399
      }));
511 400
   }
512 401

  
513 402
   @LegacySignature(type = Type.METHOD, name = "RetainAll", parameters = {
......
517 406
   {
518 407
      object<? extends Icollection> p1 = TypeFactory.initInput(_p1);
519 408

  
520
      return function(AbstractTtcollection.class, this, "RetainAll", logical.class,
521
               new Block((Body) () ->
522
               {
523
                  boolean result = false;
524
                  Iiterator it = iterator().ref();
525

  
526
                  while (it.hasNext().booleanValue())
527
                  {
528
                     object<? extends _BaseObject_> obj = it.next_();
529

  
530
                     if (!p1.ref().contains(obj).booleanValue())
531
                     {
532
                        while (remove(obj).booleanValue())
533
                           result = true;
534
                     }
535
                  }
536

  
537
                  returnNormal(result);
538
               }));
409
      return function(this, "RetainAll", logical.class, new Block((Body) () -> {
410
         boolean result = false;
411
         Iiterator it = iterator().ref();
412

  
413
         while (it.hasNext().booleanValue())
414
         {
415
            object<? extends _BaseObject_> obj = it.next_();
416

  
417
            if (!p1.ref().contains(obj).booleanValue())
418
            {
419
               while (remove(obj).booleanValue())
420
                  result = true;
421
            }
422
         }
423

  
424
         returnNormal(result);
425
      }));
539 426
   }
540 427

  
541 428
   @LegacySignature(type = Type.METHOD, name = "ToArray", extent = -1, qualified = "progress.lang.object")
542 429
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_FULL)
543 430
   public object<? extends com.goldencode.p2j.oo.lang._BaseObject_>[] toArray()
544 431
   {
545
      return extentFunction(AbstractTtcollection.class, this, "ToArray", object.class,
546
               new Block((Body) () ->
547
               {
548
                  if (objects == Collections.EMPTY_LIST)
549
                  {
550
                     if (isEmpty().booleanValue())
551
                        returnExtentNormal(new object[0]);
552
                     else
553
                     {
554
                        object<? extends _BaseObject_> oArr[] = TypeFactory
555
                                 .objectExtent(getSize().intValue(), BaseObject.class);
556
                        Iiterator it = iterator().ref();
557
                        int i = 0;
432
      return extentFunction(this, "ToArray", object.class, new Block((Body) () -> {
433
         
434
         if (isEmpty().booleanValue())
435
            returnExtentNormal(new object[0]);
436
         else
437
         {
438
            object<? extends _BaseObject_> oArr[] = TypeFactory
439
                     .objectExtent(getSize().intValue(), BaseObject.class);
440
            Iiterator it = iterator().ref();
441
            int i = 0;
558 442

  
559
                        while (it.hasNext().booleanValue())
560
                        {
561
                           oArr[i++].assign(it.next_());
562
                        }
563
                        returnExtentNormal(oArr);
564
                     }
565
                  }
566
                  else
567
                  {
568
                     returnExtentNormal(objects.toArray(new object[objects.size()]));
569
                  }
570
               }));
443
            while (it.hasNext().booleanValue())
444
            {
445
               oArr[i++].assign(it.next_());
446
            }
447
            returnExtentNormal(oArr);
448
         }
449
      }));
571 450
   }
572 451

  
573 452
   @LegacySignature(type = Type.METHOD, name = "FindBufferUseObject", parameters = {
......
579 458
   @Override
580 459
   public object<? extends com.goldencode.p2j.oo.lang._BaseObject_> clone()
581 460
   {
582
      return function(AbstractTtcollection.class, this, "Clone", object.class,
583
               new Block((Body) () ->
584
               {
585
                  object<AbstractTtcollection> clone = ObjectOps
586
                           .newInstance(AbstractTtcollection.class);
587
                  cloneElements(clone);
588
                  returnNormal(clone);
589
               }));
461
      return function(this, "Clone", object.class, new Block((Body) () -> {
462
         object<? extends AbstractTtcollection> clone = ObjectOps.newInstance(getClass());
463
         cloneElements(clone);
464
         returnNormal(clone);
465
      }));
590 466
   }
591 467

  
592 468
   @LegacySignature(type = Type.METHOD, name = "CloneElements", parameters = {
......
610 486
   {
611 487
      internalProcedure(AbstractTtcollection.class, this, "Resize", new Block((Body) () ->
612 488
      {
613
         if (objects == Collections.EMPTY_LIST)
614
         {
615
            if (!queryHandle._isValid()) {
616
               QueryWrapper.createQuery(queryHandle);
617
               queryHandle.unwrapBufferCollection().setBuffers(tableHandle.unwrapTempTable().defaultBufferHandle());
618
               queryHandle.unwrapQuery().prepare(String.format("preselect each %s no-lock", tableHandle.unwrap().name()));
619
            }
620
            
621
            queryHandle.unwrapQuery().open();
... This diff was truncated because it exceeds the maximum size that can be displayed.