Changeset 7120
- Timestamp:
- Apr 15, 2016, 9:56:30 AM (7 years ago)
- Location:
- trunk/src
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/clients/web/net/sf/basedb/clients/web/Base.java
r6958 r7120 1510 1510 oValues[j] = formatter.parseString((String)jsonValues.get(j)); 1511 1511 } 1512 a.setValues (Arrays.asList(oValues), unit);1512 a.setValuesIfDifferent(Arrays.asList(oValues), unit); 1513 1513 } 1514 1514 } -
trunk/src/core/net/sf/basedb/core/Annotation.java
r7109 r7120 113 113 data.setSource(Source.CLONED.ordinal()); 114 114 data.setValues(Type.fromValue(inheritedFrom.getAnnotationType().getValueType()).newParameterValueData()); 115 data.getValues().replaceValues (inheritedFrom.getValues().getValues());115 data.getValues().replaceValuesIfDifferent(inheritedFrom.getValues().getValues()); 116 116 data.setUnit(inheritedFrom.getUnit()); 117 117 data.setLastUpdate(inheritedFrom.getLastUpdate()); … … 526 526 } 527 527 528 @Deprecated 528 529 public void setValue(Object value) 529 530 throws PermissionDeniedException, InvalidDataException, BaseException 530 531 { 531 setValue (value, null);532 setValueIfDifferent(value, null); 532 533 } 533 534 … … 544 545 @throws BaseException If there is another error 545 546 @since 2.9 546 */ 547 @deprecated In 3.8, use {@link #setValueIfDifferent(Object, Unit)} instead 548 */ 549 @Deprecated 547 550 public void setValue(Object value, Unit unit) 551 throws PermissionDeniedException, InvalidDataException, BaseException 552 { 553 setValueIfDifferent(value, unit); 554 } 555 556 /** 557 Set the value of the annotation, replacing any previous values if they 558 are different. No change is made if the new value is the same 559 as the existing value. 560 561 @param value The new value 562 @param unit The unit of the value, or null to use the default unit of 563 the annotation type 564 @throws PermissionDeniedException If the logged in user doesn't have 565 write permission for the annotation or read permission for the annotation 566 type 567 @throws InvalidDataException If the value isn't a valid value for the 568 annotation type, see {@link AnnotationType#validateAnnotationValue(Object)} 569 @throws BaseException If there is another error 570 @since 3.8 571 */ 572 public boolean setValueIfDifferent(Object value, Unit unit) 548 573 throws PermissionDeniedException, InvalidDataException, BaseException 549 574 { … … 570 595 getData().setUnit(unit == null ? annotationType.getData().getDefaultUnit() : unit.getData()); 571 596 } 572 getData().getValues().setSingleValue(Values.getDataValue(value)); 573 getData().setLastUpdate(new Date()); 574 getAnnotationSet().setSnapshotInvalid(); 575 } 576 597 598 boolean different = getData().getValues().setSingleValueIfDifferent(Values.getDataValue(value)); 599 if (different) 600 { 601 getData().setLastUpdate(new Date()); 602 getAnnotationSet().setSnapshotInvalid(); 603 } 604 return different; 605 } 606 607 608 @Deprecated 577 609 public void setValues(List<?> values) 578 610 throws PermissionDeniedException, InvalidDataException, BaseException 579 611 { 580 setValues(values, null); 581 } 582 583 /** 584 Set the values of the annotation, replacing any previous values. 612 setValuesIfDifferent(values, null); 613 } 614 615 /** 616 Set the values of the annotation, replacing any previous values. NOTE! 617 As of BASE 3.8 the values are only replaced if the new values are 618 different from the existing values. 619 620 @deprecated In 3.8, use {@link #setValuesIfDifferent(List, Unit)} instead 621 */ 622 @Deprecated 623 public void setValues(List<?> values, Unit unit) 624 throws PermissionDeniedException, InvalidDataException, BaseException 625 { 626 setValuesIfDifferent(values, unit); 627 } 628 629 /** 630 Set the values of the annotation, replacing any previous values if they 631 are different. No change is made if the new list of values is the same 632 as the existing values. 633 585 634 @param values A list containing the new values 586 635 @param unit The unit of the value, or null to use the default unit of … … 594 643 {@link AnnotationType#validateAnnotationValue(Object)} 595 644 @throws BaseException If there is another error 596 */ 597 public void setValues(List<?> values, Unit unit) 645 @since 3.8 646 */ 647 public boolean setValuesIfDifferent(List<?> values, Unit unit) 598 648 throws PermissionDeniedException, InvalidDataException, BaseException 599 649 { … … 634 684 getData().setUnit(unit == null ? annotationType.getData().getDefaultUnit() : unit.getData()); 635 685 } 636 getData().getValues().replaceValues(Values.getDataValues(convertedValues)); 637 getData().setLastUpdate(new Date()); 638 getAnnotationSet().setSnapshotInvalid(); 639 } 640 686 687 boolean different = getData().getValues().replaceValuesIfDifferent(Values.getDataValues(convertedValues)); 688 if (different) 689 { 690 getData().setLastUpdate(new Date()); 691 getAnnotationSet().setSnapshotInvalid(); 692 }; 693 return different; 694 } 695 696 641 697 /** 642 698 If this is a cloned annotation, resync the cloned values. This method … … 657 713 } 658 714 659 data.getValues().replaceValues(inherited.getValues().getValues()); 660 data.setLastUpdate(inherited.getLastUpdate()); 661 data.setUnit(inherited.getUnit()); 662 663 getAnnotationSet().setSnapshotInvalid(); 715 if (data.getValues().replaceValuesIfDifferent(inherited.getValues().getValues())) 716 { 717 data.setLastUpdate(inherited.getLastUpdate()); 718 data.setUnit(inherited.getUnit()); 719 getAnnotationSet().setSnapshotInvalid(); 720 } 664 721 } 665 722 -
trunk/src/core/net/sf/basedb/core/AnnotationSet.java
r7052 r7120 723 723 if (a.getId() != 0) 724 724 { 725 a.getValues().replaceValues (null); // Ensure values are initialized in case logging is needed725 a.getValues().replaceValuesIfDifferent(null); // Ensure values are initialized in case logging is needed 726 726 Annotation ann = dc.getItem(Annotation.class, a); 727 727 dc.deleteItem(ann); … … 1256 1256 1257 1257 // Copy the values 1258 current.getValues().replaceValues(from.getValues().getValues()); 1259 current.setUnit(from.getUnit()); 1260 current.setLastUpdate(new Date()); 1261 setSnapshotInvalid(); 1258 if (current.getValues().replaceValuesIfDifferent(from.getValues().getValues())) 1259 { 1260 current.setUnit(from.getUnit()); 1261 current.setLastUpdate(new Date()); 1262 setSnapshotInvalid(); 1263 } 1262 1264 } 1263 1265 -
trunk/src/core/net/sf/basedb/core/AnnotationType.java
r7103 r7120 1169 1169 getData().setEnumerationValues(pv); 1170 1170 } 1171 pv.replaceValues (Values.getDataValues(values));1171 pv.replaceValuesIfDifferent(Values.getDataValues(values)); 1172 1172 } 1173 1173 -
trunk/src/core/net/sf/basedb/core/Install.java
r7107 r7120 2124 2124 { 2125 2125 ParameterValueData<?> enumValues = type.newParameterValueData(); 2126 enumValues.replaceValues (Arrays.asList(enumeration));2126 enumValues.replaceValuesIfDifferent(Arrays.asList(enumeration)); 2127 2127 at.setEnumeration(true); 2128 2128 at.setEnumerationValues(enumValues); -
trunk/src/core/net/sf/basedb/core/Job.java
r7119 r7120 1610 1610 toParameter.setLabel(fromParameter.getLabel()); 1611 1611 toParameter.setDescription(fromParameter.getDescription()); 1612 toParameter.replaceValues (fromParameter.getValues());1612 toParameter.replaceValuesIfDifferent(fromParameter.getValues()); 1613 1613 to.put(toName, toParameter); 1614 1614 } … … 1657 1657 parameterValue.setDescription(description); 1658 1658 parameterValue.setMasked(parameterType.isMasked()); 1659 parameterValue.replaceValues (Values.getDataValues(values));1659 parameterValue.replaceValuesIfDifferent(Values.getDataValues(values)); 1660 1660 old = getData().getParameters().put(name, parameterValue); 1661 1661 } -
trunk/src/core/net/sf/basedb/core/PluginConfiguration.java
r6881 r7120 566 566 parameterValue.setLabel(label); 567 567 parameterValue.setDescription(description); 568 parameterValue.replaceValues (Values.getDataValues(values));568 parameterValue.replaceValuesIfDifferent(Values.getDataValues(values)); 569 569 getData().getConfigurationValues().put(param, parameterValue); 570 570 } … … 611 611 toParameter.setLabel(fromParameter.getLabel()); 612 612 toParameter.setDescription(fromParameter.getDescription()); 613 toParameter.replaceValues (fromParameter.getValues());613 toParameter.replaceValuesIfDifferent(fromParameter.getValues()); 614 614 to.put(toName, toParameter); 615 615 } -
trunk/src/core/net/sf/basedb/core/data/DateParameterValueData.java
r7096 r7120 28 28 29 29 import net.sf.basedb.core.DateUtil; 30 import net.sf.basedb.util.EqualsHelper; 30 31 31 32 /** … … 84 85 Overrides the parent method since we want to get rid of the 85 86 time part of the date. 87 @since 3.8 86 88 */ 87 89 @Override 88 public void replaceValues(List<?> values)90 public boolean replaceValuesIfDifferent(List<?> values) 89 91 { 90 92 List<Date> current = getValues(); 93 if (EqualsHelper.invariantEquals(values, current)) return false; 94 91 95 storeCurrentValuesAsOld(current); 92 96 current.clear(); … … 98 102 } 99 103 } 104 return true; 100 105 } 101 106 … … 103 108 Overrides the parent method since we want to get rid of the 104 109 time part of the date. 110 @since 3.8 105 111 */ 106 112 @Override 107 public void setSingleValue(Object value)113 public boolean setSingleValueIfDifferent(Object value) 108 114 { 109 115 List<Date> current = getValues(); 116 if (current != null && current.size() == 1 && EqualsHelper.equals(current.get(0), value)) 117 { 118 return false; 119 } 120 110 121 storeCurrentValuesAsOld(current); 111 122 current.clear(); 112 123 current.add(DateUtil.truncate((Date)value)); 124 return true; 113 125 } 114 126 -
trunk/src/core/net/sf/basedb/core/data/ParameterValueData.java
r7096 r7120 29 29 import net.sf.basedb.core.AnnotationSet; 30 30 import net.sf.basedb.core.Type; 31 import net.sf.basedb.util.EqualsHelper; 31 32 32 33 /** … … 51 52 ParameterValueData(T... values) 52 53 { 53 replaceValues (Arrays.asList(values));54 replaceValuesIfDifferent(Arrays.asList(values)); 54 55 } 55 56 … … 150 151 the last update timestamp: {@link AnnotationData#setLastUpdate(java.util.Date)}. 151 152 and to invalidate the annotation set snapshot: {@link AnnotationSet#setSnapshotInvalid()} 153 @return TRUE if the values were replaced, FALSE if not 154 @since 3.8 152 155 */ 153 156 @SuppressWarnings("unchecked") 154 public void replaceValues(List<?> values)157 public boolean replaceValuesIfDifferent(List<?> values) 155 158 { 156 159 List<T> current = getValues(); 160 if (EqualsHelper.invariantEquals(values, current)) return false; 161 157 162 storeCurrentValuesAsOld(current); 158 163 current.clear(); 159 164 if (values != null) current.addAll((List<T>) values); 165 return true; 160 166 } 161 167 … … 168 174 the last update timestamp: {@link AnnotationData#setLastUpdate(java.util.Date)}. 169 175 and to invalidate the annotation set snapshot: {@link AnnotationSet#setSnapshotInvalid()} 176 @return TRUE if the values were replaced, FALSE if not 177 @since 3.8 170 178 */ 171 179 @SuppressWarnings("unchecked") 172 public void setSingleValue(Object value)180 public boolean setSingleValueIfDifferent(Object value) 173 181 { 174 182 List<T> current = getValues(); 183 if (current != null && current.size() == 1 && EqualsHelper.equals(current.get(0), value)) 184 { 185 return false; 186 } 187 175 188 storeCurrentValuesAsOld(current); 176 189 current.clear(); 177 190 current.add((T) value); 191 return true; 178 192 } 179 193 -
trunk/src/core/net/sf/basedb/util/EqualsHelper.java
r6125 r7120 21 21 */ 22 22 package net.sf.basedb.util; 23 24 import java.util.List; 23 25 24 26 /** … … 110 112 } 111 113 114 /** 115 Checks if two lists contains equal elements disregarding 116 their positions in the array. Eg. [1, 2] is equal to [2, 1] 117 @param l1 The first list 118 @param l2 The second list 119 @return TRUE if both list contains the same elements 120 @since 3.8 121 */ 122 public static boolean invariantEquals(List<?> l1, List<?> l2) 123 { 124 if (l1 == l2) return true; 125 if (l1 == null || l2 == null) return false; 126 if (l1.size() != l2.size()) return false; 127 128 boolean[] matched = new boolean[l2.size()]; 129 for (Object o1 : l1) 130 { 131 boolean found = false; 132 for (int j = 0; j < l2.size(); ++j) 133 { 134 if (!matched[j] && equals(o1, l2.get(j))) 135 { 136 matched[j] = true; 137 found = true; 138 break; 139 } 140 } 141 if (!found) return false; 142 } 143 return true; 144 } 145 146 112 147 } -
trunk/src/plugins/core/net/sf/basedb/plugins/AnnotationFlatFileImporter.java
r6921 r7120 29 29 import java.util.Collection; 30 30 import java.util.Collections; 31 import java.util.Date; 31 32 import java.util.EnumSet; 32 33 import java.util.HashMap; … … 719 720 protected void beginData() 720 721 { 722 System.out.println(new Date()+": begin"); 721 723 this.dc = sc.newDbControl(); 722 724 this.unitCache = new UnitCache(dc); … … 767 769 { 768 770 771 if (data.dataLineNo() % 100 == 0) 772 { 773 System.out.println(new Date()+": line " + data.dataLineNo()); 774 } 775 769 776 // Find the item(s) to annotate. Mapper gives us name OR external ID 770 777 String nameOrId = itemMapper.getValue(data); … … 920 927 protected void end(boolean success) 921 928 { 929 System.out.println(new Date()+": end start"); 922 930 try 923 931 { … … 930 938 { 931 939 current++; 940 932 941 if (progress != null) 933 942 { … … 945 954 ThreadSignalHandler.checkInterrupted(); 946 955 } 947 } 948 956 957 if (current % 100 == 0) 958 { 959 System.out.println(new Date()+": " + current + "; " + numItems + " items; " + numAnnotations + " annotations"); 960 } 961 962 } 963 System.out.println(new Date()+": commit start"); 949 964 dc.commit(); 965 System.out.println(new Date()+": commit end"); 950 966 if (progress != null) progress.display(100, "Done"); 951 967 } … … 1391 1407 if (as == null) as = item.getAnnotationSet(); 1392 1408 Annotation a = as.getAnnotation(at); 1409 1393 1410 List<Object> theValues = new ArrayList<Object>(newValues.size()); 1394 1411 // Make sure all annotation values are converted to the same unit … … 1407 1424 theValues.add(theValue); 1408 1425 } 1409 a.setValues(theValues, unit); 1410 numSet += size; 1411 if (hasAnnotation && !merge) numReplaced += size; 1426 if (a.setValuesIfDifferent(theValues, unit)) 1427 { 1428 numSet += size; 1429 if (hasAnnotation && !merge) numReplaced += size; 1430 } 1412 1431 } 1413 1432 else -
trunk/src/test/TestAnnotation.java
r7107 r7120 156 156 l.addAll(Arrays.asList(value)); 157 157 Unit unit = unitId != 0 ? Unit.getById(dc, unitId) : null; 158 a.setValues (l, unit);158 a.setValuesIfDifferent(l, unit); 159 159 } 160 160 dc.commit(); … … 364 364 l.addAll(Arrays.asList(value)); 365 365 Unit unit = unitId != 0 ? Unit.getById(dc, unitId) : null; 366 a.setValues (l, unit);366 a.setValuesIfDifferent(l, unit); 367 367 dc.commit(); 368 368 dc = TestUtil.getDbControl(); -
trunk/src/test/TestBfsExporterImporter.java
r6875 r7120 513 513 { 514 514 Object value = values[i]; 515 ba.getAnnotationSet().getAnnotation(at).setValue (value);515 ba.getAnnotationSet().getAnnotation(at).setValueIfDifferent(value, null); 516 516 ++i; 517 517 if (i >= values.length) i = 0; -
trunk/src/test/net/sf/basedb/test/roles/Util.java
r5983 r7120 231 231 AnnotationSet as = item.getAnnotationSet(); 232 232 Annotation a = as.getAnnotation(at); 233 a.setValue (value, unit);233 a.setValueIfDifferent(value, unit); 234 234 } 235 235
Note: See TracChangeset
for help on using the changeset viewer.