Changeset 8132 in josm for trunk/src/com/drew/metadata/Directory.java
- Timestamp:
- 2015-03-10T01:17:39+01:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/drew/metadata/Directory.java
r6127 r8132 1 1 /* 2 * Copyright 2002-201 2Drew Noakes2 * Copyright 2002-2015 Drew Noakes 3 3 * 4 4 * Licensed under the Apache License, Version 2.0 (the "License"); … … 16 16 * More information about this project is available at: 17 17 * 18 * http://drewnoakes.com/code/exif/ 19 * http ://code.google.com/p/metadata-extractor/18 * https://drewnoakes.com/code/exif/ 19 * https://github.com/drewnoakes/metadata-extractor 20 20 */ 21 21 package com.drew.metadata; … … 37 37 * data types. 38 38 * 39 * @author Drew Noakes http://drewnoakes.com 39 * @author Drew Noakes https://drewnoakes.com 40 40 */ 41 41 public abstract class Directory 42 42 { 43 // TODO get Array methods need to return cloned data, to maintain this directory's integrity44 45 43 /** Map of values hashed by type identifiers. */ 46 44 @NotNull … … 104 102 public Collection<Tag> getTags() 105 103 { 106 return _definedTagList; 104 return Collections.unmodifiableCollection(_definedTagList); 107 105 } 108 106 … … 158 156 public Iterable<String> getErrors() 159 157 { 160 return _errorList; 158 return Collections.unmodifiableCollection(_errorList); 161 159 } 162 160 … … 414 412 return null; 415 413 416 if (o instanceof String) { 414 if (o instanceof Number) { 415 return ((Number)o).intValue(); 416 } else if (o instanceof String) { 417 417 try { 418 418 return Integer.parseInt((String)o); … … 428 428 return (int)val; 429 429 } 430 } else if (o instanceof Number) {431 return ((Number)o).intValue();432 430 } else if (o instanceof Rational[]) { 433 431 Rational[] rationals = (Rational[])o; … … 498 496 if (o == null) 499 497 return null; 498 if (o instanceof int[]) 499 return (int[])o; 500 500 if (o instanceof Rational[]) { 501 501 Rational[] rationals = (Rational[])o; … … 506 506 return ints; 507 507 } 508 if (o instanceof int[]) 509 return (int[])o; 508 if (o instanceof short[]) { 509 short[] shorts = (short[])o; 510 int[] ints = new int[shorts.length]; 511 for (int i = 0; i < shorts.length; i++) { 512 ints[i] = shorts[i]; 513 } 514 return ints; 515 } 510 516 if (o instanceof byte[]) { 511 517 byte[] bytes = (byte[])o; 512 518 int[] ints = new int[bytes.length]; 513 519 for (int i = 0; i < bytes.length; i++) { 514 byte b = bytes[i]; 515 ints[i] = b; 520 ints[i] = bytes[i]; 516 521 } 517 522 return ints; … … 527 532 if (o instanceof Integer) 528 533 return new int[] { (Integer)o }; 529 534 530 535 return null; 531 536 } … … 560 565 } 561 566 return bytes; 567 } else if (o instanceof short[]) { 568 short[] shorts = (short[])o; 569 byte[] bytes = new byte[shorts.length]; 570 for (int i = 0; i < shorts.length; i++) { 571 bytes[i] = (byte)shorts[i]; 572 } 573 return bytes; 562 574 } else if (o instanceof CharSequence) { 563 575 CharSequence str = (CharSequence)o; … … 703 715 /** 704 716 * Returns the specified tag's value as a java.util.Date. If the value is unset or cannot be converted, <code>null</code> is returned. 705 * <p />717 * <p> 706 718 * If the underlying value is a {@link String}, then attempts will be made to parse the string as though it is in 707 719 * the current {@link TimeZone}. If the {@link TimeZone} is known, call the overload that accepts one as an argument. … … 712 724 return getDate(tagType, null); 713 725 } 714 726 715 727 /** 716 728 * Returns the specified tag's value as a java.util.Date. If the value is unset or cannot be converted, <code>null</code> is returned. 717 * <p />729 * <p> 718 730 * If the underlying value is a {@link String}, then attempts will be made to parse the string as though it is in 719 731 * the {@link TimeZone} represented by the {@code timeZone} parameter (if it is non-null). Note that this parameter … … 818 830 boolean isLongArray = componentType.getName().equals("long"); 819 831 boolean isByteArray = componentType.getName().equals("byte"); 832 boolean isShortArray = componentType.getName().equals("short"); 820 833 StringBuilder string = new StringBuilder(); 821 834 for (int i = 0; i < arrayLength; i++) { … … 826 839 else if (isIntArray) 827 840 string.append(Array.getInt(o, i)); 841 else if (isShortArray) 842 string.append(Array.getShort(o, i)); 828 843 else if (isLongArray) 829 844 string.append(Array.getLong(o, i)); … … 896 911 897 912 /** 913 * Gets whether the specified tag is known by the directory and has a name. 914 * 915 * @param tagType the tag type identifier 916 * @return whether this directory has a name for the specified tag 917 */ 918 public boolean hasTagName(int tagType) 919 { 920 return getTagNameMap().containsKey(tagType); 921 } 922 923 /** 898 924 * Provides a description of a tag's value using the descriptor set by 899 925 * <code>setDescriptor(Descriptor)</code>. … … 908 934 return _descriptor.getDescription(tagType); 909 935 } 936 937 @Override 938 public String toString() 939 { 940 return String.format("%s Directory (%d %s)", 941 getName(), 942 _tagMap.size(), 943 _tagMap.size() == 1 944 ? "tag" 945 : "tags"); 946 } 910 947 }
Note:
See TracChangeset
for help on using the changeset viewer.