Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactored fix for mulivalue manual index. issue #2741
- Loading branch information
Showing
6 changed files
with
168 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 0 additions & 41 deletions
41
core/src/main/java/com/orientechnologies/orient/core/collate/OMultivalueCollate.java
This file was deleted.
Oops, something went wrong.
90 changes: 90 additions & 0 deletions
90
core/src/main/java/com/orientechnologies/orient/core/index/OCompositeCollate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.orientechnologies.orient.core.index; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.orientechnologies.orient.core.collate.OCollate; | ||
|
||
public class OCompositeCollate implements OCollate { | ||
/** | ||
* | ||
*/ | ||
private final OAbstractIndexDefinition oCompositeIndexDefinition; | ||
|
||
/** | ||
* @param oCompositeIndexDefinition | ||
*/ | ||
public OCompositeCollate(OAbstractIndexDefinition oCompositeIndexDefinition) { | ||
this.oCompositeIndexDefinition = oCompositeIndexDefinition; | ||
} | ||
|
||
private final List<OCollate> collates = new ArrayList<OCollate>(); | ||
|
||
public void addCollate(OCollate collate) { | ||
collates.add(collate); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
throw new UnsupportedOperationException("getName"); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public Object transform(Object obj) { | ||
List<Object> keys = null; | ||
if (obj instanceof OCompositeKey) { | ||
final OCompositeKey compositeKey = (OCompositeKey) obj; | ||
keys = compositeKey.getKeys(); | ||
} else if (obj instanceof List) { | ||
keys = (List<Object>) obj; | ||
} else { | ||
throw new OIndexException("Impossible add as key of a CompositeIndex a value of type " + obj.getClass()); | ||
} | ||
|
||
OCompositeKey transformedKey = new OCompositeKey(); | ||
|
||
final int size = Math.min(keys.size(), collates.size()); | ||
for (int i = 0; i < size; i++) { | ||
final Object key = keys.get(i); | ||
|
||
final OCollate collate = collates.get(i); | ||
transformedKey.addKey(collate.transform(key)); | ||
} | ||
|
||
for (int i = size; i < keys.size(); i++) | ||
transformedKey.addKey(keys.get(i)); | ||
|
||
return transformedKey; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) | ||
return true; | ||
if (o == null || getClass() != o.getClass()) | ||
return false; | ||
|
||
OCompositeCollate that = (OCompositeCollate) o; | ||
|
||
if (!collates.equals(that.collates)) | ||
return false; | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return collates.hashCode(); | ||
} | ||
|
||
public List<OCollate> getCollates() { | ||
return collates; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "OCompositeCollate{" + "collates=" + collates + ", null values ignored = " | ||
+ this.oCompositeIndexDefinition.isNullValuesIgnored() + '}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.