//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: public static java.util.Set<?> toSet(Object value)
        public static ISet <object> ToSet(object value)
        {
            if (value == null || value == NO_VALUE)
            {
                return(Collections.emptySet());
            }
            else if (value is SequenceValue)
            {
                SequenceValue          sequenceValue = ( SequenceValue )value;
                IEnumerator <AnyValue> iterator      = sequenceValue.GetEnumerator();
                ISet <AnyValue>        set;
                if (sequenceValue.IterationPreference() == RANDOM_ACCESS)
                {
                    // If we have a random access sequence value length() should be cheap and we can optimize the initial capacity
                    int length = sequenceValue.Length();
                    set = new HashSet <AnyValue>(length);
                    for (int i = 0; i < length; i++)
                    {
                        set.Add(sequenceValue.Value(i));
                    }
                }
                else
                {
                    set = new HashSet <AnyValue>();
                    while (iterator.MoveNext())
                    {
                        AnyValue element = iterator.Current;
                        set.Add(element);
                    }
                }
                return(set);
            }
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: else if (value instanceof java.util.Collection<?>)
            else if (value is ICollection <object> )
            {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: return new java.util.HashSet<>((java.util.Collection<?>) value);
                return(new HashSet <object>((ICollection <object>)value));
            }
            else if (value is LongStream)
            {
                LongStream stream = ( LongStream )value;
                return(stream.boxed().collect(Collectors.toSet()));
            }
            else if (value is IntStream)
            {
                IntStream stream = ( IntStream )value;
                return(stream.boxed().collect(Collectors.toSet()));
            }
            else if (value is DoubleStream)
            {
                DoubleStream stream = ( DoubleStream )value;
                return(stream.boxed().collect(Collectors.toSet()));
            }
            else if (value.GetType().IsArray)
            {
                int len = Array.getLength(value);
                HashSet <object> collection = new HashSet <object>(len);
                for (int i = 0; i < len; i++)
                {
                    collection.Add(Array.get(value, i));
                }
                return(collection);
            }

            throw new CypherTypeException("Don't know how to create a set out of " + value.GetType().Name, null);
        }