-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #147 from zelenyhleb/master
Bug 560181 - [Passage] add billing core basic implementation
- Loading branch information
Showing
5 changed files
with
217 additions
and
44 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
...billing.core/src/org/eclipse/passage/loc/internal/billing/core/ProductVersionLicense.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2020 ArSysOp | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* https://www.eclipse.org/legal/epl-2.0/. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Nikifor Fedorov <[email protected]> - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.passage.loc.internal.billing.core; | ||
|
||
import java.util.Objects; | ||
|
||
import org.eclipse.passage.lic.users.UserLicenseDescriptor; | ||
|
||
/** | ||
* Local data class designed to sort licenses by product and version. | ||
* | ||
* @since 0.1 | ||
*/ | ||
public final class ProductVersionLicense { | ||
|
||
private final String product; | ||
private final String version; | ||
|
||
/** | ||
* @param license license descriptor (must not be null) | ||
*/ | ||
public ProductVersionLicense(UserLicenseDescriptor license) { | ||
Objects.requireNonNull(license); | ||
this.product = Objects.requireNonNull(license.getProductIdentifier()); | ||
this.version = Objects.requireNonNull(license.getProductVersion()); | ||
} | ||
|
||
public String getProduct() { | ||
return product; | ||
} | ||
|
||
public String getVersion() { | ||
return version; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (!this.getClass().isInstance(obj)) { | ||
return false; | ||
} | ||
ProductVersionLicense license = (ProductVersionLicense) obj; | ||
return Objects.equals(getProduct(), license.getProduct()) && Objects.equals(getVersion(), license.getVersion()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(getProduct(), getVersion()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getProduct() + ":" + getVersion(); //$NON-NLS-1$ | ||
} | ||
|
||
} |
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
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
52 changes: 52 additions & 0 deletions
52
...oc.billing.core.tests/src/org/eclipse/passage/loc/billing/core/tests/StringsProvider.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2020 ArSysOp | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* https://www.eclipse.org/legal/epl-2.0/. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Nikifor Fedorov <[email protected]> - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.passage.loc.billing.core.tests; | ||
|
||
import java.nio.charset.Charset; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
public class StringsProvider { | ||
|
||
private final List<String> strings = new LinkedList<String>(); | ||
private final Random random = new Random(); | ||
|
||
private boolean contains(String string) { | ||
return strings.contains(string); | ||
} | ||
|
||
private boolean add(String string) { | ||
return strings.add(string); | ||
} | ||
|
||
public final void clear() { | ||
strings.clear(); | ||
} | ||
|
||
public final String randomString() { | ||
String string = new String(array(), Charset.forName("UTF-8")); //$NON-NLS-1$ | ||
if (contains(string)) { | ||
return randomString(); | ||
} | ||
add(string); | ||
return string; | ||
} | ||
|
||
private byte[] array() { | ||
byte[] array = new byte[5]; | ||
random.nextBytes(array); | ||
return array; | ||
} | ||
|
||
} |
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