Created
April 26, 2022 00:41
-
-
Save Colouratura/2e52165e677a139fe1fbbeb7a5b72d90 to your computer and use it in GitHub Desktop.
The future of enterprise software.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TwitterExtensibleError extends Error { | |
constructor(message) { | |
super(message) | |
this.name = this.constructor.name | |
if (typeof Error.captureStackTrace === 'function') { | |
Error.captureStackTrace(this, this.constructor); | |
} else { | |
this.stack = (new Error(message)).stack; | |
} | |
} | |
} | |
class TwitterObjectSealedError extends TwitterExtensibleError {} | |
class TwitterNotTStringError extends TwitterExtensibleError {} | |
class TwitterNotTTimeError extends TwitterExtensibleError {} | |
class TwitterNotTNumberError extends TwitterExtensibleError {} | |
class TwitterNotTBooleanError extends TwitterExtensibleError {} | |
class TwitterNotAuthorError extends TwitterExtensibleError {} | |
class TwitterNotTimeError extends TwitterExtensibleError {} | |
class TwitterNotMessageError extends TwitterExtensibleError {} | |
class TwitterNotLikesError extends TwitterExtensibleError {} | |
class TwitterNotRetweetsError extends TwitterExtensibleError {} | |
class Tweet { | |
constructor(author, time, message, likes, retweets) { | |
if (!author instanceof Author) { | |
throw new TwitterNotAuthorError() | |
} else if (!time instanceof Time) { | |
throw new TwitterNotTimeError() | |
} else if (!message instanceof Message) { | |
throw new TwitterNotMessageError() | |
} else if (!likes instanceof Likes) { | |
throw new TwitterNotLikesError() | |
} else if (!retweets instanceof Retweets) { | |
throw new TwitterNotRetweetsError() | |
} else { | |
this._author = author | |
this._time = time | |
this._message = message | |
this._likes = likes | |
this._retweets = retweets | |
} | |
} | |
getAuthor = () => this.author | |
getTime = () => this.time | |
getMessage = () => this.message | |
getLikes = () => this.likes | |
getRetweets = () => this.retweets | |
} | |
class Author { | |
constructor() { | |
this._sealedError = "This message is already sealed!" | |
this._stringError = "val is not a TString!" | |
this._sealed = new TBoolean() | |
.setIsFalse(true) | |
.setIsTrue(false) | |
.setValue(false) | |
.seal() | |
this._value = undefined | |
} | |
getValue = () => this._value | |
isSealed = () => this._sealed | |
setValue(val) { | |
if (this.isSealed().getValue()) { | |
throw new TwitterObjectSealedError(this._sealedError) | |
} else { | |
if (val instanceof TString) { | |
this._value = val | |
} else { | |
throw new TwitterNotTStringError(this._stringError) | |
} | |
} | |
} | |
seal() { | |
if (this.isSealed().getValue()) { | |
throw new TwitterObjectSealedError(this._sealedError) | |
} else { | |
this._sealed = new TBoolean() | |
.setIsFalse(false) | |
.setIsTrue(true) | |
.setValue(true) | |
.seal() | |
} | |
} | |
} | |
class Time { | |
constructor() { | |
this._sealedError = "This message is already sealed!" | |
this._timeError = "val is not a TTime!" | |
this._sealed = new TBoolean() | |
.setIsFalse(true) | |
.setIsTrue(false) | |
.setValue(false) | |
.seal() | |
this._value = undefined | |
} | |
getValue = () => this._value | |
isSealed = () => this._sealed | |
setValue(val) { | |
if (this.isSealed().getValue()) { | |
throw new TwitterObjectSealedError(this._sealedError) | |
} else { | |
if (val instanceof TTime) { | |
this._value = val | |
} else { | |
throw new TwitterNotTTimeError(this._timeError) | |
} | |
} | |
} | |
seal() { | |
if (this.isSealed().getValue()) { | |
throw new TwitterObjectSealedError(this._sealedError) | |
} else { | |
this._sealed = new TBoolean() | |
.setIsFalse(false) | |
.setIsTrue(true) | |
.setValue(true) | |
.seal() | |
} | |
} | |
} | |
class Message { | |
constructor() { | |
this._sealedError = "This message is already sealed!" | |
this._stringError = "val is not a TString!" | |
this._sealed = new TBoolean() | |
.setIsFalse(true) | |
.setIsTrue(false) | |
.setValue(false) | |
.seal() | |
this._value = undefined | |
} | |
getValue = () => this._value | |
isSealed = () => this._sealed | |
setValue(val) { | |
if (this.isSealed().getValue()) { | |
throw new TwitterObjectSealedError(this._sealedError) | |
} else { | |
if (val instanceof TString) { | |
this._value = val | |
} else { | |
throw new TwitterNotTStringError(this._stringError) | |
} | |
} | |
} | |
seal() { | |
if (this.isSealed().getValue()) { | |
throw new TwitterObjectSealedError(this._sealedError) | |
} else { | |
this._sealed = new TBoolean() | |
.setIsFalse(false) | |
.setIsTrue(true) | |
.setValue(true) | |
.seal() | |
} | |
} | |
} | |
class Likes { | |
constructor() { | |
this._sealedError = "This likess is already sealed!" | |
this._sealed = new TBoolean() | |
.setIsFalse(true) | |
.setIsTrue(false) | |
.setValue(false) | |
.seal() | |
this._value = 0 | |
} | |
getValue = () => this._value | |
isSealed = () => this._sealed | |
addLike() { | |
if (this.isSealed().getValue()) { | |
throw new TwitterObjectSealedError(this._sealedError) | |
} else { | |
const tfalse = new TBoolean() | |
.setIsFalse(true) | |
.setIsTrue(false) | |
.setValue(false) | |
.seal() | |
const ttrue = new TBoolean() | |
.setIsFalse(false) | |
.setIsTrue(true) | |
.setValue(true) | |
.seal() | |
this._value = new TNumber() | |
.setPositive(ttrue) | |
.setNegative(tfalse) | |
.setValue(this._value.getValue() + 1) | |
} | |
} | |
deleteLike() { | |
if (this.isSealed().getValue()) { | |
throw new TwitterObjectSealedError(this._sealedError) | |
} else { | |
const tfalse = new TBoolean() | |
.setIsFalse(true) | |
.setIsTrue(false) | |
.setValue(false) | |
.seal() | |
const ttrue = new TBoolean() | |
.setIsFalse(false) | |
.setIsTrue(true) | |
.setValue(true) | |
.seal() | |
this._value = new TNumber() | |
.setPositive(ttrue) | |
.setNegative(tfalse) | |
.setValue(this._value.getValue() - 1) | |
} | |
} | |
seal() { | |
if (this.isSealed().getValue()) { | |
throw new TwitterObjectSealedError(this._sealedError) | |
} else { | |
this._sealed = new TBoolean() | |
.setIsFalse(false) | |
.setIsTrue(true) | |
.setValue(true) | |
.seal() | |
} | |
} | |
} | |
class Retweets { | |
constructor() { | |
this._sealedError = "This retweets is already sealed!" | |
this._sealed = new TBoolean() | |
.setIsFalse(true) | |
.setIsTrue(false) | |
.setValue(false) | |
.seal() | |
this._value = 0 | |
} | |
getValue = () => this._value | |
isSealed = () => this._sealed | |
addRetweet() { | |
if (this.isSealed().getValue()) { | |
throw new TwitterObjectSealedError(this._sealedError) | |
} else { | |
const tfalse = new TBoolean() | |
.setIsFalse(true) | |
.setIsTrue(false) | |
.setValue(false) | |
.seal() | |
const ttrue = new TBoolean() | |
.setIsFalse(false) | |
.setIsTrue(true) | |
.setValue(true) | |
.seal() | |
this._value = new TNumber() | |
.setPositive(ttrue) | |
.setNegative(tfalse) | |
.setValue(this._value.getValue() + 1) | |
} | |
} | |
deleteRetweet() { | |
if (this.isSealed().getValue()) { | |
throw new TwitterObjectSealedError(this._sealedError) | |
} else { | |
const tfalse = new TBoolean() | |
.setIsFalse(true) | |
.setIsTrue(false) | |
.setValue(false) | |
.seal() | |
const ttrue = new TBoolean() | |
.setIsFalse(false) | |
.setIsTrue(true) | |
.setValue(true) | |
.seal() | |
this._value = new TNumber() | |
.setPositive(ttrue) | |
.setNegative(tfalse) | |
.setValue(this._value.getValue() - 1) | |
} | |
} | |
seal() { | |
if (this.isSealed().getValue()) { | |
throw new TwitterObjectSealedError(this._sealedError) | |
} else { | |
this._sealed = new TBoolean() | |
.setIsFalse(false) | |
.setIsTrue(true) | |
.setValue(true) | |
.seal() | |
} | |
} | |
} | |
class TString { | |
constructor() { | |
this._sealedError = "This string is already sealed!" | |
this._numberError = "val is not a TNumber!" | |
this._sealed = new TBoolean() | |
.setIsFalse(true) | |
.setIsTrue(false) | |
.setValue(false) | |
.seal() | |
this._value = undefined | |
this._length = undefined | |
} | |
getValue = () => this._value | |
getLength = () => this._length | |
isSealed = () => this._sealed | |
setValue(val) { | |
if (this.isSealed().getValue()) { | |
throw new TwitterObjectSealedError(this._sealedError) | |
} else { | |
this._value = val | |
} | |
} | |
setLength(val) { | |
if (this.isSealed().getValue()) { | |
throw new TwitterObjectSealedError(this._sealedError) | |
} else { | |
if (val instanceof TNumber) { | |
this._length = val | |
} else { | |
throw new TwitterNotTNumberError(this._numberError) | |
} | |
} | |
} | |
seal() { | |
if (this.isSealed().getValue()) { | |
throw new TwitterObjectSealedError(this._sealedError) | |
} else { | |
this._sealed = new TBoolean() | |
.setIsFalse(false) | |
.setIsTrue(true) | |
.setValue(true) | |
.seal() | |
} | |
} | |
} | |
class TTime { | |
constructor() { | |
this._sealedError = "This time is already sealed!" | |
this._sealed = new TBoolean() | |
.setIsFalse(true) | |
.setIsTrue(false) | |
.setValue(false) | |
.seal() | |
this._value = undefined | |
} | |
getValue = () => this._value | |
isSealed = () => this._sealed | |
setValue(val) { | |
if (this.isSealed().getValue()) { | |
throw new TwitterObjectSealedError(this._sealedError) | |
} else { | |
this._value = val | |
} | |
} | |
seal() { | |
if (this.isSealed().getValue()) { | |
throw new TwitterObjectSealedError(this._sealedError) | |
} else { | |
this._sealed = new TBoolean() | |
.setIsFalse(false) | |
.setIsTrue(true) | |
.setValue(true) | |
.seal() | |
} | |
} | |
} | |
class TNumber { | |
constructor () { | |
this._sealedError = "This number is already sealed!" | |
this._booleanError = "val is not a TBoolean!" | |
this._sealed = new TBoolean() | |
.setIsFalse(true) | |
.setIsTrue(false) | |
.setValue(false) | |
.seal() | |
this._value = undefined | |
this._positive = undefined | |
this._negative = undefined | |
} | |
getValue = () => this._value | |
getPositive = () => this._positive | |
getNegative = () => this._negative | |
isSealed = () => this._sealed | |
setValue(val) { | |
if (this.isSealed().getValue()) { | |
throw new TwitterObjectSealedError(this._sealedError) | |
} else { | |
this.value = val | |
} | |
} | |
setPositive(val) { | |
if (this.isSealed().getValue()) { | |
throw new TwitterObjectSealedError(this._sealedError) | |
} else { | |
if (val instanceof TBoolean) { | |
this._positive = val | |
} else { | |
throw new TwitterNotTBooleanError(this._booleanError) | |
} | |
} | |
} | |
setNegative(val) { | |
if (this.isSealed().getValue()) { | |
throw new TwitterObjectSealedError(this._sealedError) | |
} else { | |
if (val instanceof TBoolean) { | |
this._negative = val | |
} else { | |
throw new TwitterNotTBooleanError(this._booleanError) | |
} | |
} | |
} | |
seal() { | |
if (this.isSealed().getValue()) { | |
throw new TwitterObjectSealedError(this._sealedError) | |
} else { | |
this._sealed = new TBoolean() | |
.setIsFalse(false) | |
.setIsTrue(true) | |
.setValue(true) | |
.seal() | |
} | |
} | |
} | |
class TBoolean { | |
constructor () { | |
this._sealedError = "This boolean is already sealed!" | |
this._sealed = false | |
this._value = undefined | |
this._istrue = undefined | |
this._isfalse = undefined | |
} | |
getValue = () => this._value | |
getIsTrue = () => this._istrue | |
getIsFalse = () => this._isfalse | |
isSealed = () => this._sealed | |
setValue(val) { | |
if (this.isSealed()) { | |
throw new TwitterObjectSealedError(this._sealedError) | |
} else { | |
this._value = val | |
} | |
} | |
setIsTrue(val) { | |
if (this.isSealed()) { | |
throw new TwitterObjectSealedError(this._sealedError) | |
} else { | |
this._value = val | |
} | |
} | |
setIsFalse(val) { | |
if (this.isSealed()) { | |
throw new TwitterObjectSealedError(this._sealedError) | |
} else { | |
this._value = val | |
} | |
} | |
seal() { | |
if (this.isSealed()) { | |
throw new TwitterObjectSealedError(this._sealedError) | |
} else { | |
this._sealed = true | |
} | |
} | |
} | |
const author = new Author() | |
.setValue(new TString() | |
.setValue("Celestia") | |
.seal()) | |
.seal() | |
const time = new Time() | |
.setValue(new TTime() | |
.setValue(new Date()) | |
.seal()) | |
.seal() | |
const message = new Message() | |
.setValue(new TString() | |
.setValue("Hello, Equestria!") | |
.seal()) | |
.seal() | |
const likes = new Likes().seal() | |
const retweets = new Retweets().seal() | |
const tweet = new Tweet(author, time, message, likes, retweets) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment