Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package enumsupport.reverselookupmapfactory; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; import org.apache.commons.lang3.Range; /** * 1????????????(??) * * @author normal * @param <T> ? */ public final class DeduplicatdeNumberSetFactory<T extends Number> { public DeduplicatdeNumberSetFactory() { } /** * * @param numberRange ??? * @param number null?? * @param numbers ??????null?????? * @return ????(??) * @throws NullPointerException ?????null????? * @throws IllegalArgumentException ??numberrange??????? */ public Set<T> makeSet(Range<T> numberRange, T number, T... numbers) throws NullPointerException, IllegalArgumentException { List<T> t = new ArrayList<>(); t.add(number); if (numbers != null) { t.addAll(Arrays.asList(numbers)); } for (T num : t) { if (num == null) { throw new IllegalArgumentException("?null???????"); } if (!numberRange.contains(num)) { MessageFormat msg = new MessageFormat( "????????????={0}"); Object[] parameters = { num }; throw new IllegalArgumentException(msg.format(parameters)); } } Set<T> numberSet_t = Collections.synchronizedSet(new HashSet<>()); numberSet_t.addAll(t); return Collections.unmodifiableSet(numberSet_t); } }