-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: npm packager build | ||
|
||
on: | ||
release: | ||
types: [published] | ||
jobs: | ||
build-npm-packager: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: 12 | ||
registry-url: https://npm.pkg.github.com | ||
scope: '@belicusbr' | ||
- run: npm install | ||
env: | ||
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} | ||
- run: npm publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Changelog | ||
## [1.0.0] - 11/11/2022 | ||
### Repositorio com.cobilas.core iniciado | ||
- Lançado para o GitHub |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 BelicusBr | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "Cobilas.Core", | ||
"references": [], | ||
"includePlatforms": [], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": true, | ||
"precompiledReferences": [], | ||
"autoReferenced": true, | ||
"defineConstraints": [], | ||
"versionDefines": [], | ||
"noEngineReferences": true | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,242 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
|
||
namespace Cobilas.Collections { | ||
public static class ArrayManipulation { | ||
public static event Action<object> ExceptionEvent; | ||
private static bool _autoClear; | ||
private static int autoClearLength; | ||
private static Queue<Exception> exceptions; | ||
|
||
public static Exception[] ExceptionsList => exceptions.ToArray(); | ||
public static Exception FirstError => exceptions.Count == 0 ? (Exception)null : ExceptionsList[0]; | ||
public static Exception LastError => exceptions.Count == 0 ? (Exception)null : ExceptionsList[exceptions.Count - 1]; | ||
|
||
static ArrayManipulation() { | ||
exceptions = new Queue<Exception>(); | ||
_autoClear = true; | ||
autoClearLength = 5; | ||
ExceptionEvent = null; | ||
} | ||
|
||
public static void AutoClearExceptionsList(bool autoClear, int length = 5) { | ||
_autoClear = autoClear; | ||
autoClearLength = length; | ||
} | ||
|
||
private static void AddException(Exception e) { | ||
if (ExceptionEvent != null) ExceptionEvent(e); | ||
if (_autoClear) { | ||
if (exceptions.Count < autoClearLength) exceptions.Enqueue(e); | ||
else { | ||
int length = (exceptions.Count - autoClearLength) - 1; | ||
length = length < 0 ? 0 : length; | ||
for (int I = 0; I < length; I++) | ||
_ = exceptions.Dequeue(); | ||
exceptions.Enqueue(e); | ||
} | ||
} | ||
else exceptions.Enqueue(e); | ||
} | ||
|
||
//Insert | ||
public static T[] Insert<T>(T[] itens, int index, T[] list) { | ||
try { | ||
if (list == null) list = new T[0]; | ||
T[] newList = new T[list.Length + itens.Length]; | ||
Array.Copy(list, 0, newList, 0, index); | ||
Array.Copy(itens, 0, newList, index, itens.Length); | ||
Array.Copy(list, index, newList, itens.Length + index, list.Length - index); | ||
return newList; | ||
} catch (Exception e) { | ||
AddException(e); | ||
return list; | ||
} | ||
} | ||
|
||
public static T[] Insert<T>(T item, int index, T[] list) | ||
=> Insert<T>(new T[] { item }, index, list); | ||
|
||
public static T[] Insert<T>(IEnumerator<T> itens, int index, T[] list) { | ||
try { | ||
while (itens.MoveNext()) | ||
list = Insert<T>(itens.Current, index, list); | ||
} catch (Exception e) { | ||
AddException(e); | ||
} | ||
return list; | ||
} | ||
|
||
public static void Insert<T>(T[] itens, int index, ref T[] list) | ||
=> list = Insert<T>(itens, index, list); | ||
|
||
public static void Insert<T>(T item, int index, ref T[] list) | ||
=> list = Insert<T>(item, index, list); | ||
|
||
public static T[] AddNon_Existing<T>(T item, T[] list) { | ||
if (!Exists(item, list)) | ||
return Add(item, list); | ||
return list; | ||
} | ||
|
||
public static void AddNon_Existing<T>(T item, ref T[] list) | ||
=> list = AddNon_Existing<T>(item, list); | ||
|
||
public static T[] Add<T>(T[] itens, T[] list) | ||
=> Insert<T>(itens, ArrayLength(list), list); | ||
|
||
public static T[] Add<T>(IEnumerator<T> itens, T[] list) | ||
=> Insert<T>(itens, ArrayLength(list), list); | ||
|
||
public static void Add<T>(IEnumerator<T> itens, ref T[] list) | ||
=> list = Add<T>(itens, list); | ||
|
||
public static T[] Add<T>(T item, T[] list) | ||
=> Insert<T>(item, ArrayLength(list), list); | ||
|
||
public static void Add<T>(T[] itens, ref T[] list) | ||
=> Insert<T>(itens, ArrayLength(list), ref list); | ||
|
||
public static void Add<T>(T item, ref T[] list) | ||
=> Insert<T>(item, ArrayLength(list), ref list); | ||
|
||
public static T[] Remove<T>(int index, int length, T[] list) { | ||
try { | ||
T[] newList = new T[list.Length - length]; | ||
Array.Copy(list, 0, newList, 0, index); | ||
Array.Copy(list, index + length, newList, index, list.Length - (index + length)); | ||
return newList; | ||
} catch (Exception e) { | ||
AddException(e); | ||
return list; | ||
} | ||
} | ||
|
||
public static void Remove<T>(int index, int length, ref T[] list) | ||
=> list = Remove<T>(index, length, list); | ||
|
||
public static T[] Remove<T>(int index, T[] list) | ||
=> Remove<T>(index, 1, list); | ||
|
||
public static void Remove<T>(int index, ref T[] list) | ||
=> list = Remove<T>(index, list); | ||
|
||
public static T[] Remove<T>(T item, T[] list) | ||
=> Remove<T>(IndexOf(item, list), list); | ||
|
||
public static void Remove<T>(T item, ref T[] list) | ||
=> list = Remove<T>(item, list); | ||
|
||
public static void ClearArray(Array array) { | ||
try { Array.Clear(array, 0, array.Length); } | ||
catch (Exception e) { AddException(e); } | ||
} | ||
|
||
public static void ClearArray<T>(ref T[] array) { | ||
try { | ||
Array.Clear(array, 0, array.Length); | ||
array = null; | ||
} catch (Exception e) { AddException(e); } | ||
} | ||
|
||
public static void ClearArraySafe(Array array) { | ||
if (!EmpytArray(array)) | ||
ClearArray(array); | ||
} | ||
|
||
public static void ClearArraySafe<T>(ref T[] array) { | ||
if (!EmpytArray(array)) { | ||
ClearArray(array); | ||
array = null; | ||
} | ||
} | ||
|
||
public static void SeparateList<T>(T[] list, int separationIndex, out T[] part1, out T[] part2) { | ||
try { | ||
Array.Copy(list, 0, part1 = new T[separationIndex + 1], 0, separationIndex + 1); | ||
Array.Copy(list, separationIndex + 1, part2 = new T[list.Length - (separationIndex + 1)], 0, list.Length - (separationIndex + 1)); | ||
} catch (Exception e) { | ||
AddException(e); | ||
part1 = part2 = (T[])null; | ||
} | ||
} | ||
|
||
public static T[] TakeStretch<T>(int index, int length, T[] list) { | ||
try { | ||
T[] Res = new T[length]; | ||
CopyTo(list, index, Res, 0, length); | ||
return Res; | ||
} catch (Exception e) { | ||
AddException(e); | ||
return (T[])null; | ||
} | ||
} | ||
|
||
public static ReadOnlyCollection<T> ReadOnly<T>(T[] list) { | ||
try { | ||
return Array.AsReadOnly<T>(list); | ||
} catch (Exception e) { | ||
AddException(e); | ||
return new ReadOnlyCollection<T>(new List<T>(0)); | ||
} | ||
} | ||
|
||
public static int IndexOf(object item, Array array, int index, int length) { | ||
try { | ||
return Array.IndexOf(array, item, index, length); | ||
} catch (Exception e) { | ||
AddException(e); | ||
return -1; | ||
} | ||
} | ||
|
||
public static int IndexOf(object item, Array array, int index) | ||
=> IndexOf(item, array, index, array.Length); | ||
|
||
public static int IndexOf(object item, Array array) | ||
=> IndexOf(item, array, 0); | ||
|
||
public static bool Exists(object item, Array array) { | ||
for (int I = 0; I < ArrayLength(array); I++) | ||
if (array.GetValue(I) == item) | ||
return true; | ||
return false; | ||
} | ||
|
||
public static void CopyTo(Array sourceArray, long sourceIndex, Array destinationArray, long destinationIndex, long length) { | ||
try { | ||
Array.Copy(sourceArray, sourceIndex, destinationArray, destinationIndex, length); | ||
} catch (Exception e) { | ||
AddException(e); | ||
} | ||
} | ||
|
||
public static void CopyTo(Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length) | ||
=> CopyTo(sourceArray, (long)sourceIndex, destinationArray, (long)destinationIndex, (long)length); | ||
|
||
public static void CopyTo(Array sourceArray, Array destinationArray, long length) | ||
=> CopyTo(sourceArray, 0, destinationArray, 0, length); | ||
|
||
public static void CopyTo(Array sourceArray, Array destinationArray, int length) | ||
=> CopyTo(sourceArray, 0, destinationArray, 0, length); | ||
|
||
public static void CopyTo(Array sourceArray, Array destinationArray) | ||
=> CopyTo(sourceArray, 0, destinationArray, 0, sourceArray.Length); | ||
|
||
public static void Reverse(Array array) { | ||
try { | ||
Array.Reverse(array, 0, array.Length); | ||
} catch (Exception e) { | ||
AddException(e); | ||
} | ||
} | ||
|
||
public static bool EmpytArray(ICollection array) | ||
=> array == null ? true : array.Count == 0; | ||
|
||
public static int ArrayLength(ICollection array) | ||
=> array == null ? 0 : array.Count; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.