Skip to content

Instantly share code, notes, and snippets.

@horrorho
Created July 13, 2017 17:14
Show Gist options
  • Select an option

  • Save horrorho/a52e0c636c6438b7e5b19fd9e5a67764 to your computer and use it in GitHub Desktop.

Select an option

Save horrorho/a52e0c636c6438b7e5b19fd9e5a67764 to your computer and use it in GitHub Desktop.
/*
* The MIT License
*
* Copyright 2016 Ayesha.
*
* 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.
*/
package com.github.horrorho.badshampoo.pcs.keyset;
import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import static java.util.stream.Collectors.toMap;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.Immutable;
/**
*
* @author Ayesha
*/
@Immutable
public enum Service {
// Internal non-standard: service is not specified/ null value
UNSPECIFIED(-2),
// Internal non-standard: service is specified but not recognised as an enum
UNKNOWN(-1),
// Raw
RAW(0),
// MasterKey
PCS_MASTERKEY(1),
// iCloudDrive
BLADERUNNER(2),
// Photos
HYPERION(3),
// CloudKit
LIVERPOOL(4),
// Escrow
PCS_ESCROW(5),
// FDE
PCS_FDE(6),
// Maildrop
PIANOMOVER(7),
// Backup
PCS_BACKUP(8),
// Notes
PCS_NOTES(9),
// iMessage
PCS_IMESSAGE(10),
// News
NEWS(11),
// Sharing
SHARING(12),
// KeyboardServices
KEYBOARD_SERVICES(13),
// Activities
ACTIVITIES(14),
// Gaming
GAMING(15),
// iAD
IAD(16),
// BulkMail
BULK_MAIL(17),
// BTPairing
BT_PAIRING(18),
// BTAnnouncement
BT_ANNOUNCEMENT(19),
// TTYCallHistory
TTY_CALL_HISTORY(20),
// Continuity
CONTINUITY(21),
LOBSTER_ROMANCE(22),
HAPPY_STONES(23),
HORROR_HO(24),
RED_SKIES(25),
BROKEN_PANDA(26),
FROZEN_MOOSE(27);
private static final Map<Integer, Service> map
= Arrays.asList(Service.values())
.stream()
.collect(toMap(Service::id, Function.identity()));
@Nonnull
public static Optional<Service> optional(int number) {
return Optional.ofNullable(map.get(number));
}
@Nonnull
public static Service service(int number) {
return optional(number)
.orElse(UNKNOWN);
}
private final int id;
private Service(int id) {
this.id = id;
}
public int id() {
return id;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment