From 29a54f5293df73e0deaac17048f924d97e87b0cf Mon Sep 17 00:00:00 2001 From: Darin Kelkhoff Date: Mon, 26 Feb 2024 14:20:28 -0600 Subject: [PATCH] Initial checkin - helper for memoizing Supplier-style functions --- .../core/utils/memoization/AnyKey.java | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/utils/memoization/AnyKey.java diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/utils/memoization/AnyKey.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/utils/memoization/AnyKey.java new file mode 100644 index 00000000..026d0fd3 --- /dev/null +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/utils/memoization/AnyKey.java @@ -0,0 +1,78 @@ +/* + * QQQ - Low-code Application Framework for Engineers. + * Copyright (C) 2021-2024. Kingsrook, LLC + * 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States + * contact@kingsrook.com + * https://github.com/Kingsrook/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package com.kingsrook.qqq.backend.core.utils.memoization; + + +/******************************************************************************* + ** Meant to serve as the key in a Memoization where we actually don't need a parameter. + ** e.g., to memoize a function like: public Object f(); + *******************************************************************************/ +public class AnyKey +{ + private static AnyKey anyKey = null; + + + + /******************************************************************************* + ** Singleton constructor + *******************************************************************************/ + private AnyKey() + { + + } + + + + /******************************************************************************* + ** Singleton accessor + *******************************************************************************/ + public static AnyKey getInstance() + { + if(anyKey == null) + { + anyKey = new AnyKey(); + } + return (anyKey); + } + + + + /******************************************************************************* + ** + *******************************************************************************/ + @Override + public boolean equals(Object obj) + { + return (obj == this); + } + + + + /******************************************************************************* + ** + *******************************************************************************/ + @Override + public int hashCode() + { + return 1; + } +}