Java Code Examples for java.util.EnumMap#isEmpty()

The following examples show how to use java.util.EnumMap#isEmpty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProcessorFactory.java    From agrest with Apache License 2.0 6 votes vote down vote up
protected Processor<C> composeStages(EnumMap<E, Processor<C>> stages) {

        if (stages.isEmpty()) {
            return c -> ProcessorOutcome.CONTINUE;
        }

        Processor<C> p = null;

        // note that EnumMap iterates in the ordinal order of the underlying enum.
        // This is important for ordering stages...
        for (Processor<C> s : stages.values()) {
            p = p == null ? s : p.andThen(s);
        }

        return p;
    }
 
Example 2
Source File: ProcessorFactory.java    From agrest with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a processor that is a combination of default stages intermixed with provided listeners.
 *
 * @return a processor that is a combination of default stages intermixed with provided listeners.
 */
public Processor<C> createProcessor(EnumMap<E, Processor<C>> processors) {

    if (processors.isEmpty()) {
        return defaultProcessor;
    }

    Processor<C> p = null;

    // note that EnumMap iterates in the ordinal order of the underlying enum.
    // This is important for ordering stages...
    for (Map.Entry<E, Processor<C>> e : defaultStages.entrySet()) {

        p = p == null ? e.getValue() : p.andThen(e.getValue());


        Processor<C> customProcessor = processors.get(e.getKey());
        if (customProcessor != null) {
            p = p.andThen(customProcessor);
        }
    }

    return p;
}
 
Example 3
Source File: PropertyValues.java    From jboss-logmanager-ext with Apache License 2.0 6 votes vote down vote up
/**
 * Converts a map into a string that can be parsed by {@link #stringToMap(String)}. The kwy will be the
 * {@linkplain Enum#name() enum name}.
 *
 * @param map the map to convert to a string
 * @param <K> the type of the key
 *
 * @return a string value for that map that can be used for configuration properties
 *
 * @see #escapeKey(StringBuilder, String)
 * @see #escapeValue(StringBuilder, String)
 */
public static <K extends Enum<K>> String mapToString(final EnumMap<K, String> map) {
    if (map == null || map.isEmpty()) {
        return null;
    }
    final StringBuilder sb = new StringBuilder(map.size() * 32);
    final Iterator<Map.Entry<K, String>> iterator = map.entrySet().iterator();
    while (iterator.hasNext()) {
        final Map.Entry<K, String> entry = iterator.next();
        sb.append(entry.getKey().name());
        sb.append('=');
        escapeValue(sb, entry.getValue());
        if (iterator.hasNext()) {
            sb.append(',');
        }
    }
    return sb.toString();
}
 
Example 4
Source File: ReportMojo.java    From revapi with Apache License 2.0 6 votes vote down vote up
private void reportDifferences(
    EnumMap<CompatibilityType, List<ReportTimeReporter.DifferenceReport>> diffsPerType, Sink sink,
    ResourceBundle bundle, String typeKey) {

    if (diffsPerType == null || diffsPerType.isEmpty()) {
        return;
    }

    sink.section2();
    sink.sectionTitle2();
    sink.text(bundle.getString(typeKey));
    sink.sectionTitle2_();

    reportDifferences(diffsPerType.get(CompatibilityType.BINARY), sink, bundle,
        "report.revapi.compatibilityType.binary");
    reportDifferences(diffsPerType.get(CompatibilityType.SOURCE), sink, bundle,
        "report.revapi.compatibilityType.source");
    reportDifferences(diffsPerType.get(CompatibilityType.SEMANTIC), sink, bundle,
        "report.revapi.compatibilityType.semantic");
    reportDifferences(diffsPerType.get(CompatibilityType.OTHER), sink, bundle,
        "report.revapi.compatibilityType.other");

    sink.section2_();
}
 
