001/* 002 * nimbus-jose-jwt 003 * 004 * Copyright 2012-2016, Connect2id Ltd and contributors. 005 * 006 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use 007 * this file except in compliance with the License. You may obtain a copy of the 008 * License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software distributed 013 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 014 * CONDITIONS OF ANY KIND, either express or implied. See the License for the 015 * specific language governing permissions and limitations under the License. 016 */ 017 018package com.nimbusds.jose.crypto.opts; 019 020 021import java.util.Set; 022 023import com.nimbusds.jose.JWSSignerOption; 024 025 026/** 027 * Utilities for processing JOSE options. 028 */ 029public class OptionUtils { 030 031 032 /** 033 * Returns {@code true} if the specified set of options contains an 034 * instance of a class implementing {@link JWSSignerOption}. 035 * 036 * @param opts The options set, may be {@code null}. 037 * @param tClass The class. Must not be {@code null}. 038 * 039 * @return {@code true} if an option is present, else {@code false}. 040 */ 041 public static <T extends JWSSignerOption> boolean optionIsPresent(final Set<JWSSignerOption> opts, final Class<T> tClass) { 042 043 if (opts == null || opts.isEmpty()) { 044 return false; 045 } 046 047 for (JWSSignerOption o: opts) { 048 049 if (o.getClass().isAssignableFrom(tClass)) { 050 return true; 051 } 052 } 053 054 return false; 055 } 056}