MCPcopy Index your code
hub / github.com/clojure/clojure / countFrom

Method countFrom

src/jvm/clojure/lang/RT.java:666–692  ·  view source on GitHub ↗
(Object o)

Source from the content-addressed store, hash-verified

664}
665
666static int countFrom(Object o){
667 if(o == null)
668 return 0;
669 else if(o instanceof IPersistentCollection) {
670 ISeq s = seq(o);
671 o = null;
672 int i = 0;
673 for(; s != null; s = s.next()) {
674 if(s instanceof Counted)
675 return i + s.count();
676 i++;
677 }
678 return i;
679 }
680 else if(o instanceof CharSequence)
681 return ((CharSequence) o).length();
682 else if(o instanceof Collection)
683 return ((Collection) o).size();
684 else if(o instanceof Map)
685 return ((Map) o).size();
686 else if (o instanceof Map.Entry)
687 return 2;
688 else if(o.getClass().isArray())
689 return Array.getLength(o);
690
691 throw new UnsupportedOperationException("count not supported on this type: " + o.getClass().getSimpleName());
692}
693
694static public IPersistentCollection conj(IPersistentCollection coll, Object x){
695 if(coll == null)

Callers 1

countMethod · 0.95

Calls 6

seqMethod · 0.95
nextMethod · 0.95
getLengthMethod · 0.80
countMethod · 0.65
lengthMethod · 0.65
sizeMethod · 0.45

Tested by

no test coverage detected