Example 5
Source File: EnumMapCodec.java    From bazel with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(SerializationContext context, EnumMap<E, V> obj, CodedOutputStream codedOut)
    throws SerializationException, IOException {
  if (!obj.getClass().equals(EnumMap.class)) {
    throw new SerializationException(
        "Cannot serialize subclasses of EnumMap: " + obj.getClass() + " (" + obj + ")");
  }
  codedOut.writeInt32NoTag(obj.size());
  if (obj.isEmpty()) {
    // Do gross hack to get key type of map, since we have no concrete element to examine.
    Unsafe unsafe = UnsafeProvider.getInstance();
    context.serialize(unsafe.getObject(obj, classTypeOffset), codedOut);
    return;
  }
  context.serialize(obj.keySet().iterator().next().getDeclaringClass(), codedOut);
  for (Map.Entry<E, V> entry : obj.entrySet()) {
    codedOut.writeInt32NoTag(entry.getKey().ordinal());
    context.serialize(entry.getValue(), codedOut);
  }
}
 
Example 6
Source File: RequestPreviewItem.java    From L2jOrg with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void runImpl() {
    if (_items == null) {
        return;
    }

    // Get the current player and return if null
    final Player activeChar = client.getPlayer();
    if (activeChar == null) {
        return;
    }

    if (!client.getFloodProtectors().getTransaction().tryPerformAction("buy")) {
        activeChar.sendMessage("You are buying too fast.");
        return;
    }

    // If Alternate rule Karma punishment is set to true, forbid Wear to player with Karma
    if (!Config.ALT_GAME_KARMA_PLAYER_CAN_SHOP && (activeChar.getReputation() < 0)) {
        return;
    }

    // Check current target of the player and the INTERACTION_DISTANCE
    final WorldObject target = activeChar.getTarget();
    // No target (i.e. GM Shop)
    if (!activeChar.isGM() && (!((target instanceof Merchant)) // Target not a merchant
            || !isInsideRadius2D(activeChar, target, Npc.INTERACTION_DISTANCE) // Distance is too far
    )) {
        return;
    }

    if ((_count < 1) || (_listId >= 4000000)) {
        client.sendPacket(ActionFailed.STATIC_PACKET);
        return;
    }

    // Get the current merchant targeted by the player
    final Merchant merchant = (target instanceof Merchant) ? (Merchant) target : null;
    if (merchant == null) {
        LOGGER.warn("Null merchant!");
        return;
    }

    final ProductList buyList = BuyListData.getInstance().getBuyList(_listId);
    if (buyList == null) {
        GameUtils.handleIllegalPlayerAction(activeChar, "Warning!! Character " + activeChar.getName() + " of account " + activeChar.getAccountName() + " sent a false BuyList list_id " + _listId);
        return;
    }

    long totalPrice = 0;
    final EnumMap<InventorySlot, Integer> items = new EnumMap<>(InventorySlot.class);

    for (int i = 0; i < _count; i++) {
        final int itemId = _items[i];

        final Product product = buyList.getProductByItemId(itemId);
        if (product == null) {
            GameUtils.handleIllegalPlayerAction(activeChar, "Warning!! Character " + activeChar.getName() + " of account " + activeChar.getAccountName() + " sent a false BuyList list_id " + _listId + " and item_id " + itemId);
            return;
        }

        var slot = product.getBodyPart().slot();
        if (isNull(slot)) {
            continue;
        }

        if (items.containsKey(slot)) {
            activeChar.sendPacket(SystemMessageId.YOU_CAN_NOT_TRY_THOSE_ITEMS_ON_AT_THE_SAME_TIME);
            return;
        }

        items.put(slot, itemId);
        totalPrice += Config.WEAR_PRICE;
        if (totalPrice > Inventory.MAX_ADENA) {
            GameUtils.handleIllegalPlayerAction(activeChar, "Warning!! Character " + activeChar.getName() + " of account " + activeChar.getAccountName() + " tried to purchase over " + Inventory.MAX_ADENA + " adena worth of goods.");
            return;
        }
    }

    // Charge buyer and add tax to castle treasury if not owned by npc clan because a Try On is not Free
    if ((totalPrice < 0) || !activeChar.reduceAdena("Wear", totalPrice, activeChar.getLastFolkNPC(), true)) {
        activeChar.sendPacket(SystemMessageId.YOU_DO_NOT_HAVE_ENOUGH_ADENA_POPUP);
        return;
    }

    if (!items.isEmpty()) {
        activeChar.sendPacket(new ShopPreviewInfo(items));
        // Schedule task
        ThreadPool.schedule(new RemoveWearItemsTask(activeChar), Config.WEAR_DELAY * 1000);
    }
}